using System;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Gdi32;
namespace Vanara.PInvoke
{
public static partial class User32
{
/// Retrieve the current settings for the display device.
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
public const uint ENUM_CURRENT_SETTINGS = unchecked((uint)-1);
/// Retrieve the settings for the display device that are currently stored in the registry.
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
public const uint ENUM_REGISTRY_SETTINGS = unchecked((uint)-2);
///
///
/// A MonitorEnumProc function is an application-defined callback function that is called by the EnumDisplayMonitors function.
///
/// A value of type MONITORENUMPROC is a pointer to a MonitorEnumProc function.
///
///
///
///
///
///
/// To continue the enumeration, return TRUE.
/// To stop the enumeration, return FALSE.
///
///
///
/// You can use the EnumDisplayMonitors function to enumerate the set of display monitors that intersect the visible region of a
/// specified device context and, optionally, a clipping rectangle. To do this, set the hdc parameter to a non- NULL value,
/// and set the lprcClip parameter as needed.
///
///
/// You can also use the EnumDisplayMonitors function to enumerate one or more of the display monitors on the desktop, without
/// supplying a device context. To do this, set the hdc parameter of EnumDisplayMonitors to NULL and set the lprcClip
/// parameter as needed.
///
///
/// In all cases, EnumDisplayMonitors calls a specified MonitorEnumProc function once for each display monitor in the
/// calculated enumeration set. The MonitorEnumProc function always receives a handle to the display monitor.
///
///
/// If the hdc parameter of EnumDisplayMonitors is non- NULL, the MonitorEnumProc function also receives a handle to a
/// device context whose color format is appropriate for the display monitor. You can then paint into the device context in a manner
/// that is optimal for the display monitor.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nc-winuser-monitorenumproc MONITORENUMPROC Monitorenumproc; BOOL
// Monitorenumproc( HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4 ) {...}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
[PInvokeData("winuser.h", MSDNShortId = "2d69e363-2b2c-450f-9069-488b80991217")]
[return: MarshalAs(UnmanagedType.Bool)]
public delegate bool MonitorEnumProc(IntPtr Arg1, IntPtr Arg2, PRECT Arg3, IntPtr Arg4);
/// Flags for .
[PInvokeData("winuser.h", MSDNShortId = "df3b493c-23d2-4996-9b79-86009efe3078")]
public enum EDD
{
///
/// Retrieve the device interface name for GUID_DEVINTERFACE_MONITOR, which is registered by the operating system on a per
/// monitor basis. The value is placed in the DeviceID member of the DISPLAY_DEVICE structure returned in lpDisplayDevice. The
/// resulting device interface name can be used with SetupAPI functions and serves as a link between GDI monitor devices and
/// SetupAPI monitor devices.
///
EDD_GET_DEVICE_INTERFACE_NAME = 0x00000001
}
/// Flags for .
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
[Flags]
public enum EDS
{
///
/// If set, the function will return all graphics modes reported by the adapter driver, regardless of monitor capabilities.
/// Otherwise, it will only return modes that are compatible with current monitors.
///
EDS_RAWMODE = 0x00000002,
///
/// If set, the function will return graphics modes in all orientations. Otherwise, it will only return modes that have the same
/// orientation as the one currently set for the requested display.
///
EDS_ROTATEDMODE = 0x00000004,
}
/// Determines the function's return value if the point is not contained within any display monitor.
[PInvokeData("winuser.h", MSDNShortId = "c46281bf-7e45-4628-be92-736850225a9e")]
public enum MonitorFlags
{
/// Returns NULL.
MONITOR_DEFAULTTONULL = 0x00000000,
/// Returns a handle to the primary display monitor.
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
/// Returns a handle to the display monitor that is nearest to the point.
MONITOR_DEFAULTTONEAREST = 0x00000002,
}
/// Flags for .
[PInvokeData("winuser.h", MSDNShortId = "ca8ec86f-69ba-4cf8-a867-67182a3d630d")]
public enum MonitorInfoFlags
{
/// This is the primary display monitor.
MONITORINFOF_PRIMARY = 0x00000001
}
/// The EnumDisplayDevices function lets you obtain information about the display devices in the current session.
///
///
/// A pointer to the device name. If NULL, function returns information for the display adapter(s) on the machine, based on iDevNum.
///
/// For more information, see Remarks.
///
///
/// An index value that specifies the display device of interest.
///
/// The operating system identifies each display device in the current session with an index value. The index values are consecutive
/// integers, starting at 0. If the current session has three display devices, for example, they are specified by the index values 0,
/// 1, and 2.
///
///
///
/// A pointer to a DISPLAY_DEVICE structure that receives information about the display device specified by iDevNum.
///
/// Before calling EnumDisplayDevices, you must initialize the cb member of DISPLAY_DEVICE to the size, in bytes, of DISPLAY_DEVICE.
///
///
///
/// Set this flag to EDD_GET_DEVICE_INTERFACE_NAME (0x00000001) to retrieve the device interface name for GUID_DEVINTERFACE_MONITOR,
/// which is registered by the operating system on a per monitor basis. The value is placed in the DeviceID member of the
/// DISPLAY_DEVICE structure returned in lpDisplayDevice. The resulting device interface name can be used with SetupAPI functions and
/// serves as a link between GDI monitor devices and SetupAPI monitor devices.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. The function fails if iDevNum is greater than the largest device index.
///
///
///
/// To query all display devices in the current session, call this function in a loop, starting with iDevNum set to 0, and
/// incrementing iDevNum until the function fails. To select all display devices in the desktop, use only the display devices that
/// have the DISPLAY_DEVICE_ATTACHED_TO_DESKTOP flag in the DISPLAY_DEVICE structure.
///
///
/// To get information on the display adapter, call EnumDisplayDevices with lpDevice set to NULL. For example,
/// DISPLAY_DEVICE. DeviceString contains the adapter name.
///
///
/// To obtain information on a display monitor, first call EnumDisplayDevices with lpDevice set to NULL. Then call
/// EnumDisplayDevices with lpDevice set to DISPLAY_DEVICE. DeviceName from the first call to EnumDisplayDevices
/// and with iDevNum set to zero. Then DISPLAY_DEVICE. DeviceString is the monitor name.
///
///
/// To query all monitor devices associated with an adapter, call EnumDisplayDevices in a loop with lpDevice set to the
/// adapter name, iDevNum set to start at 0, and iDevNum set to increment until the function fails. Note that
/// DISPLAY_DEVICE.DeviceName changes with each call for monitor information, so you must save the adapter name. The function
/// fails when there are no more monitors for the adapter.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaydevicesa BOOL EnumDisplayDevicesA( LPCSTR
// lpDevice, DWORD iDevNum, PDISPLAY_DEVICEA lpDisplayDevice, DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "df3b493c-23d2-4996-9b79-86009efe3078")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplayDevices([Optional] string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, EDD dwFlags);
///
///
/// The EnumDisplayMonitors function enumerates display monitors (including invisible pseudo-monitors associated with the
/// mirroring drivers) that intersect a region formed by the intersection of a specified clipping rectangle and the visible region of
/// a device context. EnumDisplayMonitors calls an application-defined MonitorEnumProc callback function once for each monitor
/// that is enumerated. Note that GetSystemMetrics (SM_CMONITORS) counts only the display monitors.
///
///
///
/// A handle to a display device context that defines the visible region of interest.
///
/// If this parameter is NULL, the hdcMonitor parameter passed to the callback function will be NULL, and the visible
/// region of interest is the virtual screen that encompasses all the displays on the desktop.
///
///
///
///
/// A pointer to a RECT structure that specifies a clipping rectangle. The region of interest is the intersection of the clipping
/// rectangle with the visible region specified by hdc.
///
///
/// If hdc is non- NULL, the coordinates of the clipping rectangle are relative to the origin of the hdc. If hdc is
/// NULL, the coordinates are virtual-screen coordinates.
///
/// This parameter can be NULL if you don't want to clip the region specified by hdc.
///
///
/// A pointer to a MonitorEnumProc application-defined callback function.
///
///
/// Application-defined data that EnumDisplayMonitors passes directly to the MonitorEnumProc function.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
///
/// There are two reasons to call the EnumDisplayMonitors function:
///
/// -
///
/// You want to draw optimally into a device context that spans several display monitors, and the monitors have different color formats.
///
///
/// -
/// You want to obtain a handle and position rectangle for one or more display monitors.
///
///
/// To determine whether all the display monitors in a system share the same color format, call GetSystemMetrics (SM_SAMEDISPLAYFORMAT).
///
/// You do not need to use the EnumDisplayMonitors function when a window spans display monitors that have different color
/// formats. You can continue to paint under the assumption that the entire screen has the color properties of the primary monitor.
/// Your windows will look fine. EnumDisplayMonitors just lets you make them look better.
///
///
/// Setting the hdc parameter to NULL lets you use the EnumDisplayMonitors function to obtain a handle and position
/// rectangle for one or more display monitors. The following table shows how the four combinations of NULL and non-
/// NULL hdc and lprcClip values affect the behavior of the EnumDisplayMonitors function.
///
///
///
/// hdc
/// lprcRect
/// EnumDisplayMonitors behavior
///
/// -
/// NULL
/// NULL
/// Enumerates all display monitors.The callback function receives a NULL HDC.
///
/// -
/// NULL
/// non-NULL
///
/// Enumerates all display monitors that intersect the clipping rectangle. Use virtual screen coordinates for the clipping
/// rectangle.The callback function receives a NULL HDC.
///
///
/// -
/// non-NULL
/// NULL
///
/// Enumerates all display monitors that intersect the visible region of the device context.The callback function receives a handle
/// to a DC for the specific display monitor.
///
///
/// -
/// non-NULL
/// non-NULL
///
/// Enumerates all display monitors that intersect the visible region of the device context and the clipping rectangle. Use device
/// context coordinates for the clipping rectangle.The callback function receives a handle to a DC for the specific display monitor.
///
///
///
/// Examples
///
/// To paint in response to a WM_PAINT message, using the capabilities of each monitor, you can use code like this in a window procedure:
///
/// To paint the top half of a window using the capabilities of each monitor, you can use code like this:
/// To paint the entire virtual screen optimally for each display monitor, you can use code like this:
/// To retrieve information about all of the display monitors, use code like this:
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaymonitors BOOL EnumDisplayMonitors( HDC hdc,
// LPCRECT lprcClip, MONITORENUMPROC lpfnEnum, LPARAM dwData );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "a7668c28-77c9-4373-ae1a-eab3cb98f866")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplayMonitors(HDC hdc, PRECT lprcClip, MonitorEnumProc lpfnEnum, IntPtr dwData);
///
///
/// The EnumDisplaySettings function retrieves information about one of the graphics modes for a display device. To retrieve
/// information for all the graphics modes of a display device, make a series of calls to this function.
///
///
/// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32
/// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8
/// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates
/// these modes but still runs in 32-bit color mode.
///
///
///
///
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
///
///
/// This parameter is either NULL or a DISPLAY_DEVICE. DeviceName returned from EnumDisplayDevices. A NULL value
/// specifies the current display device on the computer on which the calling thread is running.
///
///
///
/// The type of information to be retrieved. This value can be a graphics mode index or one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ENUM_CURRENT_SETTINGS
/// Retrieve the current settings for the display device.
///
/// -
/// ENUM_REGISTRY_SETTINGS
/// Retrieve the settings for the display device that are currently stored in the registry.
///
///
///
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls
/// to EnumDisplaySettings, as follows: Set iModeNum to zero for the first call, and increment iModeNum by one for each
/// subsequent call. Continue calling the function until the return value is zero.
///
///
/// When you call EnumDisplaySettings with iModeNum set to zero, the operating system initializes and caches information about
/// the display device. When you call EnumDisplaySettings with iModeNum set to a nonzero value, the function returns the
/// information that was cached the last time the function was called with iModeNum set to zero.
///
///
///
///
/// A pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling
/// EnumDisplaySettings, set the dmSize member to , and set the dmDriverExtra member to indicate the size, in
/// bytes, of the additional space available to receive private driver data.
///
/// The EnumDisplaySettings function sets values for the following five DEVMODE members:
///
/// -
/// dmBitsPerPel
///
/// -
/// dmPelsWidth
///
/// -
/// dmPelsHeight
///
/// -
/// dmDisplayFlags
///
/// -
/// dmDisplayFrequency
///
///
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
///
///
/// The function fails if iModeNum is greater than the index of the display device's last graphics mode. As noted in the description
/// of the iModeNum parameter, you can use this behavior to enumerate all of a display device's graphics modes.
///
/// DPI Virtualization
///
/// This API does not participate in DPI virtualization. The output given is always in terms of physical pixels, and is not related
/// to the calling context.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaysettingsa BOOL EnumDisplaySettingsA( LPCSTR
// lpszDeviceName, DWORD iModeNum, DEVMODEA *lpDevMode );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "af73610b-bcd8-4660-800e-84fa0cc5b4eb")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplaySettings([Optional] string lpszDeviceName, uint iModeNum, ref DEVMODE lpDevMode);
///
///
/// The EnumDisplaySettingsEx function retrieves information about one of the graphics modes for a display device. To retrieve
/// information for all the graphics modes for a display device, make a series of calls to this function.
///
/// This function differs from EnumDisplaySettings in that there is a dwFlags parameter.
///
/// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32
/// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8
/// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates
/// these modes but still runs in 32-bit color mode.
///
///
///
///
/// A pointer to a null-terminated string that specifies the display device about which graphics mode the function will obtain information.
///
///
/// This parameter is either NULL or a DISPLAY_DEVICE. DeviceName returned from EnumDisplayDevices. A NULL value
/// specifies the current display device on the computer that the calling thread is running on.
///
///
///
/// Indicates the type of information to be retrieved. This value can be a graphics mode index or one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ENUM_CURRENT_SETTINGS
/// Retrieve the current settings for the display device.
///
/// -
/// ENUM_REGISTRY_SETTINGS
/// Retrieve the settings for the display device that are currently stored in the registry.
///
///
///
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls
/// to EnumDisplaySettingsEx, as follows: Set iModeNum to zero for the first call, and increment iModeNum by one for each
/// subsequent call. Continue calling the function until the return value is zero.
///
///
/// When you call EnumDisplaySettingsEx with iModeNum set to zero, the operating system initializes and caches information
/// about the display device. When you call EnumDisplaySettingsEx with iModeNum set to a nonzero value, the function returns
/// the information that was cached the last time the function was called with iModeNum set to zero.
///
///
///
///
/// A pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling
/// EnumDisplaySettingsEx, set the dmSize member to sizeof (DEVMODE), and set the dmDriverExtra member to
/// indicate the size, in bytes, of the additional space available to receive private driver data.
///
///
/// The EnumDisplaySettingsEx function will populate the dmFields member of the lpDevMode and one or more other
/// members of the DEVMODE structure. To determine which members were set by the call to EnumDisplaySettingsEx, inspect the
/// dmFields bitmask. Some of the fields typically populated by this function include:
///
///
/// -
/// dmBitsPerPel
///
/// -
/// dmPelsWidth
///
/// -
/// dmPelsHeight
///
/// -
/// dmDisplayFlags
///
/// -
/// dmDisplayFrequency
///
/// -
/// dmPosition
///
/// -
/// dmDisplayOrientation
///
///
///
///
/// This parameter can be the following value.
///
///
/// Value
/// Meaning
///
/// -
/// EDS_RAWMODE
///
/// If set, the function will return all graphics modes reported by the adapter driver, regardless of monitor capabilities.
/// Otherwise, it will only return modes that are compatible with current monitors.
///
///
/// -
/// EDS_ROTATEDMODE
///
/// If set, the function will return graphics modes in all orientations. Otherwise, it will only return modes that have the same
/// orientation as the one currently set for the requested display.
///
///
///
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
///
///
/// The function fails if iModeNum is greater than the index of the display device's last graphics mode. As noted in the description
/// of the iModeNum parameter, you can use this behavior to enumerate all of a display device's graphics modes.
///
/// DPI Virtualization
///
/// This API does not participate in DPI virtualization. The output given is always in terms of physical pixels, and is not related
/// to the calling context.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaysettingsexa BOOL EnumDisplaySettingsExA( LPCSTR
// lpszDeviceName, DWORD iModeNum, DEVMODEA *lpDevMode, DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplaySettingsEx([Optional] string lpszDeviceName, uint iModeNum, ref DEVMODE lpDevMode, EDS dwFlags);
///
/// The GetMonitorInfo function retrieves information about a display monitor.
///
///
/// A handle to the display monitor of interest.
///
///
/// A pointer to a MONITORINFO or MONITORINFOEX structure that receives information about the specified display monitor.
///
/// You must set the cbSize member of the structure to sizeof(MONITORINFO) or sizeof(MONITORINFOEX) before calling the
/// GetMonitorInfo function. Doing so lets the function determine the type of structure you are passing to it.
///
///
/// The MONITORINFOEX structure is a superset of the MONITORINFO structure. It has one additional member: a string that contains a
/// name for the display monitor. Most applications have no use for a display monitor name, and so can save some bytes by using a
/// MONITORINFO structure.
///
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmonitorinfoa BOOL GetMonitorInfoA( HMONITOR hMonitor,
// LPMONITORINFO lpmi );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "025a89c2-4bbd-4c8b-8367-3735fb5b872a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorInfo(HMONITOR hMonitor, ref MONITORINFO lpmi);
///
/// The GetMonitorInfo function retrieves information about a display monitor.
///
///
/// A handle to the display monitor of interest.
///
///
/// A pointer to a MONITORINFO or MONITORINFOEX structure that receives information about the specified display monitor.
///
/// You must set the cbSize member of the structure to sizeof(MONITORINFO) or sizeof(MONITORINFOEX) before calling the
/// GetMonitorInfo function. Doing so lets the function determine the type of structure you are passing to it.
///
///
/// The MONITORINFOEX structure is a superset of the MONITORINFO structure. It has one additional member: a string that contains a
/// name for the display monitor. Most applications have no use for a display monitor name, and so can save some bytes by using a
/// MONITORINFO structure.
///
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmonitorinfoa BOOL GetMonitorInfoA( HMONITOR hMonitor,
// LPMONITORINFO lpmi );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "025a89c2-4bbd-4c8b-8367-3735fb5b872a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorInfo(HMONITOR hMonitor, ref MONITORINFOEX lpmi);
///
/// The MonitorFromPoint function retrieves a handle to the display monitor that contains a specified point.
///
///
/// A POINT structure that specifies the point of interest in virtual-screen coordinates.
///
///
/// Determines the function's return value if the point is not contained within any display monitor.
/// This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MONITOR_DEFAULTTONEAREST
/// Returns a handle to the display monitor that is nearest to the point.
///
/// -
/// MONITOR_DEFAULTTONULL
/// Returns NULL.
///
/// -
/// MONITOR_DEFAULTTOPRIMARY
/// Returns a handle to the primary display monitor.
///
///
///
///
/// If the point is contained by a display monitor, the return value is an HMONITOR handle to that display monitor.
/// If the point is not contained by a display monitor, the return value depends on the value of dwFlags.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-monitorfrompoint HMONITOR MonitorFromPoint( POINT pt,
// DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "c46281bf-7e45-4628-be92-736850225a9e")]
public static extern HMONITOR MonitorFromPoint(System.Drawing.Point pt, MonitorFlags dwFlags);
///
///
/// The MonitorFromRect function retrieves a handle to the display monitor that has the largest area of intersection with a
/// specified rectangle.
///
///
///
/// A pointer to a RECT structure that specifies the rectangle of interest in virtual-screen coordinates.
///
///
/// Determines the function's return value if the rectangle does not intersect any display monitor.
/// This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MONITOR_DEFAULTTONEAREST
/// Returns a handle to the display monitor that is nearest to the rectangle.
///
/// -
/// MONITOR_DEFAULTTONULL
/// Returns NULL.
///
/// -
/// MONITOR_DEFAULTTOPRIMARY
/// Returns a handle to the primary display monitor.
///
///
///
///
///
/// If the rectangle intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display
/// monitor that has the largest area of intersection with the rectangle.
///
/// If the rectangle does not intersect a display monitor, the return value depends on the value of dwFlags.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-monitorfromrect HMONITOR MonitorFromRect( LPCRECT lprc,
// DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "81c3fffb-bbc9-4adb-bb6b-edd59f7a77b4")]
public static extern HMONITOR MonitorFromRect(in RECT lprc, MonitorFlags dwFlags);
///
///
/// The MonitorFromWindow function retrieves a handle to the display monitor that has the largest area of intersection with
/// the bounding rectangle of a specified window.
///
///
///
/// A handle to the window of interest.
///
///
/// Determines the function's return value if the window does not intersect any display monitor.
/// This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MONITOR_DEFAULTTONEAREST
/// Returns a handle to the display monitor that is nearest to the window.
///
/// -
/// MONITOR_DEFAULTTONULL
/// Returns NULL.
///
/// -
/// MONITOR_DEFAULTTOPRIMARY
/// Returns a handle to the primary display monitor.
///
///
///
///
///
/// If the window intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display
/// monitor that has the largest area of intersection with the window.
///
/// If the window does not intersect a display monitor, the return value depends on the value of dwFlags.
///
///
/// If the window is currently minimized, MonitorFromWindow uses the rectangle of the window before it was minimized.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-monitorfromwindow HMONITOR MonitorFromWindow( HWND hwnd,
// DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "fe6505c9-b481-4fec-ae9d-995943234a3a")]
public static extern HMONITOR MonitorFromWindow(HWND hwnd, MonitorFlags dwFlags);
///
/// The MONITORINFO structure contains information about a display monitor.
/// The GetMonitorInfo function stores information in a MONITORINFO structure or a MONITORINFOEX structure.
///
/// The MONITORINFO structure is a subset of the MONITORINFOEX structure. The MONITORINFOEX structure adds a string
/// member to contain a name for the display monitor.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmonitorinfo typedef struct tagMONITORINFO { DWORD
// cbSize; RECT rcMonitor; RECT rcWork; DWORD dwFlags; } MONITORINFO, *LPMONITORINFO;
[PInvokeData("winuser.h", MSDNShortId = "ca8ec86f-69ba-4cf8-a867-67182a3d630d")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MONITORINFO
{
///
/// The size of the structure, in bytes.
///
/// Set this member to before calling the GetMonitorInfo function. Doing so lets the function determine the type of structure you
/// are passing to it.
///
///
public uint cbSize;
///
///
/// A RECT structure that specifies the display monitor rectangle, expressed in virtual-screen coordinates. Note that if the
/// monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
///
///
public RECT rcMonitor;
///
///
/// A RECT structure that specifies the work area rectangle of the display monitor, expressed in virtual-screen coordinates. Note
/// that if the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
///
///
public RECT rcWork;
///
/// A set of flags that represent attributes of the display monitor.
/// The following flag is defined.
///
///
/// Value
/// Meaning
///
/// -
/// MONITORINFOF_PRIMARY
/// This is the primary display monitor.
///
///
///
public MonitorInfoFlags dwFlags;
}
///
/// The MONITORINFOEX structure contains information about a display monitor.
/// The GetMonitorInfo function stores information into a MONITORINFOEX structure or a MONITORINFO structure.
///
/// The MONITORINFOEX structure is a superset of the MONITORINFO structure. The MONITORINFOEX structure adds a string
/// member to contain a name for the display monitor.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmonitorinfoexa typedef struct tagMONITORINFOEXA { CHAR
// szDevice[CCHDEVICENAME]; base_class tagMONITORINFO; } MONITORINFOEXA, *LPMONITORINFOEXA;
[PInvokeData("winuser.h", MSDNShortId = "f296ce29-3fc8-41c9-a201-56e222aa2219")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MONITORINFOEX
{
///
/// The size of the structure, in bytes.
///
/// Set this member to before calling the GetMonitorInfo function. Doing so lets the function determine the type of structure you
/// are passing to it.
///
///
public uint cbSize;
///
///
/// A RECT structure that specifies the display monitor rectangle, expressed in virtual-screen coordinates. Note that if the
/// monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
///
///
public RECT rcMonitor;
///
///
/// A RECT structure that specifies the work area rectangle of the display monitor, expressed in virtual-screen coordinates. Note
/// that if the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
///
///
public RECT rcWork;
///
/// A set of flags that represent attributes of the display monitor.
/// The following flag is defined.
///
///
/// Value
/// Meaning
///
/// -
/// MONITORINFOF_PRIMARY
/// This is the primary display monitor.
///
///
///
public MonitorFlags dwFlags;
///
///
/// A string that specifies the device name of the monitor being used. Most applications have no use for a display monitor name,
/// and so can save some bytes by using a MONITORINFO structure.
///
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szDevice;
}
}
}