Add a few signatures around window messages

With this signatures we can use rc.exe to compile a windows dialog, embed
it as a resource in a .Net executable then load and display it.

There is a working minimal sample in this repository :
https://github.com/vbfox/PInvoke.Forms.Test
This commit is contained in:
Julien Roncaglia 2016-08-21 18:06:47 +02:00
Родитель 360bf230cd
Коммит c0b59b7cb4
7 изменённых файлов: 537 добавлений и 29 удалений

Просмотреть файл

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeTypeMemberModifiers/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantUsingDirective/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FIXED_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
@ -28,7 +29,9 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FCONSTANT/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FFUNCTION/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FCLASS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FCONSTRUCTOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FFUNCTION/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FGLOBAL_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
@ -64,6 +67,27 @@
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=F655F53E49798D4C9BFEA6D23073BF4D/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=F655F53E49798D4C9BFEA6D23073BF4D/AbsolutePath/@EntryValue">G:\Code\pinvoke\src\PInvoke.sln.DotSettings</s:String>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=F655F53E49798D4C9BFEA6D23073BF4D/RelativePath/@EntryValue"></s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileF655F53E49798D4C9BFEA6D23073BF4D/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileF655F53E49798D4C9BFEA6D23073BF4D/RelativePriority/@EntryValue">1</s:Double>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Applicability/=File/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/CustomProperties/=Extension/@EntryIndexedValue">cs</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/CustomProperties/=FileName/@EntryIndexedValue">Base+Nested</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/CustomProperties/=ValidateFileName/@EntryIndexedValue">False</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Description/@EntryValue">Nested PInvoke declaration</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Field/=BASECLASS/@KeyIndexDefined">True</s:Boolean>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Field/=BASECLASS/Order/@EntryValue">0</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Field/=NESTED/@KeyIndexDefined">True</s:Boolean>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Field/=NESTED/InitialRange/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Field/=NESTED/Order/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Reformat/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Scope/=E8F0594528C33E45BBFEC6CFE851095D/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Scope/=E8F0594528C33E45BBFEC6CFE851095D/Type/@EntryValue">InCSharpProjectFile</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=67C1E0A08AB96D4BB8249F5551FDFD07/Text/@EntryValue">// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved.&#xD;// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.&#xD;&#xD;namespace PInvoke&#xD;{&#xD; /// &lt;content&gt;&#xD; /// Contains the &lt;see cref="$NESTED$"/&gt; nested type.&#xD; /// &lt;/content&gt;&#xD; public partial class $BASECLASS$&#xD; {&#xD; /// &lt;summary&gt;&#xD; /// &lt;/summary&gt;&#xD; public class $NESTED$&#xD; {&#xD; $END$&#xD; }&#xD; }&#xD;}</s:String></wpf:ResourceDictionary>

Просмотреть файл

@ -0,0 +1,46 @@
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. namespace PInvoke { using System.Runtime.InteropServices; /// <content> /// Contains the <see cref="DLGITEMTEMPLATE"/> nested type. /// </content> public partial class User32 { /// <summary>
/// Defines the dimensions and style of a control in a dialog box. One or more of these structures are combined with a
/// <see cref="DLGTEMPLATE" /> structure to form a standard template for a dialog box.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct DLGITEMTEMPLATE
{
/// <summary>
/// The style of the control. This member can be a combination of window style values (such as WS_BORDER) and one or
/// more of the control style values (such as BS_PUSHBUTTON and ES_LEFT).
/// </summary>
public int style;
/// <summary>
/// The extended styles for a window. This member is not used to create controls in dialog boxes, but applications that
/// use dialog box templates can use it to create other types of windows.
/// </summary>
public int dwExtendedStyle;
/// <summary>
/// The x-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative
/// to the upper-left corner of the dialog box's client area.
/// </summary>
public byte x;
/// <summary>
/// The y-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative
/// to the upper-left corner of the dialog box's client area.
/// </summary>
public byte y;
/// <summary>
/// The width, in dialog box units, of the control.
/// </summary>
public byte cx;
/// <summary>
/// The height, in dialog box units, of the control.
/// </summary>
public byte cy;
/// <summary>
/// The control identifier.
/// </summary>
public short id;
} } }

Просмотреть файл

@ -0,0 +1,54 @@
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. namespace PInvoke { using System.Runtime.InteropServices; /// <content> /// Contains the <see cref="DLGTEMPLATE"/> nested type. /// </content> public partial class User32 { /// <summary>
/// Defines the dimensions and style of a dialog box. This structure, always the first in a standard template for a
/// dialog box, also specifies the number of controls in the dialog box and therefore specifies the number of
/// subsequent <see cref="DLGITEMTEMPLATE" /> structures in the template.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct DLGTEMPLATE
{
/// <summary>
/// The style of the dialog box. This member can be a combination of window style values (such as WS_CAPTION and
/// WS_SYSMENU) and dialog box style values (such as DS_CENTER).
/// <para>
/// If the style member includes the DS_SETFONT style, the header of the dialog box template contains additional
/// data specifying the font to use for text in the client area and controls of the dialog box. The font data
/// begins on the WORD boundary that follows the title array. The font data specifies a 16-bit point size value and
/// a Unicode font name string. If possible, the system creates a font according to the specified values. Then the
/// system sends a WM_SETFONT message to the dialog box and to each control to provide a handle to the font. If
/// DS_SETFONT is not specified, the dialog box template does not include the font data.
/// </para>
/// <para>The DS_SHELLFONT style is not supported in the DLGTEMPLATE header.</para>
/// </summary>
public int style;
/// <summary>
/// The extended styles for a window. This member is not used to create dialog boxes, but applications that use dialog
/// box templates can use it to create other types of windows.
/// </summary>
public int dwExtendedStyle;
/// <summary>
/// The number of items in the dialog box.
/// </summary>
public short cdit;
/// <summary>
/// The x-coordinate, in dialog box units, of the upper-left corner of the dialog box.
/// </summary>
public byte x;
/// <summary>
/// The y-coordinate, in dialog box units, of the upper-left corner of the dialog box.
/// </summary>
public byte y;
/// <summary>
/// The width, in dialog box units, of the dialog box.
/// </summary>
public byte cx;
/// <summary>
/// The height, in dialog box units, of the dialog box.
/// </summary>
public byte cy;
} } }

Просмотреть файл

@ -0,0 +1,37 @@
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. namespace PInvoke { using System; using System.Runtime.InteropServices; /// <content> /// Contains the <see cref="MSG"/> nested type. /// </content> public partial class User32 { /// <summary>
/// Contains message information from a thread's message queue.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
/// <summary>
/// A handle to the window whose window procedure receives the message. This member is <see cref="IntPtr.Zero" /> when
/// the message is a thread message.
/// </summary>
public IntPtr hwnd;
/// <summary>
/// The message identifier. Applications can only use the low word; the high word is reserved by the system.
/// </summary>
public WindowMessage message;
/// <summary>
/// Additional information about the message. The exact meaning depends on the value of the message member.
/// </summary>
public IntPtr wParam;
/// <summary>
/// Additional information about the message. The exact meaning depends on the value of the message member.
/// </summary>
public IntPtr lParam;
/// <summary>
/// The time at which the message was posted.
/// </summary>
public int time;
/// <summary>
/// The cursor position, in screen coordinates, when the message was posted.
/// </summary>
public POINT pt;
} } }

Просмотреть файл

@ -0,0 +1,4 @@
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. namespace PInvoke { using System; /// <content> /// Contains the <see cref="PeekMessageRemoveFlags"/> nested type. /// </content> public partial class User32 { /// <summary> /// Flags to be passed to the <code>wRemoveMsg</code> parameter of /// <see cref="PeekMessage(IntPtr, IntPtr, WindowMessage, WindowMessage, PeekMessageRemoveFlags)" /> /// </summary> [Flags]
public enum PeekMessageRemoveFlags : uint
{ /// <summary> /// Messages are not removed from the queue after processing by /// <see cref="PeekMessage(IntPtr, IntPtr, WindowMessage, WindowMessage, PeekMessageRemoveFlags)" />. /// </summary> PM_NOREMOVE = 0x0000, /// <summary> /// Messages are removed from the queue after processing by /// <see cref="PeekMessage(IntPtr, IntPtr, WindowMessage, WindowMessage, PeekMessageRemoveFlags)" />. /// </summary> PM_REMOVE = 0x0001, /// <summary> /// Prevents the system from releasing any thread that is waiting for the caller to go idle (see /// WaitForInputIdle). Combine this value with either <see cref="PM_NOREMOVE" /> or <see cref="PM_REMOVE" />. /// </summary> PM_NOYIELD = 0x0002, /// <summary>Process mouse and keyboard messages.</summary> PM_QS_INPUT = QueueStatusFlags.QS_INPUT << 16, /// <summary>Process paint messages.</summary> PM_QS_PAINT = QueueStatusFlags.QS_PAINT << 16, /// <summary>Process all posted messages, including timers and hotkeys.</summary> PM_QS_POSTMESSAGE = (QueueStatusFlags.QS_POSTMESSAGE | QueueStatusFlags.QS_HOTKEY | QueueStatusFlags.QS_TIMER) << 16, /// <summary>Process all sent messages.</summary> PM_QS_SENDMESSAGE = QueueStatusFlags.QS_SENDMESSAGE << 16
} } }

Просмотреть файл

@ -22,6 +22,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="User32+DesktopCreationFlags.cs" />
<Compile Include="User32+DLGITEMTEMPLATE.cs" />
<Compile Include="User32+DLGTEMPLATE.cs" />
<Compile Include="User32+InputType.cs" />
<Compile Include="User32+KEYEVENTF.cs" />
<Compile Include="User32+MOUSEEVENTF.cs" />
@ -33,7 +35,9 @@
</Compile>
<Compile Include="User32+HARDWAREINPUT.cs" />
<Compile Include="User32+INPUT.cs" />
<Compile Include="User32+MSG.cs" />
<Compile Include="User32+ObjectIinformationFlag.cs" />
<Compile Include="User32+PeekMessageRemoveFlags.cs" />
<Compile Include="User32+QueueStatusFlags.cs" />
<Compile Include="User32+PeekMessageParams.cs" />
<Compile Include="User32+SafeDesktopHandle.cs" />

Просмотреть файл

@ -1,11 +1,15 @@
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#pragma warning disable SA1625 // Element documentation must not be copied and pasted
namespace PInvoke
{
using System;
using System.Runtime.InteropServices;
using static PInvoke.Kernel32;
/// <summary>
/// Exported functions from the User32.dll Windows library.
/// </summary>
@ -56,6 +60,13 @@ namespace PInvoke
/// <summary>Windows icon or the icon of the window specified in <see cref="MENUITEMINFO.dwItemData" />.</summary>
public static readonly IntPtr HBMMENU_SYSTEM = new IntPtr(1);
/// <summary>
/// A special windows handle used to indicate to <see cref="SendMessage(IntPtr, WindowMessage, IntPtr, IntPtr)" />
/// that the message is sent to all top-level windows in the system, including disabled or invisible unowned windows,
/// overlapped windows, and pop-up windows.
/// </summary>
public static readonly IntPtr HWND_BROADCAST = (IntPtr)0xffff;
/// <summary>
/// An application-defined or library-defined callback function used with the <see cref="SetWindowsHookEx(WindowsHookType, IntPtr, IntPtr, int)"/> function.
/// This is a generic function to Hook callbacks. For specific callback functions see this <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms632589(v=vs.85).aspx" >API documentation on MSDN</see>.
@ -110,6 +121,28 @@ namespace PInvoke
[return:MarshalAs(UnmanagedType.Bool)]
public delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam);
/// <summary>
/// Application-defined callback function used with the CreateDialog and DialogBox families of functions. It processes
/// messages sent to a modal or modeless dialog box.
/// </summary>
/// <param name="hwndDlg">A handle to the dialog box.</param>
/// <param name="uMsg">The message.</param>
/// <param name="wParam">Additional message-specific information.</param>
/// <param name="lParam">Additional message-specific information.</param>
/// <returns>
/// Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the
/// dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the
/// message.
/// <para>
/// If the dialog box procedure processes a message that requires a specific return value, the dialog box
/// procedure should set the desired return value by calling <see cref="SetWindowLong" /> with
/// <see cref="WindowLongIndexFlags.DWLP_MSGRESULT" /> immediately before returning TRUE. Note that you must call
/// SetWindowLong immediately before returning TRUE; doing so earlier may result in the
/// <see cref="WindowLongIndexFlags.DWLP_MSGRESULT" /> value being overwritten by a nested dialog box message.
/// </para>
/// </returns>
public delegate IntPtr DialogProc(IntPtr hwndDlg, WindowMessage uMsg, IntPtr wParam, IntPtr lParam);
/// <summary>
/// Plays a waveform sound. The waveform sound for each sound type is identified by an entry in the registry.
/// </summary>
@ -220,7 +253,6 @@ namespace PInvoke
[DllImport(nameof(User32))]
public static extern IntPtr GetForegroundWindow();
#pragma warning disable SA1625 // Element documentation must not be copied and pasted
/// <summary>
/// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
/// To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
@ -259,7 +291,6 @@ namespace PInvoke
[DllImport(nameof(User32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool PostMessage(IntPtr hWnd, WindowMessage wMsg, void* wParam, void* lParam);
#pragma warning restore SA1625 // Element documentation must not be copied and pasted
/// <summary>
/// Brings the thread that created the specified window into the foreground and activates the window. Keyboard
@ -894,7 +925,7 @@ namespace PInvoke
/// The calling process must have DESKTOP_SWITCHDESKTOP access to the desktop for the SwitchDesktop function to succeed.
/// </summary>
/// <param name="hDesktop">
/// A handle to the desktop. This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> and <see cref="OpenDesktop"/> functions.
/// A handle to the desktop. This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> and <see cref="OpenDesktop"/> functions.
/// This desktop must be associated with the current window station for the process.</param>
/// <returns>If the function succeeds, the return value is true, if it fails, the return value is false.</returns>
/// <remarks>
@ -920,7 +951,7 @@ namespace PInvoke
/// </summary>
/// <param name="hDesktop">
/// A handle to the desktop to be assigned to the calling thread.
/// This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetThreadDesktop"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> function.
/// This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetThreadDesktop"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> function.
/// This desktop must be associated with the current window station for the process.
/// </param>
/// <returns>If the function succeeds, the return value is true, if it fails, the return value is false.</returns>
@ -937,7 +968,7 @@ namespace PInvoke
/// <param name="lpszDesktop">The name of the desktop to be opened. Desktop names are case-insensitive. This desktop must belong to the current window station.</param>
/// <param name="dwFlags">Access control flags</param>
/// <param name="fInherit">If this value is true, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.</param>
/// <param name="dwDesiredAccess">The access to the desktop. For a list of access rights, see <see cref="Kernel32.ACCESS_MASK"/>.</param>
/// <param name="dwDesiredAccess">The access to the desktop. For a list of access rights, see <see cref="ACCESS_MASK"/>.</param>
/// <returns>If the function succeeds, the return value is a handle to the opened desktop, if the function fails, the return value is an invalid handle.</returns>
/// <remarks>
/// <para>
@ -955,14 +986,14 @@ namespace PInvoke
string lpszDesktop,
DesktopCreationFlags dwFlags,
[MarshalAs(UnmanagedType.Bool)] bool fInherit,
Kernel32.ACCESS_MASK dwDesiredAccess);
ACCESS_MASK dwDesiredAccess);
/// <summary>
/// Enumerates all top-level windows associated with the specified desktop. It passes the handle to each window, in turn, to an application-defined callback function.
/// </summary>
/// <param name="hDesktop">
/// A handle to the desktop whose top-level windows are to be enumerated. This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetThreadDesktop"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> function,
/// and must have the <see cref="Kernel32.ACCESS_MASK.DesktopSpecificRight.DESKTOP_READOBJECTS"/> access right.
/// A handle to the desktop whose top-level windows are to be enumerated. This handle is returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetThreadDesktop"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> function,
/// and must have the <see cref="ACCESS_MASK.DesktopSpecificRight.DESKTOP_READOBJECTS"/> access right.
/// If this parameter is NULL, the current desktop is used.
/// </param>
/// <param name="lpfn">An application-defined <see cref="WNDENUMPROC"/> callback function.</param>
@ -1000,7 +1031,7 @@ namespace PInvoke
/// <summary>
/// Enumerates all desktops associated with the specified window station of the calling process. The function passes the name of each desktop, in turn, to an application-defined callback function.
/// </summary>
/// <param name="hWinsta">A handle to the window station whose desktops are to be enumerated. This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetProcessWindowStation"/>, or <see cref="OpenWindowStation"/> function, and must have the WINSTA_ENUMDESKTOPS access right.</param>
/// <param name="hWinsta">A handle to the window station whose desktops are to be enumerated. This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="GetProcessWindowStation"/>, or <see cref="OpenWindowStation"/> function, and must have the WINSTA_ENUMDESKTOPS access right.</param>
/// <param name="lpEnumFunc">An application-defined <see cref="DESKTOPENUMPROC"/> callback function.</param>
/// <param name="lParam">An application-defined value to be passed to the callback function.</param>
/// <returns>
@ -1009,7 +1040,7 @@ namespace PInvoke
/// If the callback function fails, the return value is zero. The callback function can call SetLastError to set an error code for the caller to retrieve by calling GetLastError.
/// </returns>
/// <remarks>
/// The EnumDesktops function enumerates only those desktops for which the calling process has the <see cref="Kernel32.ACCESS_MASK.DesktopSpecificRight.DESKTOP_ENUMERATE"/> access right.
/// The EnumDesktops function enumerates only those desktops for which the calling process has the <see cref="ACCESS_MASK.DesktopSpecificRight.DESKTOP_ENUMERATE"/> access right.
/// The EnumDesktops function repeatedly invokes the lpEnumFunc callback function until the last desktop is enumerated or the callback function returns zero.
/// </remarks>
[DllImport(nameof(User32), SetLastError = true)]
@ -1021,7 +1052,7 @@ namespace PInvoke
/// </summary>
/// <param name="dwFlags">Access control flags</param>
/// <param name="fInherit">If this value is true, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.</param>
/// <param name="dwDesiredAccess">The requested access to the desktop. For a list of values, see <see cref="Kernel32.ACCESS_MASK"/>.</param>
/// <param name="dwDesiredAccess">The requested access to the desktop. For a list of values, see <see cref="ACCESS_MASK"/>.</param>
/// <returns>If the function succeeds, the return value is a handle to the opened desktop, if the function fails, the return value is an invalid handle.</returns>
/// <remarks>
/// <para>
@ -1042,7 +1073,7 @@ namespace PInvoke
public static extern SafeDesktopHandle OpenInputDesktop(
DesktopCreationFlags dwFlags,
[MarshalAs(UnmanagedType.Bool)] bool fInherit,
Kernel32.ACCESS_MASK dwDesiredAccess);
ACCESS_MASK dwDesiredAccess);
/// <summary>
/// Creates a new desktop with the specified heap, associates it with the current window station of the calling process, and assigns it to the calling thread.
@ -1053,8 +1084,8 @@ namespace PInvoke
/// <param name="pDevmode">This parameter is reserved and must be <see cref="IntPtr.Zero"/>.</param>
/// <param name="dwFlags">Access control flags</param>
/// <param name="dwDesiredAccess">
/// The requested access to the desktop. For a list of values, see <see cref="Kernel32.ACCESS_MASK"/>.
/// This parameter must include the <see cref="Kernel32.ACCESS_MASK.DesktopSpecificRight.DESKTOP_CREATEWINDOW"/> access right, because internally <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> uses the handle to create a window.
/// The requested access to the desktop. For a list of values, see <see cref="ACCESS_MASK"/>.
/// This parameter must include the <see cref="ACCESS_MASK.DesktopSpecificRight.DESKTOP_CREATEWINDOW"/> access right, because internally <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> uses the handle to create a window.
/// </param>
/// <param name="lpsa">
/// A pointer to a <see cref="Kernel32.SECURITY_ATTRIBUTES"/> structure that determines whether the returned handle can be inherited by child processes. If lpsa is NULL, the handle cannot be inherited.
@ -1084,7 +1115,7 @@ namespace PInvoke
IntPtr lpszDevice,
IntPtr pDevmode,
DesktopCreationFlags dwFlags,
Kernel32.ACCESS_MASK dwDesiredAccess,
ACCESS_MASK dwDesiredAccess,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] Kernel32.SECURITY_ATTRIBUTES* lpsa,
uint ulHeapSize,
IntPtr pvoid = default(IntPtr));
@ -1097,8 +1128,8 @@ namespace PInvoke
/// <param name="pDevmode">This parameter is reserved and must be <see cref="IntPtr.Zero"/>.</param>
/// <param name="dwFlags">Access control flags</param>
/// <param name="dwDesiredAccess">
/// The requested access to the desktop. For a list of values, see <see cref="Kernel32.ACCESS_MASK"/>.
/// This parameter must include the <see cref="Kernel32.ACCESS_MASK.DesktopSpecificRight.DESKTOP_CREATEWINDOW"/> access right, because internally <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> uses the handle to create a window.
/// The requested access to the desktop. For a list of values, see <see cref="ACCESS_MASK"/>.
/// This parameter must include the <see cref="ACCESS_MASK.DesktopSpecificRight.DESKTOP_CREATEWINDOW"/> access right, because internally <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> uses the handle to create a window.
/// </param>
/// <param name="lpsa">
/// A pointer to a <see cref="Kernel32.SECURITY_ATTRIBUTES"/> structure that determines whether the returned handle can be inherited by child processes. If lpsa is NULL, the handle cannot be inherited.
@ -1123,7 +1154,7 @@ namespace PInvoke
string lpszDevice,
IntPtr pDevmode,
DesktopCreationFlags dwFlags,
Kernel32.ACCESS_MASK dwDesiredAccess,
ACCESS_MASK dwDesiredAccess,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] Kernel32.SECURITY_ATTRIBUTES* lpsa);
/// <summary>
@ -1152,7 +1183,7 @@ namespace PInvoke
/// Closes an open handle to a desktop object.
/// </summary>
/// <param name="hDesktop">
/// A handle to the desktop to be closed. This can be a handle returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> functions.
/// A handle to the desktop to be closed. This can be a handle returned by the <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenDesktop"/>, or <see cref="OpenInputDesktop"/> functions.
/// Do not specify the handle returned by the <see cref="GetThreadDesktop"/> function.
/// </param>
/// <returns>If the function succeeds, the return value is true, if it fails, the return value is false.</returns>
@ -1164,7 +1195,7 @@ namespace PInvoke
/// <summary>
/// Retrieves information about the specified window station or desktop object.
/// </summary>
/// <param name="hObj">A handle to the window station or desktop object. This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenWindowStation"/>, <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, or <see cref="OpenDesktop"/> function.</param>
/// <param name="hObj">A handle to the window station or desktop object. This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenWindowStation"/>, <see cref="CreateDesktop(string, string, IntPtr, DesktopCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, or <see cref="OpenDesktop"/> function.</param>
/// <param name="nIndex">The information to be retrieved.</param>
/// <param name="pvInfo">A pointer to a buffer to receive the object information.</param>
/// <param name="nLength">The size of the buffer pointed to by the <paramref name="pvInfo"/> parameter, in bytes.</param>
@ -1182,7 +1213,7 @@ namespace PInvoke
/// This enables the process to access objects in the window station such as desktops, the clipboard, and global atoms. All subsequent operations on the window station use the access rights granted to <paramref name="hWinSta"/>.
/// </summary>
/// <param name="hWinSta">
/// A handle to the window station. This can be a handle returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenWindowStation"/>, or <see cref="GetProcessWindowStation"/> function.
/// A handle to the window station. This can be a handle returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/>, <see cref="OpenWindowStation"/>, or <see cref="GetProcessWindowStation"/> function.
/// This window station must be associated with the current session.
/// </param>
/// <returns>If the function succeeds, the return value is true, if it fails, the return value is false.</returns>
@ -1195,7 +1226,7 @@ namespace PInvoke
/// </summary>
/// <param name="hWinsta">
/// A handle to the window station to be closed.
/// This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, Kernel32.ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> or <see cref="OpenWindowStation"/> function.
/// This handle is returned by the <see cref="CreateWindowStation(string, WindowStationCreationFlags, ACCESS_MASK, Kernel32.SECURITY_ATTRIBUTES*)"/> or <see cref="OpenWindowStation"/> function.
/// Do not specify the handle returned by the <see cref="GetProcessWindowStation"/> function.
/// </param>
/// <returns>If the function succeeds, the return value is true, if it fails, the return value is false.</returns>
@ -1225,13 +1256,13 @@ namespace PInvoke
/// Windows XP/2000: This parameter is reserved and must be zero.
/// </param>
/// <param name="dwDesiredAccess">
/// The requested access to the window station. For a list of values, see <see cref="Kernel32.ACCESS_MASK"/>.
/// In addition, you can specify any of the standard access rights, such as <see cref="Kernel32.ACCESS_MASK.StandardRight.READ_CONTROL"/> or <see cref="Kernel32.ACCESS_MASK.StandardRight.WRITE_DAC"/>, and a combination of the window station-specific access rights.
/// The requested access to the window station. For a list of values, see <see cref="ACCESS_MASK"/>.
/// In addition, you can specify any of the standard access rights, such as <see cref="ACCESS_MASK.StandardRight.READ_CONTROL"/> or <see cref="ACCESS_MASK.StandardRight.WRITE_DAC"/>, and a combination of the window station-specific access rights.
/// </param>
/// <param name="lpsa">
/// A pointer to a <see cref="Kernel32.SECURITY_ATTRIBUTES"/> structure that determines whether the returned handle can be inherited by child processes. If lpsa is NULL, the handle cannot be inherited.
/// The <see cref="Kernel32.SECURITY_ATTRIBUTES.lpSecurityDescriptor"/> member of the structure specifies a security descriptor for the new window station.
/// If lpsa is NULL, the window station (and any desktops created within the window) gets a security descriptor that grants <see cref="Kernel32.ACCESS_MASK.GenericRight.GENERIC_ALL"/> access to all users.
/// If lpsa is NULL, the window station (and any desktops created within the window) gets a security descriptor that grants <see cref="ACCESS_MASK.GenericRight.GENERIC_ALL"/> access to all users.
/// </param>
/// <returns>
/// If the function succeeds, the return value is a handle to the newly created window station.
@ -1243,7 +1274,7 @@ namespace PInvoke
public static unsafe extern SafeWindowStationHandle CreateWindowStation(
string lpwinsta,
WindowStationCreationFlags dwFlags,
Kernel32.ACCESS_MASK dwDesiredAccess,
ACCESS_MASK dwDesiredAccess,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] Kernel32.SECURITY_ATTRIBUTES* lpsa);
/// <summary>
@ -1278,7 +1309,7 @@ namespace PInvoke
/// If the callback function fails, the return value is zero. The callback function can call SetLastError to set an error code for the caller to retrieve by calling GetLastError.
/// </returns>
/// <remarks>
/// The EnumWindowStations function enumerates only those window stations for which the calling process has the <see cref="Kernel32.ACCESS_MASK.WindowStationSpecificRight.WINSTA_ENUMERATE"/> access right.
/// The EnumWindowStations function enumerates only those window stations for which the calling process has the <see cref="ACCESS_MASK.WindowStationSpecificRight.WINSTA_ENUMERATE"/> access right.
/// EnumWindowStations repeatedly invokes the <paramref name="lpEnumFunc"/> callback function until the last window station is enumerated or the callback function returns FALSE.
/// </remarks>
[DllImport(nameof(User32), SetLastError = true)]
@ -1297,7 +1328,315 @@ namespace PInvoke
public static extern SafeWindowStationHandle OpenWindowStation(
string lpszWinSta,
[MarshalAs(UnmanagedType.Bool)] bool fInherit,
Kernel32.ACCESS_MASK dwDesiredAccess);
ACCESS_MASK dwDesiredAccess);
/// <summary>
/// Creates a modeless dialog box from a dialog box template in memory. Before displaying the dialog box, the function
/// passes an application-defined value to the dialog box procedure as the lParam parameter of the
/// <see cref="WindowMessage.WM_INITDIALOG" /> message. An application can use this value to initialize dialog box
/// controls.
/// </summary>
/// <param name="hInstance">
/// A handle to the module which contains the dialog box template. If this parameter is
/// <see cref="Kernel32.SafeLibraryHandle.Null" />, then the current executable is used.
/// </param>
/// <param name="lpTemplate">
/// The template CreateDialogIndirectParam uses to create the dialog box. A dialog box template consists of a header
/// that describes the dialog box, followed by one or more additional blocks of data that describe each of the controls
/// in the dialog box. The template can use either the standard format or the extended format.
/// <para>
/// In a standard template, the header is a <see cref="DLGTEMPLATE" /> structure followed by additional
/// variable-length arrays. The data for each control consists of a <see cref="DLGITEMTEMPLATE" /> structure
/// followed by additional variable-length arrays.
/// </para>
/// <para>
/// In an extended dialog box template, the header uses the DLGTEMPLATEEX format and the control definitions use
/// the DLGITEMTEMPLATEEX format.
/// </para>
/// <para>
/// After CreateDialogIndirectParam returns, you can free the template, which is only used to get the dialog box
/// started.
/// </para>
/// </param>
/// <param name="hWndParent">A handle to the window that owns the dialog box.</param>
/// <param name="lpDialogFunc">A pointer to the dialog box procedure.</param>
/// <param name="lParamInit">
/// The value to pass to the dialog box in the lParam parameter of the
/// <see cref="WindowMessage.WM_INITDIALOG" /> message.
/// </param>
/// <returns>
/// If the function succeeds, the return value is the window handle to the dialog box.
/// <para>
/// If the function fails, the return value is <see cref="IntPtr.Zero" />. To get extended error information,
/// call <see cref="GetLastError" />.
/// </para>
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
public static extern unsafe IntPtr CreateDialogIndirectParam(
Kernel32.SafeLibraryHandle hInstance,
DLGTEMPLATE* lpTemplate,
IntPtr hWndParent,
DialogProc lpDialogFunc,
IntPtr lParamInit);
/// <summary>
/// Retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a
/// posted message is available for retrieval.
/// <para>
/// Unlike <see cref="GetMessage(MSG*, IntPtr, WindowMessage,WindowMessage)" />, the <see cref="PeekMessage(MSG*, IntPtr, WindowMessage,WindowMessage,PeekMessageRemoveFlags)" /> function does not wait for a message to be
/// posted before returning.
/// </para>
/// </summary>
/// <param name="lpMsg">A pointer to an <see cref="MSG" /> structure that receives message information.</param>
/// <param name="hWnd">
/// A handle to the window whose messages are to be retrieved. The window must belong to the current thread.
/// <para>
/// If hWnd is <see cref="IntPtr.Zero" />, PeekMessage retrieves messages for any window that belongs to the
/// current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG
/// structure). Therefore if hWnd is <see cref="IntPtr.Zero" />, both window messages and thread messages are
/// processed.
/// </para>
/// <para>
/// If hWnd is -1, PeekMessage retrieves only messages on the current thread's message queue whose hwnd value is
/// NULL, that is, thread messages as posted by <see cref="PostMessage(IntPtr, WindowMessage, void*, void*)" />
/// (when the hWnd parameter is <see cref="IntPtr.Zero" />) or <see cref="PostThreadMessage" />.
/// </para>
/// </param>
/// <param name="wMsgFilterMin">
/// <para>
/// The value of the first message in the range of messages to be examined. Use
/// <see cref="WindowMessage.WM_KEYFIRST" /> to specify the first keyboard message or
/// <see cref="WindowMessage.WM_MOUSEFIRST" /> to specify the first mouse message.
/// </para>
/// <para>
/// If wMsgFilterMin and wMsgFilterMax are both <see cref="WindowMessage.WM_NULL" />, PeekMessage returns all
/// available messages (that is, no range filtering is performed).
/// </para>
/// </param>
/// <param name="wMsgFilterMax">
/// <para>
/// The value of the last message in the range of messages to be examined. Use
/// <see cref="WindowMessage.WM_KEYLAST" /> to specify the last keyboard message or
/// <see cref="WindowMessage.WM_MOUSELAST" /> to specify the last mouse message.
/// </para>
/// <para>
/// If wMsgFilterMin and wMsgFilterMax are both <see cref="WindowMessage.WM_NULL" />, PeekMessage returns all
/// available messages (that is, no range filtering is performed).
/// </para>
/// </param>
/// <returns>
/// If the function retrieves a message other than <see cref="WindowMessage.WM_QUIT" />, the return value is nonzero.
/// <para>If the function retrieves the <see cref="WindowMessage.WM_QUIT" /> message, the return value is zero.</para>
/// <para>
/// If there is an error, the return value is -1. For example, the function fails if <paramref name="hWnd" /> is
/// an invalid window handle or <paramref name="lpMsg" /> is an invalid pointer. To get extended error information,
/// call <see cref="GetLastError" />.
/// </para>
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
public static extern unsafe int GetMessage(
MSG* lpMsg,
IntPtr hWnd,
WindowMessage wMsgFilterMin,
WindowMessage wMsgFilterMax);
/// <summary>
/// Dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message
/// (if any exist).
/// </summary>
/// <param name="lpMsg">A pointer to an <see cref="MSG" /> structure that receives message information.</param>
/// <param name="hWnd">
/// A handle to the window whose messages are to be retrieved. The window must belong to the current thread.
/// <para>
/// If hWnd is <see cref="IntPtr.Zero" />, PeekMessage retrieves messages for any window that belongs to the
/// current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG
/// structure). Therefore if hWnd is <see cref="IntPtr.Zero" />, both window messages and thread messages are
/// processed.
/// </para>
/// <para>
/// If hWnd is -1, PeekMessage retrieves only messages on the current thread's message queue whose hwnd value is
/// NULL, that is, thread messages as posted by <see cref="PostMessage(IntPtr, WindowMessage, void*, void*)" /> (when the hWnd parameter is
/// <see cref="IntPtr.Zero" />) or
/// <see cref="PostThreadMessage" />.
/// </para>
/// </param>
/// <param name="wMsgFilterMin">
/// <para>
/// The value of the first message in the range of messages to be examined. Use
/// <see cref="WindowMessage.WM_KEYFIRST" /> to specify the first keyboard message or
/// <see cref="WindowMessage.WM_MOUSEFIRST" /> to specify the first mouse message.
/// </para>
/// <para>
/// If wMsgFilterMin and wMsgFilterMax are both <see cref="WindowMessage.WM_NULL" />, PeekMessage returns all
/// available messages (that is, no range filtering is performed).
/// </para>
/// </param>
/// <param name="wMsgFilterMax">
/// <para>
/// The value of the last message in the range of messages to be examined. Use
/// <see cref="WindowMessage.WM_KEYLAST" /> to specify the last keyboard message or
/// <see cref="WindowMessage.WM_MOUSELAST" /> to specify the last mouse message.
/// </para>
/// <para>
/// If wMsgFilterMin and wMsgFilterMax are both <see cref="WindowMessage.WM_NULL" />, PeekMessage returns all
/// available messages (that is, no range filtering is performed).
/// </para>
/// </param>
/// <param name="wRemoveMsg">Specifies how messages are to be handled</param>
/// <returns>
/// If a message is available, the return value is true.
/// <para>If no messages are available, the return value is false.</para>
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool PeekMessage(
MSG* lpMsg,
IntPtr hWnd,
WindowMessage wMsgFilterMin,
WindowMessage wMsgFilterMax,
PeekMessageRemoveFlags wRemoveMsg);
/// <summary>
/// Posts a message to the message queue of the specified thread. It returns without waiting for the thread to process
/// the message.
/// </summary>
/// <param name="idThread">
/// The identifier of the thread to which the message is to be posted.
/// <para>
/// The function fails if the specified thread does not have a message queue. The system creates a thread's
/// message queue when the thread makes its first call to one of the User or GDI functions.
/// </para>
/// <para>
/// Message posting is subject to UIPI. The thread of a process can post messages only to posted-message queues
/// of threads in processes of lesser or equal integrity level.
/// </para>
/// <para>
/// This thread must have the SE_TCB_NAME privilege to post a message to a thread that belongs to a process with
/// the same locally unique identifier (LUID) but is in a different desktop. Otherwise, the function fails and
/// returns <see cref="Win32ErrorCode.ERROR_INVALID_THREAD_ID" />.
/// </para>
/// <para>
/// This thread must either belong to the same desktop as the calling thread or to a process with the same LUID.
/// Otherwise, the function fails and returns <see cref="Win32ErrorCode.ERROR_INVALID_THREAD_ID" />.
/// </para>
/// </param>
/// <param name="Msg">The type of message to be posted.</param>
/// <param name="wParam">Additional message-specific information.</param>
/// <param name="lParam">Additional message-specific information.</param>
/// <returns>
/// If the function succeeds, the return value is nonzero.
/// <para>
/// If the function fails, the return value is zero. To get extended error information, call
/// <see cref="GetLastError" />. GetLastError returns
/// <see cref="Win32ErrorCode.ERROR_INVALID_THREAD_ID" /> if idThread is not a valid thread identifier, or if the
/// thread specified by idThread does not have a message queue. GetLastError returns
/// <see cref="Win32ErrorCode.ERROR_NOT_ENOUGH_QUOTA" /> when the message limit is hit.
/// </para>
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PostThreadMessage(
int idThread,
WindowMessage Msg,
IntPtr wParam,
IntPtr lParam);
/// <summary>
/// Calls the default window procedure to provide default processing for any window messages that an application does
/// not process. This function ensures that every message is processed. DefWindowProc is called with the same
/// parameters received by the window procedure.
/// </summary>
/// <param name="hWnd">A handle to the window procedure that received the message.</param>
/// <param name="Msg">The message.</param>
/// <param name="wParam">
/// Additional message information. The content of this parameter depends on the value of the
/// <paramref name="Msg" /> parameter.
/// </param>
/// <param name="lParam">
/// Additional message information. The content of this parameter depends on the value of the
/// <paramref name="Msg" /> parameter.
/// </param>
/// <returns>The return value is the result of the message processing and depends on the message.</returns>
[DllImport(nameof(User32))]
public static extern IntPtr DefWindowProc(
IntPtr hWnd,
WindowMessage Msg,
IntPtr wParam,
IntPtr lParam);
/// <summary>
/// Retrieves the type of messages found in the calling thread's message queue.
/// </summary>
/// <param name="flags">The types of messages for which to check</param>
/// <returns>
/// The high-order word of the return value indicates the types of messages currently in the queue. The low-order word
/// indicates the types of messages that have been added to the queue and that are still in the queue since the last
/// call to the <see cref="GetQueueStatus" />, <see cref="GetMessage(MSG*, IntPtr, WindowMessage,WindowMessage)" />, or <see cref="PeekMessage(MSG*, IntPtr, WindowMessage,WindowMessage,PeekMessageRemoveFlags)" /> function.
/// </returns>
[DllImport(nameof(User32))]
public static extern int GetQueueStatus(QueueStatusFlags flags);
/// <summary>
/// Translates virtual-key messages into character messages. The character messages are posted to the calling thread's
/// message queue, to be read the next time the thread calls the <see cref="GetMessage(MSG*, IntPtr, WindowMessage,WindowMessage)" /> or
/// <see cref="PeekMessage(MSG*, IntPtr, WindowMessage,WindowMessage,PeekMessageRemoveFlags)" /> function.
/// </summary>
/// <param name="lpMsg">
/// A pointer to an <see cref="MSG" /> structure that contains message information retrieved from the
/// calling thread's message queue by using the <see cref="GetMessage(MSG*, IntPtr, WindowMessage,WindowMessage)" /> or <see cref="PeekMessage(MSG*, IntPtr, WindowMessage,WindowMessage,PeekMessageRemoveFlags)" /> function.
/// </param>
/// <returns>
/// If the message is translated (that is, a character message is posted to the thread's message queue), the return
/// value is nonzero.
/// <para>
/// If the message is <see cref="WindowMessage.WM_KEYDOWN" />, <see cref="WindowMessage.WM_KEYUP" />,
/// <see cref="WindowMessage.WM_SYSKEYDOWN" />, or
/// <see cref="WindowMessage.WM_SYSKEYUP" />, the return value is nonzero, regardless of the translation.
/// </para>
/// <para>
/// If the message is not translated (that is, a character message is not posted to the thread's message queue),
/// the return value is zero.
/// </para>
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool TranslateMessage(MSG* lpMsg);
/// <summary>
/// Dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the
/// <see cref="GetMessage(MSG*, IntPtr, WindowMessage,WindowMessage)" /> function.
/// </summary>
/// <param name="lpMsg">A pointer to a structure that contains the message.</param>
/// <returns>
/// The return value specifies the value returned by the window procedure. Although its meaning depends on the
/// message being dispatched, the return value generally is ignored.
/// </returns>
[DllImport(nameof(User32), SetLastError = true)]
public static extern unsafe IntPtr DispatchMessage(MSG* lpMsg);
/// <summary>
/// Indicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a
/// <see cref="WindowMessage.WM_DESTROY" /> message.
/// </summary>
/// <param name="nExitCode">
/// The application exit code. This value is used as the wParam parameter of the
/// <see cref="WindowMessage.WM_QUIT" /> message.
/// </param>
[DllImport(nameof(User32), SetLastError = true)]
public static extern void PostQuitMessage(int nExitCode);
/// <summary>
/// Determines whether a message is intended for the specified dialog box and, if it is, processes the message.
/// </summary>
/// <param name="hDlg">A handle to the dialog box.</param>
/// <param name="lpMsg">A pointer to an <see cref="MSG" /> structure that contains the message to be checked.</param>
/// <returns>
/// If the message has been processed, the return value is nonzero.
/// <para>If the message has not been processed, the return value is zero.</para>
/// </returns>
[DllImport(nameof(User32))]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool IsDialogMessage(IntPtr hDlg, MSG* lpMsg);
/// <summary>
/// The <see cref="GetDC"/> function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.