diff --git a/PInvoke/User32.Gdi/WinUser.Monitor.cs b/PInvoke/User32.Gdi/WinUser.Monitor.cs index 4154f5fe..8f163818 100644 --- a/PInvoke/User32.Gdi/WinUser.Monitor.cs +++ b/PInvoke/User32.Gdi/WinUser.Monitor.cs @@ -1,10 +1,19 @@ using System; using System.Runtime.InteropServices; +using static Vanara.PInvoke.Gdi32; namespace Vanara.PInvoke { public static partial class User32_Gdi { + /// 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. @@ -47,6 +56,37 @@ namespace Vanara.PInvoke [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 @@ -69,6 +109,66 @@ namespace Vanara.PInvoke 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 @@ -179,6 +279,230 @@ namespace Vanara.PInvoke [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. ///