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

add a couple of APIs from user32.dll #595

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/User32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ PInvoke.User32.EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME = 1 -> PInv
PInvoke.User32.EnumDisplaySettingsExFlags
PInvoke.User32.EnumDisplaySettingsExFlags.EDS_RAWMODE = 2 -> PInvoke.User32.EnumDisplaySettingsExFlags
PInvoke.User32.EnumDisplaySettingsExFlags.EDS_ROTATEDMODE = 4 -> PInvoke.User32.EnumDisplaySettingsExFlags
PInvoke.User32.ICONINFO
PInvoke.User32.ICONINFO.ICONINFO() -> void
PInvoke.User32.ICONINFO.fIcon -> bool
PInvoke.User32.ICONINFO.xHotspot -> int
PInvoke.User32.ICONINFO.yHotspot -> int
PInvoke.User32.ICONINFO.hbmMask -> System.IntPtr
PInvoke.User32.ICONINFO.hbmColor -> System.IntPtr
PInvoke.User32.LASTINPUTINFO
PInvoke.User32.LASTINPUTINFO.LASTINPUTINFO() -> void
PInvoke.User32.LASTINPUTINFO.cbSize -> int
Expand Down Expand Up @@ -176,6 +183,7 @@ PInvoke.User32.StaticControlWindowStyles.SS_WORDELLIPSIS = PInvoke.User32.Static
PInvoke.User32.WindowStylesEx.WS_EX_NOREDIRECTIONBITMAP = 2097152 -> PInvoke.User32.WindowStylesEx
const PInvoke.User32.ENUM_CURRENT_SETTINGS = 4294967295 -> uint
const PInvoke.User32.ENUM_REGISTRY_SETTINGS = 4294967294 -> uint
const PInvoke.User32.ASFW_ANY = 4294967295 -> uint
static PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, System.IntPtr pChangeFilterStruct) -> bool
static PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, ref PInvoke.User32.CHANGEFILTERSTRUCT? pChangeFilterStruct) -> bool
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
Expand All @@ -192,11 +200,21 @@ static PInvoke.User32.EnumDisplaySettingsEx(System.ReadOnlySpan<char> lpszDevice
static PInvoke.User32.EnumDisplaySettingsEx(char[] lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
static PInvoke.User32.GetClassName(System.IntPtr hWnd, System.Span<char> lpClassName) -> int
static PInvoke.User32.GetClipboardFormatName(int format, System.Span<char> lpszFormatName) -> int
static PInvoke.User32.GetIconInfo(PInvoke.User32.Cursors cursor, out PInvoke.User32.ICONINFO piconinfo) -> bool
static PInvoke.User32.GetIconInfo(PInvoke.User32.Cursors cursor, PInvoke.User32.ICONINFO* piconinfo) -> bool
static PInvoke.User32.GetIconInfo(PInvoke.User32.Cursors cursor, System.IntPtr piconinfo) -> bool
static PInvoke.User32.GetIconInfo(PInvoke.User32.Icons icon, out PInvoke.User32.ICONINFO piconinfo) -> bool
static PInvoke.User32.GetIconInfo(PInvoke.User32.Icons icon, PInvoke.User32.ICONINFO* piconinfo) -> bool
static PInvoke.User32.GetIconInfo(PInvoke.User32.Icons icon, System.IntPtr piconinfo) -> bool
static PInvoke.User32.GetIconInfo(System.IntPtr hIcon, System.IntPtr piconinfo) -> bool
static PInvoke.User32.GetIconInfo(System.IntPtr hIcon, out PInvoke.User32.ICONINFO piconinfo) -> bool
static PInvoke.User32.GetLastInputInfo(System.IntPtr plii) -> bool
static PInvoke.User32.GetLastInputInfo(out PInvoke.User32.LASTINPUTINFO plii) -> bool
static PInvoke.User32.GetMenuString(System.IntPtr hMenu, uint uIDItem, System.Span<char> lpString, PInvoke.User32.GetMenuStateFlags flags) -> int
static PInvoke.User32.GetMonitorInfo(System.IntPtr hMonitor, PInvoke.User32.MONITORINFOEX* lpmi) -> bool
static PInvoke.User32.GetMonitorInfo(System.IntPtr hMonitor, out PInvoke.User32.MONITORINFOEX lpmi) -> bool
static PInvoke.User32.GetWindowLongPtr(System.IntPtr hWnd, PInvoke.User32.WindowLongIndexFlags nIndex) -> void*
static PInvoke.User32.GetWindowLongPtr_IntPtr(System.IntPtr hWnd, PInvoke.User32.WindowLongIndexFlags nIndex) -> System.IntPtr
static PInvoke.User32.GetWindowText(System.IntPtr hWnd, System.Span<char> lpString) -> int
static PInvoke.User32.LASTINPUTINFO.Create() -> PInvoke.User32.LASTINPUTINFO
static PInvoke.User32.LoadCursor(System.IntPtr hInstance, System.ReadOnlySpan<char> lpCursorName) -> PInvoke.User32.SafeCursorHandle
Expand All @@ -211,11 +229,17 @@ static PInvoke.User32.MsgWaitForMultipleObjectsEx(uint nCount, System.ReadOnlySp
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
static PInvoke.User32.RealGetWindowClass(System.IntPtr hwnd, System.Span<char> pszType) -> uint
static PInvoke.User32.SendInput(int nInputs, System.ReadOnlySpan<PInvoke.User32.INPUT> pInputs, int cbSize) -> uint
static extern PInvoke.User32.AllowSetForegroundWindow(int dwProcessId) -> bool
static extern PInvoke.User32.BringWindowToTop(System.IntPtr hWnd) -> bool
static extern PInvoke.User32.ChangeWindowMessageFilterEx(System.IntPtr hwnd, uint message, uint action, PInvoke.User32.CHANGEFILTERSTRUCT* pChangeFilterStruct) -> bool
static extern PInvoke.User32.DestroyIcon(System.IntPtr hIcon) -> int
static extern PInvoke.User32.GetIconInfo(System.IntPtr hIcon, PInvoke.User32.ICONINFO* piconinfo) -> bool
static extern PInvoke.User32.EnumChildWindows(System.IntPtr hWndParent, System.IntPtr lpEnumFunc, System.IntPtr lParam) -> bool
static extern PInvoke.User32.EnumDisplayDevices(char* lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode) -> bool
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
static extern PInvoke.User32.EnumThreadWindows(int dwThreadId, PInvoke.User32.WNDENUMPROC lpfn, System.IntPtr lParam) -> bool
static extern PInvoke.User32.FlashWindow(System.IntPtr hWnd, bool bInvert) -> bool
static extern PInvoke.User32.GetLastInputInfo(PInvoke.User32.LASTINPUTINFO* plii) -> bool
static extern PInvoke.User32.GetParent(System.IntPtr hWnd) -> System.IntPtr
static extern PInvoke.User32.GetProp(System.IntPtr hWnd, int atom) -> System.IntPtr
Expand All @@ -225,5 +249,17 @@ static extern PInvoke.User32.RemoveProp(System.IntPtr hWnd, int atom) -> System.
static extern PInvoke.User32.RemoveProp(System.IntPtr hWnd, string lpString) -> System.IntPtr
static extern PInvoke.User32.SetProp(System.IntPtr hWnd, int atom, System.IntPtr hData) -> bool
static extern PInvoke.User32.SetProp(System.IntPtr hWnd, string lpString, System.IntPtr hData) -> bool
static extern PInvoke.User32.ShowWindowAsync(System.IntPtr hWnd, PInvoke.User32.WindowShowStyle nCmdShow) -> bool
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_APPLICATION = 32512 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_ASTERISK = 32516 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_ERROR = 32513 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_EXCLAMATION = 32515 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_HAND = 32513 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_INFORMATION = 32516 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_QUESTION = 32514 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_SHIELD = 32518 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_WARNING = 32515 -> PInvoke.User32.Icons
PInvoke.User32.Icons.IDI_WINLOGO = 32517 -> PInvoke.User32.Icons
51 changes: 51 additions & 0 deletions src/User32/User32+ICONINFO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright © .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;

/// <content>
/// Contains the <see cref="ICONINFO"/> nested type.
/// </content>
public partial class User32
{
/// <summary>
/// Contains information about an icon or a cursor.
/// </summary>
public struct ICONINFO
{
/// <summary>
/// Contains information about an icon or a cursor.
/// </summary>
public bool fIcon;

/// <summary>
/// The x-coordinate of a cursor's hot spot. If this structure defines an icon,
/// the hot spot is always in the center of the icon, and this member is ignored.
/// </summary>
public int xHotspot;

/// <summary>
/// The y-coordinate of the cursor's hot spot. If this structure defines an icon,
/// the hot spot is always in the center of the icon, and this member is ignored.
/// </summary>
public int yHotspot;

/// <summary>
/// The icon bitmask bitmap. If this structure defines a black and white icon, this bitmask
/// is formatted so that the upper half is the icon AND bitmask and the lower half is the icon
/// XOR bitmask. Under this condition, the height should be an even multiple of two.
/// If this structure defines a color icon, this mask only defines the AND bitmask of the icon.
/// </summary>
public IntPtr hbmMask;

/// <summary>
/// A handle to the icon color bitmap. This member can be optional if this structure defines
/// a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND flag to the destination;
/// subsequently, the color bitmap is applied (using XOR) to the destination by using the SRCINVERT flag.
/// </summary>
public IntPtr hbmColor;
}
}
}
47 changes: 47 additions & 0 deletions src/User32/User32+Icons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright © .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
/// <content>
/// Contains the <see cref="Icons"/> nested type.
/// </content>
public static partial class User32
{
/// <summary>
/// Represents system predefined cursors.
/// </summary>
public enum Icons
{
/// <summary>Default application icon.</summary>
IDI_APPLICATION = 32512,

/// <summary>Asterisk icon. Same as IDI_INFORMATION.</summary>
IDI_ASTERISK = 32516,

/// <summary>Hand-shaped icon.</summary>
IDI_ERROR = 32513,

/// <summary>Exclamation point icon.Same as IDI_WARNING.</summary>
IDI_EXCLAMATION = 32515,

/// <summary>Hand-shaped icon.Same as IDI_ERROR.</summary>
IDI_HAND = 32513,

/// <summary>Asterisk icon.</summary>
IDI_INFORMATION = 32516,

/// <summary>Question mark icon.</summary>
IDI_QUESTION = 32514,

/// <summary>Security Shield icon.</summary>
IDI_SHIELD = 32518,

/// <summary>Exclamation point icon.</summary>
IDI_WARNING = 32515,

/// <summary>Default application icon. Windows 2000: Windows logo icon.</summary>
IDI_WINLOGO = 32517,
}
}
}
99 changes: 99 additions & 0 deletions src/User32/User32.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,55 @@ public static unsafe WINDOWPLACEMENT GetWindowPlacement(IntPtr hWnd)
}
}

/// <summary>
/// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.
/// </summary>
/// <param name="hWnd">A handle to the window and, indirectly, the class to which the window belongs.</param>
/// <param name="nIndex">The zero-based offset to the value to be set. Valid values are in the range zero
/// through the number of bytes of extra window memory, minus the size of a LONG_PTR. To set any other value,
/// specify one of the following values.
///
/// <list type="table">
/// <listheader><term>Value</term><term>Meaning</term></listheader>
/// <item><term>GWL_EXSTYLE(-20)</term><term>Retrieves the extended window styles.</term></item>
/// <item><term>GWLP_HINSTANCE(-6)</term><term>Retrieves a handle to the application instance.</term></item>
/// <item><term>GWLP_HWNDPARENT(-8)</term><term>Retrieves a handle to the parent window, if there is one.</term></item>
/// <item><term>GWLP_ID(-12)</term><term>Retrieves the identifier of the window.</term></item>
/// <item><term>GWL_STYLE (-16)</term><term>Retrieves the window styles.</term></item>
/// <item><term>GWLP_USERDATA</term><term>Retrieves the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.</term></item>
/// <item><term>GWLP_WNDPROC (-4)</term><term>Retrieves the pointer to the window procedure, or a handle representing the pointer to the window procedure. You must use the CallWindowProc function to call the window procedure.</term></item>
/// </list>
///
/// The following values are also available when the hWnd parameter identifies a dialog box.
///
/// <list type="table">
/// <listheader><term>Value</term><term>Meaning</term></listheader>
/// <item><term>DWLP_DLGPROC (DWLP_MSGRESULT + sizeof(LRESULT))</term><term>Retrieves the pointer to the dialog box procedure, or a handle representing the pointer to the dialog box procedure. You must use the CallWindowProc function to call the dialog box procedure.</term></item>
/// <item><term>DWLP_MSGRESULT (0)</term><term>Retrieves the return value of a message processed in the dialog box procedure.</term></item>
/// <item><term>DWLP_USER (DWLP_DLGPROC + sizeof(DLGPROC))</term><term>Retrieves extra information private to the application, such as handles or pointers.</term></item>
/// </list>
///
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the requested value.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
/// <para>If SetWindowLong or SetWindowLongPtr has not been called previously, GetWindowLongPtr returns zero for values in the extra window or class memory.</para>
/// </returns>
/// <remarks>
/// <para>Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.</para>
/// </remarks>
public static unsafe void* GetWindowLongPtr(IntPtr hWnd, WindowLongIndexFlags nIndex)
{
if (IntPtr.Size == 8)
{
return GetWindowLongPtr64(hWnd, nIndex);
}
else
{
return (void*)GetWindowLong(hWnd, nIndex);
}
}

/// <inheritdoc cref="GetMonitorInfo(IntPtr, MONITORINFO*)"/>
[NoFriendlyOverloads]
public static unsafe bool GetMonitorInfo(
Expand All @@ -481,5 +530,55 @@ public static unsafe bool GetMonitorInfo(
return GetMonitorInfo(hMonitor, lpmiLocal);
}
}

/// <summary>
/// Retrieves information about the specified icon or cursor.
/// </summary>
/// <remarks>
/// <para>
/// GetIconInfo creates bitmaps for the hbmMask and hbmCol or members of ICONINFO. The calling application
/// must manage these bitmaps and delete them when they are no longer necessary.
/// </para>
/// <para>
/// DPI Virtualization: This API does not participate in DPI virtualization. The output returned is not
/// affected by the DPI of the calling thread.
/// </para>
/// </remarks>
/// <param name="cursor">The cursor</param>
/// <param name="piconinfo">A pointer to an ICONINFO structure. The function fills in the structure's members.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero and the function fills in the members of the specified ICONINFO structure.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
/// by dwThreadId, the return value is FALSE.
/// </returns>
public static unsafe bool GetIconInfo(Cursors cursor, [Friendly(FriendlyFlags.Out)] ICONINFO* piconinfo)
{
return GetIconInfo(new IntPtr(MAKEINTRESOURCE((int)cursor)), piconinfo);
}

/// <summary>
/// Retrieves information about the specified icon or cursor.
/// </summary>
/// <remarks>
/// <para>
/// GetIconInfo creates bitmaps for the hbmMask and hbmCol or members of ICONINFO. The calling application
/// must manage these bitmaps and delete them when they are no longer necessary.
/// </para>
/// <para>
/// DPI Virtualization: This API does not participate in DPI virtualization. The output returned is not
/// affected by the DPI of the calling thread.
/// </para>
/// </remarks>
/// <param name="icon">The icon</param>
/// <param name="piconinfo">A pointer to an ICONINFO structure. The function fills in the structure's members.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero and the function fills in the members of the specified ICONINFO structure.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
/// by dwThreadId, the return value is FALSE.
/// </returns>
public static unsafe bool GetIconInfo(Icons icon, [Friendly(FriendlyFlags.Out)] ICONINFO* piconinfo)
{
return GetIconInfo(new IntPtr(MAKEINTRESOURCE((int)icon)), piconinfo);
}
}
}
Loading