private static bool MonitorEnumCallBack(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData) { Debug.WriteLine(hMonitor); MONITORINFO mon_info = new(); mon_info.cbSize = (uint)Marshal.SizeOf(mon_info); NativeMethods.GetMonitorInfo(hMonitor, mon_info); Debug.WriteLine(Marshal.GetLastWin32Error()); AllMonitorInfo.Add(mon_info); return(true); }
public static Rectangle CurrentMonitorSize() { NativeMethods.GetCursorPos(out POINT lpPoint); IntPtr lPrimaryScreen = NativeMethods.MonitorFromPoint(lpPoint, NativeMethods.MonitorOptions.MONITOR_DEFAULTTOPRIMARY); MONITORINFO lPrimaryScreenInfo = new(); lPrimaryScreenInfo.cbSize = (uint)Marshal.SizeOf(lPrimaryScreenInfo); if (NativeMethods.GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false) { Debug.WriteLine(Marshal.GetLastWin32Error()); return(new Rectangle()); } return(new Rectangle { Rect = lPrimaryScreenInfo.rcWork }); }