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

Commit 0bb497c

Browse files
committed
Add User32 ChangeWindowMessageFilterEx and more
Also adds `GetParent`, `EnumChildWindows` Closes #540 Closes #532
1 parent 395b66d commit 0bb497c

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

src/User32/PublicAPI.Unshipped.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
PInvoke.User32.CHANGEFILTERSTRUCT
2+
PInvoke.User32.CHANGEFILTERSTRUCT.CHANGEFILTERSTRUCT() -> void
3+
PInvoke.User32.CHANGEFILTERSTRUCT.ExtStatus -> uint
4+
PInvoke.User32.CHANGEFILTERSTRUCT.cbSize -> uint
15
PInvoke.User32.EnumDisplayDevicesFlags
26
PInvoke.User32.EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME = 1 -> PInvoke.User32.EnumDisplayDevicesFlags
37
PInvoke.User32.EnumDisplaySettingsExFlags
@@ -9,6 +13,8 @@ PInvoke.User32.MONITORINFO_Flags.None = 0 -> PInvoke.User32.MONITORINFO_Flags
913
PInvoke.User32.WindowStylesEx.WS_EX_NOREDIRECTIONBITMAP = 2097152 -> PInvoke.User32.WindowStylesEx
1014
const PInvoke.User32.ENUM_CURRENT_SETTINGS = 4294967295 -> uint
1115
const PInvoke.User32.ENUM_REGISTRY_SETTINGS = 4294967294 -> uint
16+
static PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, System.IntPtr pChangeFilterStruct) -> bool
17+
static PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, ref PInvoke.User32.CHANGEFILTERSTRUCT? pChangeFilterStruct) -> bool
1218
static PInvoke.User32.CreateCursor(System.IntPtr hInst, int xHotspot, int yHotSpot, int nWidth, int nHeight, System.ReadOnlySpan<byte> pvANDPlane, System.ReadOnlySpan<byte> pvXORPlane) -> PInvoke.User32.SafeCursorHandle
1319
static PInvoke.User32.DrawText(PInvoke.User32.SafeDCHandle hdc, System.Span<char> lpchText, ref PInvoke.RECT lprc, PInvoke.User32.TextFormats format) -> int
1420
static PInvoke.User32.DrawTextEx(PInvoke.User32.SafeDCHandle hdc, System.Span<char> lpchText, ref PInvoke.RECT lprc, uint dwDTFormat, PInvoke.User32.DRAWTEXTPARAMS? lpDTParams) -> int
@@ -39,9 +45,12 @@ static PInvoke.User32.MsgWaitForMultipleObjectsEx(uint nCount, System.ReadOnlySp
3945
static PInvoke.User32.QueryDisplayConfig(uint Flags, ref int pNumPathArrayElements, System.Span<PInvoke.User32.DISPLAYCONFIG_PATH_INFO> pPathInfoArray, ref int pNumModeInfoArrayElements, System.Span<PInvoke.User32.DISPLAYCONFIG_MODE_INFO> pModeInfoArray, PInvoke.User32.DISPLAYCONFIG_TOPOLOGY_ID pCurrentTopologyId) -> int
4046
static PInvoke.User32.RealGetWindowClass(System.IntPtr hwnd, System.Span<char> pszType) -> uint
4147
static PInvoke.User32.SendInput(int nInputs, System.ReadOnlySpan<PInvoke.User32.INPUT> pInputs, int cbSize) -> uint
48+
static extern PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, PInvoke.User32.CHANGEFILTERSTRUCT* pChangeFilterStruct) -> bool
49+
static extern PInvoke.User32.EnumChildWindows(System.IntPtr hWndParent, System.IntPtr lpEnumFunc, nint lParam) -> bool
4250
static extern PInvoke.User32.EnumDisplayDevices(char* lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
4351
static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode) -> bool
4452
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
53+
static extern PInvoke.User32.GetParent(System.IntPtr hWnd) -> System.IntPtr
4554
static extern PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, char* lpBuffer, int cchBufferMax) -> int
4655
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
4756
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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="CHANGEFILTERSTRUCT"/> nested type.
8+
/// </content>
9+
public partial class User32
10+
{
11+
/// <summary>Contains extended result information obtained by calling the ChangeWindowMessageFilterEx function.</summary>
12+
/// <remarks>
13+
/// <para>Certain messages whose value is smaller than <b>WM_USER</b> are required to pass through the filter, regardless of the filter setting. There will be no effect when you attempt to use this function to allow or block such messages.</para>
14+
/// <para>An application may use the <a href = "https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-changewindowmessagefilter">ChangeWindowMessageFilter</a> function to allow or block a message in a process-wide manner. If the message is allowed by either the process message filter or the window message filter, it will be delivered to the window.</para>
15+
/// <para>The following table lists the possible values returned in <b>ExtStatus</b>.</para>
16+
/// <para>This doc was truncated.</para>
17+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/ns-winuser-changefilterstruct#">Read more on docs.microsoft.com</see>.</para>
18+
/// </remarks>
19+
public struct CHANGEFILTERSTRUCT
20+
{
21+
/// <summary>
22+
/// <para>Type: <b>DWORD</b>The size of the structure, in bytes. Must be set to <c>sizeof(CHANGEFILTERSTRUCT)</c>, otherwise the function fails with <b>ERROR_INVALID_PARAMETER</b>.</para>
23+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/ns-winuser-changefilterstruct#members">Read more on docs.microsoft.com</see>.</para>
24+
/// </summary>
25+
public uint cbSize;
26+
27+
/// <summary>
28+
/// <para>Type: <b>DWORD</b>If the function succeeds, this field contains one of the following values.</para>
29+
/// <para>This doc was truncated.</para>
30+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/ns-winuser-changefilterstruct#members">Read more on docs.microsoft.com</see>.</para>
31+
/// </summary>
32+
public uint ExtStatus;
33+
}
34+
}
35+
}

src/User32/User32.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,82 @@ public static unsafe extern uint MsgWaitForMultipleObjectsEx(
39443944
WakeMask dwWakeMask,
39453945
MsgWaitForMultipleObjectsExFlags dwFlags);
39463946

3947+
/// <summary>Modifies the User Interface Privilege Isolation (UIPI) message filter for a specified window.</summary>
3948+
/// <param name = "hwnd">
3949+
/// <para>Type: <b>HWND</b></para>
3950+
/// <para>A handle to the window whose UIPI message filter is to be modified.</para>
3951+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-changewindowmessagefilterex#parameters">Read more on docs.microsoft.com</see>.</para>
3952+
/// </param>
3953+
/// <param name = "message">
3954+
/// <para>Type: <b>UINT</b></para>
3955+
/// <para>The message that the message filter allows through or blocks.</para>
3956+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-changewindowmessagefilterex#parameters">Read more on docs.microsoft.com</see>.</para>
3957+
/// </param>
3958+
/// <param name = "action">
3959+
/// <para>Type: <b>DWORD</b>The action to be performed, and can take one of the following values:</para>
3960+
/// <para>This doc was truncated.</para>
3961+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-changewindowmessagefilterex#parameters">Read more on docs.microsoft.com</see>.</para>
3962+
/// </param>
3963+
/// <param name = "pChangeFilterStruct">
3964+
/// <para>Type: <b>PCHANGEFILTERSTRUCT</b></para>
3965+
/// <para>Optional pointer to a <a href = "https://docs.microsoft.com/windows/desktop/api/winuser/ns-winuser-changefilterstruct">CHANGEFILTERSTRUCT</a> structure.</para>
3966+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-changewindowmessagefilterex#parameters">Read more on docs.microsoft.com</see>.</para>
3967+
/// </param>
3968+
/// <returns>
3969+
/// <para>Type: <b>BOOL</b></para>
3970+
/// <para>If the function succeeds, it returns <b>TRUE</b>; otherwise, it returns <b>FALSE</b>. To get extended error information, call <a href = "https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
3971+
/// </returns>
3972+
/// <remarks>
3973+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-changewindowmessagefilterex">Learn more about this API from docs.microsoft.com</see>.</para>
3974+
/// </remarks>
3975+
[DllImport("User32", ExactSpelling = true, SetLastError = true)]
3976+
[return: MarshalAs(UnmanagedType.Bool)]
3977+
public static extern unsafe bool ChangeWindowMessageFilterEx(IntPtr hwnd, uint message, uint action, [Friendly(FriendlyFlags.Bidirectional | FriendlyFlags.Optional)] CHANGEFILTERSTRUCT* pChangeFilterStruct);
3978+
3979+
/// <summary>Retrieves a handle to the specified window's parent or owner.</summary>
3980+
/// <param name = "hWnd">
3981+
/// <para>Type: <b>HWND</b></para>
3982+
/// <para>A handle to the window whose parent window handle is to be retrieved.</para>
3983+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-getparent#parameters">Read more on docs.microsoft.com</see>.</para>
3984+
/// </param>
3985+
/// <returns>
3986+
/// <para>Type: <b>HWND</b>If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window with the <b>WS_POPUP</b> style, the return value is a handle to the owner window.If the function fails, the return value is <b>NULL</b>. To get extended error information, call <a href = "https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.This function typically fails for one of the following reasons:</para>
3987+
/// <para></para>
3988+
/// <para>This doc was truncated.</para>
3989+
/// </returns>
3990+
/// <remarks>
3991+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-getparent">Learn more about this API from docs.microsoft.com</see>.</para>
3992+
/// </remarks>
3993+
[DllImport("User32", ExactSpelling = true, SetLastError = true)]
3994+
public static extern IntPtr GetParent(IntPtr hWnd);
3995+
3996+
/// <summary>Enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function.</summary>
3997+
/// <param name = "hWndParent">
3998+
/// <para>Type: <b>HWND</b></para>
3999+
/// <para>A handle to the parent window whose child windows are to be enumerated. If this parameter is <b>NULL</b>, this function is equivalent to <a href = "https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-enumwindows">EnumWindows</a>.</para>
4000+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-enumchildwindows#parameters">Read more on docs.microsoft.com</see>.</para>
4001+
/// </param>
4002+
/// <param name = "lpEnumFunc">
4003+
/// <para>Type: <b>WNDENUMPROC</b></para>
4004+
/// <para>A pointer to an application-defined callback function. For more information, see <a href = "https://docs.microsoft.com/previous-versions/windows/desktop/legacy/ms633493(v=vs.85)">EnumChildProc</a>.</para>
4005+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-enumchildwindows#parameters">Read more on docs.microsoft.com</see>.</para>
4006+
/// </param>
4007+
/// <param name = "lParam">
4008+
/// <para>Type: <b>LPARAM</b></para>
4009+
/// <para>An application-defined value to be passed to the callback function.</para>
4010+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-enumchildwindows#parameters">Read more on docs.microsoft.com</see>.</para>
4011+
/// </param>
4012+
/// <returns>
4013+
/// <para>Type: <b>BOOL</b></para>
4014+
/// <para>The return value is not used.</para>
4015+
/// </returns>
4016+
/// <remarks>
4017+
/// <para><see href = "https://docs.microsoft.com/en-us/windows/win32/api//winuser/nf-winuser-enumchildwindows">Learn more about this API from docs.microsoft.com</see>.</para>
4018+
/// </remarks>
4019+
[DllImport("User32", ExactSpelling = true)]
4020+
[return: MarshalAs(UnmanagedType.Bool)]
4021+
public static extern bool EnumChildWindows(IntPtr hWndParent, IntPtr lpEnumFunc, nint lParam);
4022+
39474023
/// <summary>
39484024
/// Retrieves the time of the last input event.
39494025
/// </summary>

0 commit comments

Comments
 (0)