Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit b160958

Browse files
committed
Added EnumDisplayDevices
1 parent 6378271 commit b160958

7 files changed

+179
-4
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Please send pull requests to add what you've come up with.
2020

2121
### How to build
2222

23+
Run the init script at the root of the repo. Run `init -installlocality machine` from an elevated prompt.
24+
2325
The `build.ps1` script at the root of this project will restore packages, build, and run tests.
2426
With the appropriate switch, this script will perform a subset of these functions.
2527

src/User32/PublicAPI.Unshipped.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DEFAULT = 0 -> PInvoke.User32.DIA
3434
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_ALL = 1 -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
3535
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_CONTROL_RELAYOUT = PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_ALL | PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_RESIZE -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
3636
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_RESIZE = 2 -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
37+
PInvoke.User32.DISPLAY_DEVICE
38+
PInvoke.User32.DISPLAY_DEVICE.DISPLAY_DEVICE() -> void
39+
PInvoke.User32.DISPLAY_DEVICE.DeviceID -> char*
40+
PInvoke.User32.DISPLAY_DEVICE.DeviceKey -> char*
41+
PInvoke.User32.DISPLAY_DEVICE.DeviceName -> char*
42+
PInvoke.User32.DISPLAY_DEVICE.DeviceString -> char*
43+
PInvoke.User32.DISPLAY_DEVICE.StateFlags -> PInvoke.User32.DisplayDeviceFlags
44+
PInvoke.User32.DISPLAY_DEVICE.cb -> uint
3745
PInvoke.User32.DPI_AWARENESS
3846
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_INVALID = -1 -> PInvoke.User32.DPI_AWARENESS
3947
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_PER_MONITOR_AWARE = 2 -> PInvoke.User32.DPI_AWARENESS
@@ -43,6 +51,15 @@ PInvoke.User32.DPI_HOSTING_BEHAVIOR
4351
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_DEFAULT = 0 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
4452
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_INVALID = -1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
4553
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED = 1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
54+
PInvoke.User32.DisplayDeviceFlags
55+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_ACTIVE = 1 -> PInvoke.User32.DisplayDeviceFlags
56+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_MIRRORING_DRIVER = 8 -> PInvoke.User32.DisplayDeviceFlags
57+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_MODESPRUNED = 134217728 -> PInvoke.User32.DisplayDeviceFlags
58+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_PRIMARY_DEVICE = 4 -> PInvoke.User32.DisplayDeviceFlags
59+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_REMOVABLE = 32 -> PInvoke.User32.DisplayDeviceFlags
60+
PInvoke.User32.DisplayDeviceFlags.DISPLAY_DEVICE_VGA_COMPATIBLE = 16 -> PInvoke.User32.DisplayDeviceFlags
61+
PInvoke.User32.EnumDisplayDevicesFlags
62+
PInvoke.User32.EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME = 1 -> PInvoke.User32.EnumDisplayDevicesFlags
4663
PInvoke.User32.GetMenuDefaultItemFlags
4764
PInvoke.User32.GetMenuDefaultItemFlags.GMDI_GOINTOPOPUPS = 2 -> PInvoke.User32.GetMenuDefaultItemFlags
4865
PInvoke.User32.GetMenuDefaultItemFlags.GMDI_USEDISABLED = 1 -> PInvoke.User32.GetMenuDefaultItemFlags
@@ -180,6 +197,9 @@ static PInvoke.User32.CreateCursor(System.IntPtr hInst, int xHotspot, int yHotSp
180197
static PInvoke.User32.CreateCursor(System.IntPtr hInst, int xHotspot, int yHotSpot, int nWidth, int nHeight, byte[] pvANDPlane, byte[] pvXORPlane) -> PInvoke.User32.SafeCursorHandle
181198
static PInvoke.User32.CreateWindowEx(PInvoke.User32.WindowStylesEx dwExStyle, short lpClassName, string lpWindowName, PInvoke.User32.WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, System.IntPtr hWndParent, System.IntPtr hMenu, System.IntPtr hInstance, System.IntPtr lpParam) -> System.IntPtr
182199
static PInvoke.User32.CreateWindowEx(PInvoke.User32.WindowStylesEx dwExStyle, short lpClassName, string lpWindowName, PInvoke.User32.WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, System.IntPtr hWndParent, System.IntPtr hMenu, System.IntPtr hInstance, void* lpParam) -> System.IntPtr
200+
static PInvoke.User32.DISPLAY_DEVICE.Create() -> PInvoke.User32.DISPLAY_DEVICE
201+
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, System.IntPtr lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
202+
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, ref PInvoke.User32.DISPLAY_DEVICE lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
183203
static PInvoke.User32.GetCursorInfo(System.IntPtr pci) -> bool
184204
static PInvoke.User32.GetCursorInfo(out PInvoke.User32.CURSORINFO pci) -> bool
185205
static PInvoke.User32.GetMenuBarInfo(System.IntPtr hwnd, PInvoke.User32.MenuObject idObject, int idItem, System.IntPtr pmbi) -> bool
@@ -209,6 +229,7 @@ static extern PInvoke.User32.AreDpiAwarenessContextsEqual(System.IntPtr dpiConte
209229
static extern PInvoke.User32.CreateCursor(System.IntPtr hInst, int xHotspot, int yHotSpot, int nWidth, int nHeight, byte* pvANDPlane, byte* pvXORPlane) -> PInvoke.User32.SafeCursorHandle
210230
static extern PInvoke.User32.DestroyWindow(System.IntPtr hWnd) -> bool
211231
static extern PInvoke.User32.EnableNonClientDpiScaling(System.IntPtr hwnd) -> bool
232+
static extern PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, PInvoke.User32.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
212233
static extern PInvoke.User32.GetAwarenessFromDpiAwarenessContext(System.IntPtr dpiAwarenessContext) -> PInvoke.User32.DPI_AWARENESS
213234
static extern PInvoke.User32.GetCursor() -> PInvoke.User32.SafeCursorHandle
214235
static extern PInvoke.User32.GetCursorInfo(PInvoke.User32.CURSORINFO* pci) -> bool

src/User32/User32+DISPLAY_DEVICE.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright © .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System.Runtime.InteropServices;
7+
8+
/// <content>
9+
/// Contains the <see cref="DISPLAY_DEVICE"/> nested type.
10+
/// </content>
11+
public partial class User32
12+
{
13+
/// <summary>
14+
/// Receives information about the display device specified by the <c>iDevNum</c> parameter of the <see cref="User32.EnumDisplayDevices"/> function.
15+
/// </summary>
16+
public unsafe struct DISPLAY_DEVICE
17+
{
18+
/// <summary>
19+
/// Size, in bytes, of the DISPLAY_DEVICE structure. This must be initialized prior to calling <see cref="User32.EnumDisplayDevices"/>.
20+
/// </summary>
21+
public uint cb;
22+
23+
/// <summary>
24+
/// An array of characters identifying the device name. This is either the adapter device or the monitor device.
25+
/// </summary>
26+
public fixed char DeviceName[32];
27+
28+
/// <summary>
29+
/// An array of characters containing the device context string. This is either a description of the display adapter or of the display monitor.
30+
/// </summary>
31+
public fixed char DeviceString[128];
32+
33+
/// <summary>
34+
/// Device state flags.
35+
/// </summary>
36+
public DisplayDeviceFlags StateFlags;
37+
38+
/// <summary>
39+
/// Not used.
40+
/// </summary>
41+
public fixed char DeviceID[128];
42+
43+
/// <summary>
44+
/// Reserved.
45+
/// </summary>
46+
public fixed char DeviceKey[128];
47+
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="DISPLAY_DEVICE"/> struct
50+
/// with the <see cref="cb" /> field initialized.
51+
/// </summary>
52+
/// <returns>
53+
/// An instance of the structure.
54+
/// </returns>
55+
public static DISPLAY_DEVICE Create() => new DISPLAY_DEVICE { cb = (uint)Marshal.SizeOf(typeof(DISPLAY_DEVICE)) };
56+
}
57+
}
58+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright © .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System;
7+
8+
/// <content>
9+
/// Contains the <see cref="DisplayDeviceFlags"/> nested type.
10+
/// </content>
11+
public partial class User32
12+
{
13+
/// <summary>
14+
/// Device state flags.
15+
/// </summary>
16+
[Flags]
17+
public enum DisplayDeviceFlags : uint
18+
{
19+
/// <summary>
20+
/// DISPLAY_DEVICE_ACTIVE specifies whether a monitor is presented as being "on" by the respective GDI view.
21+
/// Windows Vista: EnumDisplayDevices will only enumerate monitors that can be presented as being "on".
22+
/// </summary>
23+
DISPLAY_DEVICE_ACTIVE = 0x00000001,
24+
25+
/// <summary>
26+
/// Represents a pseudo device used to mirror application drawing for remoting or other purposes. An invisible pseudo monitor is associated with this device.
27+
/// For example, NetMeeting uses it. Note that <see cref="User32.GetSystemMetrics(User32.SystemMetric)"/> (SM_MONITORS) only accounts for visible display monitors.
28+
/// </summary>
29+
DISPLAY_DEVICE_MIRRORING_DRIVER = 0x00000008,
30+
31+
/// <summary>The device has more display modes than its output devices support.</summary>
32+
DISPLAY_DEVICE_MODESPRUNED = 0x08000000,
33+
34+
/// <summary>
35+
/// The primary desktop is on the device. For a system with a single display card, this is always set.
36+
/// For a system with multiple display cards, only one device can have this set.
37+
/// </summary>
38+
DISPLAY_DEVICE_PRIMARY_DEVICE = 0x00000004,
39+
40+
/// <summary>The device is removable; it cannot be the primary display.</summary>
41+
DISPLAY_DEVICE_REMOVABLE = 0x00000020,
42+
43+
/// <summary>The device is VGA compatible.</summary>
44+
DISPLAY_DEVICE_VGA_COMPATIBLE = 0x00000010,
45+
}
46+
}
47+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright © .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
/// <content>
7+
/// Contains the <see cref="EnumDisplayDevicesFlags"/> nested type.
8+
/// </content>
9+
public partial class User32
10+
{
11+
public enum EnumDisplayDevicesFlags : uint
12+
{
13+
EDD_GET_DEVICE_INTERFACE_NAME = 0x00000001,
14+
}
15+
}
16+
}

src/User32/User32+MonitorOptions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
namespace PInvoke
55
{
6-
using System;
7-
using System.Runtime.InteropServices;
8-
96
/// <content>
107
/// Contains the <see cref="MonitorOptions"/> nested type.
118
/// </content>

src/User32/User32.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,12 +1655,46 @@ public static extern unsafe int LookupIconIdFromDirectoryEx(
16551655
/// If the function fails, the return value is zero.
16561656
/// </returns>
16571657
/// <remarks>
1658-
/// See: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors#remarks
1658+
/// See: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors#remarks.
16591659
/// </remarks>
16601660
[DllImport(nameof(User32), SetLastError = true)]
16611661
[return: MarshalAs(UnmanagedType.Bool)]
16621662
public static extern unsafe bool EnumDisplayMonitors(IntPtr hdc, RECT* lprcClip, MONITORENUMPROC lpfnEnum, void* dwData);
16631663

1664+
/// <summary>
1665+
/// Lets you obtain information about the display devices in the current session.
1666+
/// </summary>
1667+
/// <param name="lpDevice">A pointer to the device name. If <c>NULL</c>, function returns information for the display adapter(s) on the machine, based on <paramref name="iDevNum"/>.</param>
1668+
/// <param name="iDevNum">
1669+
/// An index value that specifies the display device of interest.
1670+
/// The operating system identifies each display device in the current session with an index value.
1671+
/// 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.
1672+
/// </param>
1673+
/// <param name="lpDisplayDevice">
1674+
/// A pointer to a <see cref="DISPLAY_DEVICE"/> structure that receives information about the display device specified by <paramref name="iDevNum"/>.
1675+
/// Before calling <see cref="EnumDisplayDevices"/>, you must initialize the member <see cref="DISPLAY_DEVICE.cb"/> to the size, in bytes, of <see cref="DISPLAY_DEVICE"/>.
1676+
/// </param>
1677+
/// <param name="dwFlags">
1678+
/// Set this flag to <see cref="EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME"/> to retrieve the device interface name for <c>GUID_DEVINTERFACE_MONITOR</c>, which is registered by the operating system on a per monitor basis.
1679+
/// The value is placed in the <see cref="DISPLAY_DEVICE.DeviceID"/> structure returned in <paramref name="lpDisplayDevice"/>.
1680+
/// The resulting device interface name can be used with SetupAPI functions and serves as a link between GDI monitor devices and SetupAPI monitor devices.
1681+
/// </param>
1682+
/// <returns>
1683+
/// If the function succeeds, the return value is nonzero.
1684+
/// If the function fails, the return value is zero.
1685+
/// The function fails if <paramref name="iDevNum"/> is greater than the largest device index.
1686+
/// </returns>
1687+
/// <remarks>
1688+
/// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaydevicesa#remarks.
1689+
/// </remarks>
1690+
[DllImport(nameof(User32), SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "EnumDisplayDevicesW")]
1691+
[return: MarshalAs(UnmanagedType.Bool)]
1692+
public static unsafe extern bool EnumDisplayDevices(
1693+
[MarshalAs(UnmanagedType.LPWStr)] string lpDevice,
1694+
uint iDevNum,
1695+
[Friendly(FriendlyFlags.Bidirectional)] DISPLAY_DEVICE* lpDisplayDevice,
1696+
EnumDisplayDevicesFlags dwFlags);
1697+
16641698
[DllImport(nameof(User32), SetLastError = true, CharSet = CharSet.Unicode)]
16651699
[return: MarshalAs(UnmanagedType.Bool)]
16661700
public static extern bool GetClassInfoEx(

0 commit comments

Comments
 (0)