public static System.Windows.Point ClientToScreen(MouseEventArgs e) { if (e.Source is Visual visual) { var presentationSource = PresentationSource.FromVisual(visual); if (!presentationSource.IsDisposed && presentationSource.RootVisual is Window window) { var hwnd = (presentationSource as HwndSource).Handle; var point = e.GetPosition(window); var pointArg = new WinApiPoint() { X = (int)point.X, Y = (int)point.Y }; if (ClientToScreenWinApi(hwnd, ref pointArg)) { return(new System.Windows.Point(pointArg.X, pointArg.Y)); } } } return(new System.Windows.Point()); }
extern static bool ClientToScreenWinApi(IntPtr hwnd, ref WinApiPoint WinApiPoint);