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

Commit 2eaa7f2

Browse files
authored
Merge pull request #381 from vatsanm/HighDpiApi
Adding support for High DPI related API's and types.
2 parents 918b9e4 + c9e99dc commit 2eaa7f2

9 files changed

+644
-2
lines changed

src/User32/PublicAPI.Unshipped.txt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS
2+
PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS.DCDC_DEFAULT = 0 -> PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS
3+
PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS.DCDC_DISABLE_FONT_UPDATE = 1 -> PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS
4+
PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS.DCDC_DISABLE_RELAYOUT = 2 -> PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS
5+
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
6+
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DEFAULT = 0 -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
7+
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_ALL = 1 -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
8+
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
9+
PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS.DDC_DISABLE_RESIZE = 2 -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
10+
PInvoke.User32.DPI_AWARENESS
11+
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_INVALID = -1 -> PInvoke.User32.DPI_AWARENESS
12+
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_PER_MONITOR_AWARE = 2 -> PInvoke.User32.DPI_AWARENESS
13+
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_SYSTEM_AWARE = 1 -> PInvoke.User32.DPI_AWARENESS
14+
PInvoke.User32.DPI_AWARENESS.DPI_AWARENESS_UNAWARE = 0 -> PInvoke.User32.DPI_AWARENESS
15+
PInvoke.User32.DPI_HOSTING_BEHAVIOR
16+
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_DEFAULT = 0 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
17+
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_INVALID = -1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
18+
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED = 1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
119
PInvoke.User32.GetNextWindowCommands
220
PInvoke.User32.GetNextWindowCommands.GW_HWNDNEXT = 2 -> PInvoke.User32.GetNextWindowCommands
321
PInvoke.User32.GetNextWindowCommands.GW_HWNDPREV = 3 -> PInvoke.User32.GetNextWindowCommands
@@ -15,6 +33,9 @@ PInvoke.User32.SendMessageTimeoutFlags.SMTO_BLOCK = 1 -> PInvoke.User32.SendMess
1533
PInvoke.User32.SendMessageTimeoutFlags.SMTO_ERRORONEXIT = 32 -> PInvoke.User32.SendMessageTimeoutFlags
1634
PInvoke.User32.SendMessageTimeoutFlags.SMTO_NORMAL = 0 -> PInvoke.User32.SendMessageTimeoutFlags
1735
PInvoke.User32.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG = 8 -> PInvoke.User32.SendMessageTimeoutFlags
36+
PInvoke.User32.WindowMessage.WM_DPICHANGED_AFTERPARENT = 739 -> PInvoke.User32.WindowMessage
37+
PInvoke.User32.WindowMessage.WM_DPICHANGED_BEFOREPARENT = 738 -> PInvoke.User32.WindowMessage
38+
PInvoke.User32.WindowMessage.WM_GETDPISCALEDSIZE = 740 -> PInvoke.User32.WindowMessage
1839
PInvoke.User32.mouse_eventFlags
1940
PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_ABSOLUTE = 32768 -> PInvoke.User32.mouse_eventFlags
2041
PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_HWHEEL = 4096 -> PInvoke.User32.mouse_eventFlags
@@ -28,14 +49,42 @@ PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_RIGHTUP = 16 -> PInvoke.User32.mouse
2849
PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_WHEEL = 2048 -> PInvoke.User32.mouse_eventFlags
2950
PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_XDOWN = 128 -> PInvoke.User32.mouse_eventFlags
3051
PInvoke.User32.mouse_eventFlags.MOUSEEVENTF_XUP = 256 -> PInvoke.User32.mouse_eventFlags
52+
static PInvoke.User32.AdjustWindowRectExForDpi(System.IntPtr lpRect, PInvoke.User32.WindowStyles dwStyle, bool bMenu, PInvoke.User32.WindowStylesEx dwExStyle, int dpi) -> bool
3153
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
3254
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
3355
static PInvoke.User32.GetNextWindow(System.IntPtr hWnd, PInvoke.User32.GetNextWindowCommands wCmd) -> System.IntPtr
56+
static PInvoke.User32.SystemParametersInfoForDpi(PInvoke.User32.SystemParametersInfoAction uiAction, int uiParam, System.IntPtr pvParam, PInvoke.User32.SystemParametersInfoFlags fWinIni, int dpi) -> bool
3457
static PInvoke.User32.mouse_event(PInvoke.User32.mouse_eventFlags dwFlags, int dx, int dy, int dwData, System.IntPtr dwExtraInfo) -> void
58+
static extern PInvoke.User32.AdjustWindowRectExForDpi(PInvoke.RECT* lpRect, PInvoke.User32.WindowStyles dwStyle, bool bMenu, PInvoke.User32.WindowStylesEx dwExStyle, int dpi) -> bool
59+
static extern PInvoke.User32.AreDpiAwarenessContextsEqual(System.IntPtr dpiContextA, System.IntPtr dpiContextB) -> bool
3560
static extern PInvoke.User32.DestroyWindow(System.IntPtr hWnd) -> bool
61+
static extern PInvoke.User32.EnableNonClientDpiScaling(System.IntPtr hwnd) -> bool
62+
static extern PInvoke.User32.GetAwarenessFromDpiAwarenessContext(System.IntPtr dpiAwarenessContext) -> PInvoke.User32.DPI_AWARENESS
63+
static extern PInvoke.User32.GetDialogControlDpiChangeBehavior(System.IntPtr hWnd) -> PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS
64+
static extern PInvoke.User32.GetDialogDpiChangeBehavior(System.IntPtr hDlg) -> PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS
65+
static extern PInvoke.User32.GetDpiForSystem() -> int
66+
static extern PInvoke.User32.GetDpiForWindow(System.IntPtr hwnd) -> int
67+
static extern PInvoke.User32.GetDpiFromDpiAwarenessContext(System.IntPtr dpiAwarenessContext) -> int
68+
static extern PInvoke.User32.GetSystemDpiForProcess(PInvoke.Kernel32.SafeObjectHandle hProcess) -> int
69+
static extern PInvoke.User32.GetSystemMetricsForDpi(int nIndex, int dpi) -> bool
70+
static extern PInvoke.User32.GetThreadDpiAwarenessContext() -> System.IntPtr
71+
static extern PInvoke.User32.GetThreadDpiHostingBehavior() -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
3672
static extern PInvoke.User32.GetTopWindow(System.IntPtr hWnd) -> System.IntPtr
3773
static extern PInvoke.User32.GetWindow(System.IntPtr hWnd, PInvoke.User32.GetWindowCommands wCmd) -> System.IntPtr
74+
static extern PInvoke.User32.GetWindowDpiAwarenessContext(System.IntPtr hwnd) -> System.IntPtr
75+
static extern PInvoke.User32.GetWindowDpiHostingBehavior(System.IntPtr hwnd) -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
76+
static extern PInvoke.User32.IsValidDpiAwarenessContext(System.IntPtr dpiAwarenessContext) -> bool
3877
static extern PInvoke.User32.SendMessageTimeout(System.IntPtr hWnd, PInvoke.User32.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, PInvoke.User32.SendMessageTimeoutFlags flags, int timeout, out System.IntPtr pdwResult) -> System.IntPtr
78+
static extern PInvoke.User32.SetDialogControlDpiChangeBehavior(System.IntPtr hwnd, PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS mask, PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS values) -> bool
79+
static extern PInvoke.User32.SetDialogDpiChangeBehavior(System.IntPtr hDlg, PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS mask, PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS values) -> bool
3980
static extern PInvoke.User32.SetLastErrorEx(uint dwErrCode, uint dwType) -> void
81+
static extern PInvoke.User32.SetProcessDpiAwarenessContext(System.IntPtr dpiAWarenessContext) -> bool
82+
static extern PInvoke.User32.SetThreadDpiAwarenessContext(System.IntPtr dpiContext) -> System.IntPtr
83+
static extern PInvoke.User32.SetThreadDpiHostingBehavior(PInvoke.User32.DPI_HOSTING_BEHAVIOR dpiHostingBehavior) -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
4084
static extern PInvoke.User32.SetWindowText(System.IntPtr hWnd, string lpString) -> bool
41-
static extern PInvoke.User32.mouse_event(PInvoke.User32.mouse_eventFlags dwFlags, int dx, int dy, int dwData, void* dwExtraInfo) -> void
85+
static extern PInvoke.User32.SystemParametersInfoForDpi(PInvoke.User32.SystemParametersInfoAction uiAction, int uiParam, void* pvParam, PInvoke.User32.SystemParametersInfoFlags fWinIni, int dpi) -> bool
86+
static extern PInvoke.User32.mouse_event(PInvoke.User32.mouse_eventFlags dwFlags, int dx, int dy, int dwData, void* dwExtraInfo) -> void
87+
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE -> System.IntPtr
88+
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 -> System.IntPtr
89+
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE -> System.IntPtr
90+
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE -> System.IntPtr
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) All 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 nested type <see cref="DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS"/>
10+
/// </content>
11+
public partial class User32
12+
{
13+
/// <summary>
14+
/// Describes per-monitor DPI scaling behavior overrides for child windows within dialogs. The values in this enumeration are bitfields and can be combined.
15+
/// </summary>
16+
/// <remarks>
17+
/// This enum is used with SetDialogControlDpiChangeBehavior in order to override the default per-monitor DPI scaling behavior for a child window within a dialog.
18+
///
19+
/// These settings only apply to individual controls within dialogs. The dialog-wide per-monitor DPI scaling behavior of a dialog is controlled by <see cref="DIALOG_DPI_CHANGE_BEHAVIORS"/>.
20+
/// </remarks>
21+
[Flags]
22+
public enum DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS : int
23+
{
24+
/// <summary>
25+
/// The default behavior of the dialog manager. The dialog managed will update the font, size, and position of the child window on DPI changes.
26+
/// </summary>
27+
DCDC_DEFAULT = 0x0000,
28+
29+
/// <summary>
30+
/// Prevents the dialog manager from sending an updated font to the child window via WM_SETFONT in response to a DPI change.
31+
/// </summary>
32+
DCDC_DISABLE_FONT_UPDATE = 0x0001,
33+
34+
/// <summary>
35+
/// Prevents the dialog manager from resizing and repositioning the child window in response to a DPI change.
36+
/// </summary>
37+
DCDC_DISABLE_RELAYOUT = 0x0002,
38+
}
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) All 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 nested type <see cref="DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS"/>
10+
/// </content>
11+
public partial class User32
12+
{
13+
/// <summary>
14+
/// In Per Monitor v2 contexts, dialogs will automatically respond to DPI changes by resizing themselves and re-computing the positions of their child windows (here referred to as re-layouting).
15+
/// This enum works in conjunction with SetDialogDpiChangeBehavior in order to override the default DPI scaling behavior for dialogs.
16+
/// This does not affect DPI scaling behavior for the child windows of dialogs(beyond re-layouting), which is controlled by <see cref="DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS"/>.
17+
/// </summary>
18+
[Flags]
19+
public enum DIALOG_DPI_CHANGE_BEHAVIORS : int
20+
{
21+
/// <summary>
22+
/// The default behavior of the dialog manager. In response to a DPI change, the dialog manager will re-layout each control, update the font on each control, resize the dialog, and update the dialog's own font.
23+
/// </summary>
24+
DDC_DEFAULT = 0x0000,
25+
26+
/// <summary>
27+
/// Prevents the dialog manager from responding to <see cref="WindowMessage.WM_GETDPISCALEDSIZE"/> and <see cref="WindowMessage.WM_DPICHANGED"/>, disabling all default DPI scaling behavior.
28+
/// </summary>
29+
DDC_DISABLE_ALL = 0x0001,
30+
31+
/// <summary>
32+
/// Prevents the dialog manager from resizing the dialog in response to a DPI change.
33+
/// </summary>
34+
DDC_DISABLE_RESIZE = 0x0002,
35+
36+
/// <summary>
37+
/// Prevents the dialog manager from re-layouting all of the dialogue's immediate children HWNDs in response to a DPI change.
38+
/// </summary>
39+
DDC_DISABLE_CONTROL_RELAYOUT = 0x0003,
40+
}
41+
}
42+
}

src/User32/User32+DPI_AWARENESS.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) All 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="DPI_AWARENESS"/> nested type.
8+
/// </content>
9+
public partial class User32
10+
{
11+
/// <summary>
12+
/// Identifies the dots per inch (dpi) setting for a thread, process, or window.
13+
/// </summary>
14+
public enum DPI_AWARENESS : int
15+
{
16+
/// <summary>
17+
/// Invalid DPI awareness. This is an invalid DPI awareness value.
18+
/// </summary>
19+
DPI_AWARENESS_INVALID = -1,
20+
21+
/// <summary>
22+
/// DPI unaware. This process does not scale for DPI changes and is always assumed to have a scale factor of 100% (96 DPI). It will be automatically scaled by the system on any other DPI setting.
23+
/// </summary>
24+
DPI_AWARENESS_UNAWARE = 0,
25+
26+
/// <summary>
27+
/// System DPI aware. This process does not scale for DPI changes. It will query for the DPI once and use that value for the lifetime of the process. If the DPI changes, the process will not adjust to the new DPI value. It will be automatically scaled up or down by the system when the DPI changes from the system value.
28+
/// </summary>
29+
DPI_AWARENESS_SYSTEM_AWARE = 1,
30+
31+
/// <summary>
32+
/// Per monitor DPI aware. This process checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes. These processes are not automatically scaled by the system.
33+
/// </summary>
34+
DPI_AWARENESS_PER_MONITOR_AWARE = 2,
35+
}
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) All 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 nested type <see cref="DPI_HOSTING_BEHAVIOR"/>
8+
/// </content>
9+
public partial class User32
10+
{
11+
/// <summary>
12+
/// Identifies the DPI hosting behavior for a window. This behavior allows windows created in the thread to host child windows with a different DPI_AWARENESS_CONTEXT.
13+
/// </summary>
14+
public enum DPI_HOSTING_BEHAVIOR : int
15+
{
16+
/// <summary>
17+
/// Invalid DPI hosting behavior. This usually occurs if the previous <see cref="SetThreadDpiHostingBehavior"/> call used an invalid parameter.
18+
/// </summary>
19+
DPI_HOSTING_BEHAVIOR_INVALID = -1,
20+
21+
/// <summary>
22+
/// Default DPI hosting behavior. The associated window behaves as normal, and cannot create or re-parent child windows with a different DPI_AWARENESS_CONTEXT.
23+
/// </summary>
24+
DPI_HOSTING_BEHAVIOR_DEFAULT = 0,
25+
26+
/// <summary>
27+
/// Mixed DPI hosting behavior. This enables the creation and re-parenting of child windows with different DPI_AWARENESS_CONTEXT. These child windows will be independently scaled by the OS.
28+
/// </summary>
29+
DPI_HOSTING_BEHAVIOR_MIXED = 1,
30+
}
31+
}
32+
}

src/User32/User32+WindowMessage.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,21 @@ public enum WindowMessage : int
982982
/// </summary>
983983
WM_DPICHANGED = 0x02E0,
984984

985+
/// <summary>
986+
/// For Per Monitor v2 top-level windows, this message is sent to all HWNDs in the child HWDN tree of the window that is undergoing a DPI change. This message occurs before the top-level window receives <see cref="WM_DPICHANGED"/>, and traverses the child tree from the bottom up.
987+
/// </summary>
988+
WM_DPICHANGED_BEFOREPARENT = 0x02E2,
989+
990+
/// <summary>
991+
/// For Per Monitor v2 top-level windows, this message is sent to all HWNDs in the child HWDN tree of the window that is undergoing a DPI change. This message occurs after the top-level window receives <see cref="WM_DPICHANGED"/>, and traverses the child tree from the top down.
992+
/// </summary>
993+
WM_DPICHANGED_AFTERPARENT = 0x02E3,
994+
995+
/// <summary>
996+
/// The WM_GETDPISCALEDSIZE message tells the operating system that the window will be sized to dimensions other than the default.
997+
/// </summary>
998+
WM_GETDPISCALEDSIZE = 0x02E4,
999+
9851000
/// <summary>
9861001
/// An application sends a WM_CUT message to an edit control or combo box to delete (cut) the current selection, if any, in the edit control and copy the deleted text to the clipboard in CF_TEXT format.
9871002
/// </summary>

0 commit comments

Comments
 (0)