MonitorFromWindow(DefaultToNearest) doesn't work during drag
我正在使用Windows API方法
假设您在分辨率不同的两个屏幕之间拖动窗口,并在第二个屏幕上触发Aero Snap功能。这将触发有关窗口大小(消息
由于捕捉是基于鼠标位置的,因此解决此问题的方法是使用
一个简单的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [DllImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetCursorPos(ref Point lpPoint); public const int MONITOR_DEFAULTTONEAREST = 2; [DllImport("User32.dll")] public static extern IntPtr MonitorFromPoint(Point pt, UInt32 dwFlags); public IntPtr GetCurrentMonitor() { Point p = new Point(0,0); if (!GetCursorPos(ref p)) { // Decide what to do here. } IntPtr hMonitor = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST); // validate hMonitor return hMonitor; } |