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

Commit 9ec5e24

Browse files
committed
Add EnumDisplaySettings
1 parent 67506c8 commit 9ec5e24

7 files changed

+1214
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
using PInvoke;
5+
using Xunit;
6+
using static PInvoke.User32;
7+
8+
public partial class User32Facts
9+
{
10+
[Fact]
11+
public void EnumDisplaySettings_Test()
12+
{
13+
// Arrange
14+
var mode = DEVMODEW.Create();
15+
16+
// Act
17+
var result = EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref mode);
18+
19+
// Assert
20+
Assert.True(result);
21+
Assert.True(mode.dmPelsWidth > 0);
22+
Assert.True(mode.dmPelsHeight > 0);
23+
}
24+
}

src/User32/PublicAPI.Unshipped.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
PInvoke.User32.EnumDisplayDevicesFlags
22
PInvoke.User32.EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME = 1 -> PInvoke.User32.EnumDisplayDevicesFlags
3+
PInvoke.User32.EnumDisplaySettingsExFlags
4+
PInvoke.User32.EnumDisplaySettingsExFlags.EDS_RAWMODE = 2 -> PInvoke.User32.EnumDisplaySettingsExFlags
5+
PInvoke.User32.EnumDisplaySettingsExFlags.EDS_ROTATEDMODE = 4 -> PInvoke.User32.EnumDisplaySettingsExFlags
6+
const PInvoke.User32.ENUM_CURRENT_SETTINGS = 4294967295 -> uint
7+
const PInvoke.User32.ENUM_REGISTRY_SETTINGS = 4294967294 -> uint
38
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, System.IntPtr lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
49
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, ref PInvoke.DISPLAY_DEVICE lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
10+
static PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode) -> bool
11+
static PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODEW lpDevMode) -> bool
12+
static PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
13+
static PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODEW lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
514
static extern PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
15+
static extern PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, PInvoke.DEVMODEW* lpDevMode) -> bool
16+
static extern PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, PInvoke.DEVMODEW* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
617
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
718
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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="EnumDisplaySettingsExFlags"/> nested type.
10+
/// </content>
11+
public partial class User32
12+
{
13+
/// <summary>
14+
/// Flags for <see cref="EnumDisplaySettingsEx(string, uint, ref DEVMODEW, EnumDisplaySettingsExFlags)"/>.
15+
/// </summary>
16+
[Flags]
17+
public enum EnumDisplaySettingsExFlags : uint
18+
{
19+
/// <summary>
20+
/// If set, the function will return all graphics modes reported by the adapter driver, regardless of monitor capabilities.
21+
/// Otherwise, it will only return modes that are compatible with current monitors.
22+
/// </summary>
23+
EDS_RAWMODE = 0x00000002,
24+
25+
/// <summary>
26+
/// If set, the function will return graphics modes in all orientations.
27+
/// Otherwise, it will only return modes that have the same orientation as the one currently set for the requested display.
28+
/// </summary>
29+
EDS_ROTATEDMODE = 0x00000004,
30+
}
31+
}
32+
}

src/User32/User32.cs

+84
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public static partial class User32
6262

6363
public const uint WAIT_FAILED = 0xFFFFFFFF;
6464

65+
public const uint ENUM_CURRENT_SETTINGS = unchecked((uint)-1);
66+
67+
public const uint ENUM_REGISTRY_SETTINGS = unchecked((uint)-2);
68+
6569
/// <summary>
6670
/// A bitmap that is drawn by the window that owns the menu. The application must process the WM_MEASUREITEM and
6771
/// WM_DRAWITEM messages.
@@ -1696,6 +1700,86 @@ public static extern unsafe bool EnumDisplayDevices(
16961700
[Friendly(FriendlyFlags.Bidirectional)] DISPLAY_DEVICE* lpDisplayDevice,
16971701
EnumDisplayDevicesFlags dwFlags);
16981702

1703+
/// <summary>
1704+
/// 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.
1705+
/// </summary>
1706+
/// <param name="lpszDeviceName">
1707+
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
1708+
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(string, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
1709+
/// A <c>NULL</c> value specifies the current display device on the computer on which the calling thread is running.
1710+
/// </param>
1711+
/// <param name="iModeNum">
1712+
/// <para>The type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
1713+
/// <para><see cref="ENUM_CURRENT_SETTINGS"/>: Retrieve the current settings for the display device.</para>
1714+
/// <para><see cref="ENUM_REGISTRY_SETTINGS"/>: Retrieve the settings for the display device that are currently stored in the registry.</para>
1715+
/// <para>
1716+
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettings(string, uint, DEVMODEW*)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
1717+
/// and increment <paramref name="iModeNum"/> by one for each subsequent call.
1718+
/// </para>
1719+
/// <para>
1720+
/// Continue calling the function until the return value is zero.<br/>
1721+
/// When you call <see cref="EnumDisplaySettings(string, uint, DEVMODEW*)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1722+
/// When you call <see cref="EnumDisplaySettings(string, uint, DEVMODEW*)"/> with <paramref name="iModeNum"/> set to a nonzero value,
1723+
/// the function returns the information that was cached the last time the function was called with iModeNum set to zero.
1724+
/// </para>
1725+
/// </param>
1726+
/// <param name="lpDevMode">
1727+
/// A pointer to a <see cref="DEVMODEW"/> structure into which the function stores information about the specified graphics mode.
1728+
/// </param>
1729+
/// <remarks>
1730+
/// The function fails if <paramref name="iModeNum"/> is greater than the index of the display device's last graphics mode.
1731+
/// As noted in the description of the <paramref name="iModeNum"/> parameter, you can use this behavior to enumerate all of a display device's graphics modes.
1732+
/// </remarks>
1733+
/// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.</returns>
1734+
[DllImport(nameof(User32), EntryPoint = "EnumDisplaySettingsW")]
1735+
[return: MarshalAs(UnmanagedType.Bool)]
1736+
public static extern unsafe bool EnumDisplaySettings(
1737+
[MarshalAs(UnmanagedType.LPWStr)] string lpszDeviceName,
1738+
uint iModeNum,
1739+
[Friendly(FriendlyFlags.Bidirectional)]DEVMODEW* lpDevMode);
1740+
1741+
/// <summary>
1742+
/// 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.
1743+
/// </summary>
1744+
/// <param name="lpszDeviceName">
1745+
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
1746+
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(string, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
1747+
/// A <c>NULL</c> value specifies the current display device on the computer on which the calling thread is running.
1748+
/// </param>
1749+
/// <param name="iModeNum">
1750+
/// <para>The type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
1751+
/// <para><see cref="ENUM_CURRENT_SETTINGS"/>: Retrieve the current settings for the display device.</para>
1752+
/// <para><see cref="ENUM_REGISTRY_SETTINGS"/>: Retrieve the settings for the display device that are currently stored in the registry.</para>
1753+
/// <para>
1754+
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettingsEx(string, uint, DEVMODEW*, EnumDisplaySettingsExFlags)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
1755+
/// and increment <paramref name="iModeNum"/> by one for each subsequent call.
1756+
/// </para>
1757+
/// <para>
1758+
/// Continue calling the function until the return value is zero.<br/>
1759+
/// When you call <see cref="EnumDisplaySettingsEx(string, uint, DEVMODEW*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1760+
/// When you call <see cref="EnumDisplaySettingsEx(string, uint, DEVMODEW*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to a nonzero value,
1761+
/// the function returns the information that was cached the last time the function was called with iModeNum set to zero.
1762+
/// </para>
1763+
/// </param>
1764+
/// <param name="lpDevMode">
1765+
/// A pointer to a <see cref="DEVMODEW"/> structure into which the function stores information about the specified graphics mode.
1766+
/// </param>
1767+
/// <param name="dwFlags">
1768+
/// See documentation on the fields of <see cref="EnumDisplaySettingsExFlags"/>.
1769+
/// </param>
1770+
/// <remarks>
1771+
/// The function fails if <paramref name="iModeNum"/> is greater than the index of the display device's last graphics mode.
1772+
/// As noted in the description of the <paramref name="iModeNum"/> parameter, you can use this behavior to enumerate all of a display device's graphics modes.
1773+
/// </remarks>
1774+
/// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.</returns>
1775+
[DllImport(nameof(User32), EntryPoint = "EnumDisplaySettingsExW")]
1776+
[return: MarshalAs(UnmanagedType.Bool)]
1777+
public static extern unsafe bool EnumDisplaySettingsEx(
1778+
[MarshalAs(UnmanagedType.LPWStr)] string lpszDeviceName,
1779+
uint iModeNum,
1780+
[Friendly(FriendlyFlags.Bidirectional)] DEVMODEW* lpDevMode,
1781+
EnumDisplaySettingsExFlags dwFlags);
1782+
16991783
[DllImport(nameof(User32), SetLastError = true, CharSet = CharSet.Unicode)]
17001784
[return: MarshalAs(UnmanagedType.Bool)]
17011785
public static extern bool GetClassInfoEx(

0 commit comments

Comments
 (0)