Added display functions

pull/47/head
David Hall 2019-02-05 14:14:27 -07:00
parent 47599ad6f2
commit 9d30be3077
1 changed files with 324 additions and 0 deletions

View File

@ -1,10 +1,19 @@
using System;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Gdi32;
namespace Vanara.PInvoke
{
public static partial class User32_Gdi
{
/// <summary>Retrieve the current settings for the display device.</summary>
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
public const uint ENUM_CURRENT_SETTINGS = unchecked((uint)-1);
/// <summary>Retrieve the settings for the display device that are currently stored in the registry.</summary>
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
public const uint ENUM_REGISTRY_SETTINGS = unchecked((uint)-2);
/// <summary>
/// <para>
/// A <c>MonitorEnumProc</c> 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);
/// <summary>Flags for <see cref="EnumDisplayDevices"/>.</summary>
[PInvokeData("winuser.h", MSDNShortId = "df3b493c-23d2-4996-9b79-86009efe3078")]
public enum EDD
{
/// <summary>
/// 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.
/// </summary>
EDD_GET_DEVICE_INTERFACE_NAME = 0x00000001
}
/// <summary>Flags for <see cref="EnumDisplaySettingsEx"/>.</summary>
[PInvokeData("winuser.h", MSDNShortId = "99794fb1-7ba3-4864-bf6a-e3a514fa7917")]
[Flags]
public enum EDS
{
/// <summary>
/// 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.
/// </summary>
EDS_RAWMODE = 0x00000002,
/// <summary>
/// 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.
/// </summary>
EDS_ROTATEDMODE = 0x00000004,
}
/// <summary>Determines the function's return value if the point is not contained within any display monitor.</summary>
[PInvokeData("winuser.h", MSDNShortId = "c46281bf-7e45-4628-be92-736850225a9e")]
public enum MonitorFlags
@ -69,6 +109,66 @@ namespace Vanara.PInvoke
MONITORINFOF_PRIMARY = 0x00000001
}
/// <summary>The <c>EnumDisplayDevices</c> function lets you obtain information about the display devices in the current session.</summary>
/// <param name="lpDevice">
/// <para>
/// A pointer to the device name. If <c>NULL</c>, function returns information for the display adapter(s) on the machine, based on iDevNum.
/// </para>
/// <para>For more information, see Remarks.</para>
/// </param>
/// <param name="iDevNum">
/// <para>An index value that specifies the display device of interest.</para>
/// <para>
/// 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.
/// </para>
/// </param>
/// <param name="lpDisplayDevice">
/// <para>A pointer to a DISPLAY_DEVICE structure that receives information about the display device specified by iDevNum.</para>
/// <para>
/// Before calling <c>EnumDisplayDevices</c>, you must initialize the <c>cb</c> member of DISPLAY_DEVICE to the size, in bytes, of <c>DISPLAY_DEVICE</c>.
/// </para>
/// </param>
/// <param name="dwFlags">
/// 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.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero. The function fails if iDevNum is greater than the largest device index.</para>
/// </returns>
/// <remarks>
/// <para>
/// 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.
/// </para>
/// <para>
/// To get information on the display adapter, call <c>EnumDisplayDevices</c> with lpDevice set to <c>NULL</c>. For example,
/// DISPLAY_DEVICE. <c>DeviceString</c> contains the adapter name.
/// </para>
/// <para>
/// To obtain information on a display monitor, first call <c>EnumDisplayDevices</c> with lpDevice set to <c>NULL</c>. Then call
/// <c>EnumDisplayDevices</c> with lpDevice set to DISPLAY_DEVICE. <c>DeviceName</c> from the first call to <c>EnumDisplayDevices</c>
/// and with iDevNum set to zero. Then <c>DISPLAY_DEVICE</c>. <c>DeviceString</c> is the monitor name.
/// </para>
/// <para>
/// To query all monitor devices associated with an adapter, call <c>EnumDisplayDevices</c> 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
/// <c>DISPLAY_DEVICE.DeviceName</c> 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.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>
/// The <c>EnumDisplayMonitors</c> 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);
/// <summary>
/// <para>
/// The <c>EnumDisplaySettings</c> 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.
/// </para>
/// <para>
/// <c>Note</c> 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.
/// </para>
/// </summary>
/// <param name="lpszDeviceName">
/// <para>
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
/// </para>
/// <para>
/// This parameter is either <c>NULL</c> or a DISPLAY_DEVICE. <c>DeviceName</c> returned from EnumDisplayDevices. A <c>NULL</c> value
/// specifies the current display device on the computer on which the calling thread is running.
/// </para>
/// </param>
/// <param name="iModeNum">
/// <para>The type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ENUM_CURRENT_SETTINGS</term>
/// <term>Retrieve the current settings for the display device.</term>
/// </item>
/// <item>
/// <term>ENUM_REGISTRY_SETTINGS</term>
/// <term>Retrieve the settings for the display device that are currently stored in the registry.</term>
/// </item>
/// </list>
/// <para>
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls
/// to <c>EnumDisplaySettings</c>, 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.
/// </para>
/// <para>
/// When you call <c>EnumDisplaySettings</c> with iModeNum set to zero, the operating system initializes and caches information about
/// the display device. When you call <c>EnumDisplaySettings</c> 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.
/// </para>
/// </param>
/// <param name="lpDevMode">
/// <para>
/// A pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling
/// <c>EnumDisplaySettings</c>, set the <c>dmSize</c> member to , and set the <c>dmDriverExtra</c> member to indicate the size, in
/// bytes, of the additional space available to receive private driver data.
/// </para>
/// <para>The <c>EnumDisplaySettings</c> function sets values for the following five DEVMODE members:</para>
/// <list type="bullet">
/// <item>
/// <term><c>dmBitsPerPel</c></term>
/// </item>
/// <item>
/// <term><c>dmPelsWidth</c></term>
/// </item>
/// <item>
/// <term><c>dmPelsHeight</c></term>
/// </item>
/// <item>
/// <term><c>dmDisplayFlags</c></term>
/// </item>
/// <item>
/// <term><c>dmDisplayFrequency</c></term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// 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.
/// </para>
/// <para>DPI Virtualization</para>
/// <para>
/// 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.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>
/// The <c>EnumDisplaySettingsEx</c> 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.
/// </para>
/// <para>This function differs from EnumDisplaySettings in that there is a dwFlags parameter.</para>
/// <para>
/// <c>Note</c> 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.
/// </para>
/// </summary>
/// <param name="lpszDeviceName">
/// <para>
/// A pointer to a null-terminated string that specifies the display device about which graphics mode the function will obtain information.
/// </para>
/// <para>
/// This parameter is either <c>NULL</c> or a DISPLAY_DEVICE. <c>DeviceName</c> returned from EnumDisplayDevices. A <c>NULL</c> value
/// specifies the current display device on the computer that the calling thread is running on.
/// </para>
/// </param>
/// <param name="iModeNum">
/// <para>Indicates the type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ENUM_CURRENT_SETTINGS</term>
/// <term>Retrieve the current settings for the display device.</term>
/// </item>
/// <item>
/// <term>ENUM_REGISTRY_SETTINGS</term>
/// <term>Retrieve the settings for the display device that are currently stored in the registry.</term>
/// </item>
/// </list>
/// <para>
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls
/// to <c>EnumDisplaySettingsEx</c>, 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.
/// </para>
/// <para>
/// When you call <c>EnumDisplaySettingsEx</c> with iModeNum set to zero, the operating system initializes and caches information
/// about the display device. When you call <c>EnumDisplaySettingsEx</c> 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.
/// </para>
/// </param>
/// <param name="lpDevMode">
/// <para>
/// A pointer to a DEVMODE structure into which the function stores information about the specified graphics mode. Before calling
/// <c>EnumDisplaySettingsEx</c>, set the <c>dmSize</c> member to <c>sizeof</c> (DEVMODE), and set the <c>dmDriverExtra</c> member to
/// indicate the size, in bytes, of the additional space available to receive private driver data.
/// </para>
/// <para>
/// The <c>EnumDisplaySettingsEx</c> function will populate the <c>dmFields</c> member of the <c>lpDevMode</c> and one or more other
/// members of the DEVMODE structure. To determine which members were set by the call to <c>EnumDisplaySettingsEx</c>, inspect the
/// dmFields bitmask. Some of the fields typically populated by this function include:
/// </para>
/// <list type="bullet">
/// <item>
/// <term><c>dmBitsPerPel</c></term>
/// </item>
/// <item>
/// <term><c>dmPelsWidth</c></term>
/// </item>
/// <item>
/// <term><c>dmPelsHeight</c></term>
/// </item>
/// <item>
/// <term><c>dmDisplayFlags</c></term>
/// </item>
/// <item>
/// <term><c>dmDisplayFrequency</c></term>
/// </item>
/// <item>
/// <term><c>dmPosition</c></term>
/// </item>
/// <item>
/// <term><c>dmDisplayOrientation</c></term>
/// </item>
/// </list>
/// </param>
/// <param name="dwFlags">
/// <para>This parameter can be the following value.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>EDS_RAWMODE</term>
/// <term>
/// 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.
/// </term>
/// </item>
/// <item>
/// <term>EDS_ROTATEDMODE</term>
/// <term>
/// 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.
/// </term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// 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.
/// </para>
/// <para>DPI Virtualization</para>
/// <para>
/// 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.
/// </para>
/// </remarks>
// 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);
/// <summary>
/// <para>The <c>GetMonitorInfo</c> function retrieves information about a display monitor.</para>
/// </summary>