private NativeStructures.PHYSICAL_MONITOR[] getMonitors() { WindowInteropHelper helper = new WindowInteropHelper(this); // Get the right monitor NativeStructures.tagPOINT right = new NativeStructures.tagPOINT(); right.x = 2000; right.y = 0; //IntPtr hMonitor = NativeMethods.MonitorFromWindow(helper.Handle, NativeConstants.MONITOR_DEFAULTTONULL); IntPtr hMonitor = NativeMethods.MonitorFromPoint(right, NativeConstants.MONITOR_DEFAULTTONULL); int lastWin32Error = Marshal.GetLastWin32Error(); uint pdwNumberOfPhysicalMonitors = 0u; bool numberOfPhysicalMonitorsFromHmonitor = NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR( hMonitor, ref pdwNumberOfPhysicalMonitors); lastWin32Error = Marshal.GetLastWin32Error(); NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray = new NativeStructures.PHYSICAL_MONITOR[pdwNumberOfPhysicalMonitors]; bool physicalMonitorsFromHmonitor = NativeMethods.GetPhysicalMonitorsFromHMONITOR( hMonitor, pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray); lastWin32Error = Marshal.GetLastWin32Error(); return(pPhysicalMonitorArray); }
public static extern IntPtr MonitorFromPoint( [In] NativeStructures.tagPOINT pt, uint dwFlags);