using System; using System.Runtime.InteropServices; using System.Text; using Vanara.InteropServices; namespace Vanara.PInvoke { public static partial class User32 { /// Return this value when processing a broadcast message to deny a query. public static readonly IntPtr BROADCAST_QUERY_DENY = (IntPtr)0x424D5144; /// /// Used to define private messages for use by private window classes, usually of the form OCM__BASE+x, where x is an integer value. /// public const uint OCM__BASE = (WM_USER + 0x1c00); /// Used to define private messages, usually of the form WM_APP+x, where x is an integer value. public const uint WM_APP = 0x8000; /// /// Used to define private messages for use by private window classes, usually of the form WM_USER+x, where x is an integer value. /// public const uint WM_USER = 0x0400; /// /// An application-defined callback function used with the SendMessageCallback function. The system passes the message to the /// callback function after passing the message to the destination window procedure. The SENDASYNCPROC type defines a pointer /// to this callback function. SendAsyncProc is a placeholder for the application-defined function name. /// /// /// A handle to the window whose window procedure received the message. /// /// If the SendMessageCallback function was called with its hwnd parameter set to HWND_BROADCAST, the system calls the SendAsyncProc /// function once for each top-level window. /// /// /// The message. /// An application-defined value sent from the SendMessageCallback function. /// The result of the message processing.This value depends on the message. /// /// /// You install a SendAsyncProc application-defined callback function by passing a SENDASYNCPROC pointer to the /// SendMessageCallback function. /// /// /// The callback function is only called when the thread that called SendMessageCallback calls GetMessage, PeekMessage, or WaitMessage. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nc-winuser-sendasyncproc SENDASYNCPROC Sendasyncproc; void // Sendasyncproc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ ULONG_PTR dwData, _In_ LRESULT lResult); [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("winuser.h")] public delegate void Sendasyncproc(HWND hwnd, uint uMsg, UIntPtr dwData, IntPtr lResult); /// Flags used by BroadcastSystemMessage and BroadcastSystemMessageEx. [PInvokeData("winuser.h")] [Flags] public enum BSF { /// Enables the recipient to set the foreground window while processing the message. BSF_ALLOWSFW = 0x00000080, /// Flushes the disk after each recipient processes the message. BSF_FLUSHDISK = 0x00000004, /// Continues to broadcast the message, even if the time-out period elapses or one of the recipients is not responding. BSF_FORCEIFHUNG = 0x00000020, /// /// Does not send the message to windows that belong to the current task. This prevents an application from receiving its own message. /// BSF_IGNORECURRENTTASK = 0x00000002, /// /// Forces a non-responsive application to time out. If one of the recipients times out, do not continue broadcasting the message. /// BSF_NOHANG = 0x00000008, /// Waits for a response to the message, as long as the recipient is not being unresponsive. Does not time out. BSF_NOTIMEOUTIFNOTHUNG = 0x00000040, /// Posts the message. Do not use in combination with BSF_QUERY. BSF_POSTMESSAGE = 0x00000010, /// /// Sends the message to one recipient at a time, sending to a subsequent recipient only if the current recipient returns TRUE. /// BSF_QUERY = 0x00000001, /// Sends the message using SendNotifyMessage function. Do not use in combination with BSF_QUERY. BSF_SENDNOTIFYMESSAGE = 0x00000100, /// BSF_RETURNHDESK = 0x00000200, /// BSF_LUID = 0x00000400, } /// System message info flags used by BroadcastSystemMessage and BroadcastSystemMessageEx. [PInvokeData("winuser.h")] [Flags] public enum BSM { /// Broadcast to all system components. BSM_ALLCOMPONENTS = 0x00000000, /// Broadcast to all desktops. Requires the SE_TCB_NAME privilege. BSM_ALLDESKTOPS = 0x00000010, /// Broadcast to applications. BSM_APPLICATIONS = 0x00000008, /// BSM_VXDS = 0x00000001, /// BSM_NETDRIVER = 0x00000002, /// BSM_INSTALLABLEDRIVERS = 0x00000004, } /// Return values from InSendMessageEx [PInvokeData("winuser.h")] [Flags] public enum ISMEX { /// The message was not sent. ISMEX_NOSEND = 0x00000000, /// The message was sent using the SendMessageCallback function. The thread that sent the message is not blocked. ISMEX_CALLBACK = 0x00000004, /// The message was sent using the SendNotifyMessage function. The thread that sent the message is not blocked. ISMEX_NOTIFY = 0x00000002, /// The window procedure has processed the message. The thread that sent the message is no longer blocked. ISMEX_REPLIED = 0x00000008, /// /// The message was sent using the SendMessage or SendMessageTimeout function. If ISMEX_REPLIED is not set, the thread that sent /// the message is blocked. /// ISMEX_SEND = 0x00000001, } /// Flags for [PInvokeData("winuser.h", MSDNShortId = "1774b721-3ad4-492e-96af-b71de9066f0c")] [Flags] public enum MWMO { /// /// The function returns when any one of the objects is signaled. The return value indicates the object whose state caused the /// function to return. /// MWMO_ANY = 0, /// /// The function also returns if an APC has been queued to the thread with QueueUserAPC while the thread is in the waiting state. /// MWMO_ALERTABLE = 0x0002, /// /// The function returns if input exists for the queue, even if the input has been seen (but not removed) using a call to another /// function, such as PeekMessage. /// MWMO_INPUTAVAILABLE = 0x0004, /// /// The function returns when all objects in the pHandles array are signaled and an input event has been received, all at the /// same time. /// MWMO_WAITALL = 0x0001, } /// Flags used by PeekMessage. [PInvokeData("winuser.h")] [Flags] public enum PM { /// Messages are not removed from the queue after processing by PeekMessage. M_NOREMOVE = 0x0000, /// Messages are removed from the queue after processing by PeekMessage. PM_REMOVE = 0x0001, /// /// Prevents the system from releasing any thread that is waiting for the caller to go idle (see WaitForInputIdle). /// Combine this value with either PM_NOREMOVE or PM_REMOVE. /// PM_NOYIELD = 0x0002, /// Process mouse and keyboard messages. PM_QS_INPUT = (QS.QS_INPUT << 16), /// Process all posted messages, including timers and hotkeys. PM_QS_POSTMESSAGE = ((QS.QS_POSTMESSAGE | QS.QS_HOTKEY | QS.QS_TIMER) << 16), /// Process paint messages. PM_QS_PAINT = (QS.QS_PAINT << 16), /// Process all sent messages. PM_QS_SENDMESSAGE = (QS.QS_SENDMESSAGE << 16), } /// Flags used GetQueueStatus. [PInvokeData("winuser.h")] [Flags] public enum QS { /// An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue. QS_ALLEVENTS = (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY), /// Any message is in the queue. QS_ALLINPUT = (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE), /// A posted message (other than those listed here) is in the queue. QS_ALLPOSTMESSAGE = 0x0100, /// A WM_HOTKEY message is in the queue. QS_HOTKEY = 0x0080, /// An input message is in the queue. QS_INPUT = (QS_MOUSE | QS_KEY | QS_RAWINPUT | QS_TOUCH | QS_POINTER), /// A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue. QS_KEY = 0x0001, /// A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). QS_MOUSE = (QS_MOUSEMOVE | QS_MOUSEBUTTON), /// A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). QS_MOUSEBUTTON = 0x0004, /// A WM_MOUSEMOVE message is in the queue. QS_MOUSEMOVE = 0x0002, /// A WM_PAINT message is in the queue. QS_PAINT = 0x0020, /// A posted message (other than those listed here) is in the queue. QS_POSTMESSAGE = 0x0008, /// /// A raw input message is in the queue. For more information, see Raw Input. /// Windows 2000: This flag is not supported. /// QS_RAWINPUT = 0x0400, /// A message sent by another thread or application is in the queue. QS_SENDMESSAGE = 0x0040, /// A WM_TIMER message is in the queue. QS_TIMER = 0x0010, /// QS_TOUCH = 0x0800, /// QS_POINTER = 0x1000, } /// Flags used by the SendMessageTimeout function. [PInvokeData("winuser.h")] [Flags] public enum SMTO { /// /// The function returns without waiting for the time-out period to elapse if the receiving thread appears to not respond or "hangs." /// SMTO_ABORTIFHUNG = 0x0002, /// Prevents the calling thread from processing any other requests until the function returns. SMTO_BLOCK = 0x0001, /// The calling thread is not prevented from processing other requests while waiting for the function to return. SMTO_NORMAL = 0x0000, /// The function does not enforce the time-out period as long as the receiving thread is processing messages. SMTO_NOTIMEOUTIFNOTHUNG = 0x0008, /// /// The function should return 0 if the receiving window is destroyed or its owning thread dies while the message is being processed. /// SMTO_ERRORONEXIT = 0x0020, } /// /// /// Sends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, /// system-level device drivers, or any combination of these system components. /// /// To receive additional information if the request is defined, use the BroadcastSystemMessageEx function. /// /// /// Type: DWORD /// The broadcast option. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// BSF_ALLOWSFW 0x00000080 /// Enables the recipient to set the foreground window while processing the message. /// /// /// BSF_FLUSHDISK 0x00000004 /// Flushes the disk after each recipient processes the message. /// /// /// BSF_FORCEIFHUNG 0x00000020 /// Continues to broadcast the message, even if the time-out period elapses or one of the recipients is not responding. /// /// /// BSF_IGNORECURRENTTASK 0x00000002 /// /// Does not send the message to windows that belong to the current task. This prevents an application from receiving its own message. /// /// /// /// BSF_NOHANG 0x00000008 /// /// Forces a non-responsive application to time out. If one of the recipients times out, do not continue broadcasting the message. /// /// /// /// BSF_NOTIMEOUTIFNOTHUNG 0x00000040 /// Waits for a response to the message, as long as the recipient is not being unresponsive. Does not time out. /// /// /// BSF_POSTMESSAGE 0x00000010 /// Posts the message. Do not use in combination with BSF_QUERY. /// /// /// BSF_QUERY 0x00000001 /// /// Sends the message to one recipient at a time, sending to a subsequent recipient only if the current recipient returns TRUE. /// /// /// /// BSF_SENDNOTIFYMESSAGE 0x00000100 /// Sends the message using SendNotifyMessage function. Do not use in combination with BSF_QUERY. /// /// /// /// /// Type: LPDWORD /// A pointer to a variable that contains and receives information about the recipients of the message. /// /// When the function returns, this variable receives a combination of these values identifying which recipients actually received /// the message. /// /// If this parameter is NULL, the function broadcasts to all components. /// This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// BSM_ALLCOMPONENTS 0x00000000 /// Broadcast to all system components. /// /// /// BSM_ALLDESKTOPS 0x00000010 /// Broadcast to all desktops. Requires the SE_TCB_NAME privilege. /// /// /// BSM_APPLICATIONS 0x00000008 /// Broadcast to applications. /// /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: Type: long /// If the function succeeds, the return value is a positive value. /// If the function is unable to broadcast the message, the return value is –1. /// /// If the dwFlags parameter is BSF_QUERY and at least one recipient returned BROADCAST_QUERY_DENY to the corresponding /// message, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// /// If BSF_QUERY is not specified, the function sends the specified message to all requested recipients, ignoring values /// returned by those recipients. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// Examples /// For an example, see Terminating a Process. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-broadcastsystemmessage long BroadcastSystemMessage( DWORD // flags, LPDWORD lpInfo, UINT Msg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern long BroadcastSystemMessage(BSF flags, ref BSM lpInfo, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam); /// /// /// Sends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, /// system-level device drivers, or any combination of these system components. /// /// This function is similar to BroadcastSystemMessage except that this function can return more information from the recipients. /// /// /// Type: DWORD /// The broadcast option. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// BSF_ALLOWSFW 0x00000080 /// Enables the recipient to set the foreground window while processing the message. /// /// /// BSF_FLUSHDISK 0x00000004 /// Flushes the disk after each recipient processes the message. /// /// /// BSF_FORCEIFHUNG 0x00000020 /// Continues to broadcast the message, even if the time-out period elapses or one of the recipients is not responding. /// /// /// BSF_IGNORECURRENTTASK 0x00000002 /// /// Does not send the message to windows that belong to the current task. This prevents an application from receiving its own message. /// /// /// /// BSF_LUID 0x00000400 /// /// If BSF_LUID is set, the message is sent to the window that has the same LUID as specified in the luid member of the BSMINFO /// structure. Windows 2000: This flag is not supported. /// /// /// /// BSF_NOHANG 0x00000008 /// /// Forces a non-responsive application to time out. If one of the recipients times out, do not continue broadcasting the message. /// /// /// /// BSF_NOTIMEOUTIFNOTHUNG 0x00000040 /// Waits for a response to the message, as long as the recipient is not being unresponsive. Does not time out. /// /// /// BSF_POSTMESSAGE 0x00000010 /// Posts the message. Do not use in combination with BSF_QUERY. /// /// /// BSF_RETURNHDESK 0x00000200 /// /// If access is denied and both this and BSF_QUERY are set, BSMINFO returns both the desktop handle and the window handle. If access /// is denied and only BSF_QUERY is set, only the window handle is returned by BSMINFO. Windows 2000: This flag is not supported. /// /// /// /// BSF_QUERY 0x00000001 /// /// Sends the message to one recipient at a time, sending to a subsequent recipient only if the current recipient returns TRUE. /// /// /// /// BSF_SENDNOTIFYMESSAGE 0x00000100 /// Sends the message using SendNotifyMessage function. Do not use in combination with BSF_QUERY. /// /// /// /// /// Type: LPDWORD /// A pointer to a variable that contains and receives information about the recipients of the message. /// /// When the function returns, this variable receives a combination of these values identifying which recipients actually received /// the message. /// /// If this parameter is NULL, the function broadcasts to all components. /// This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// BSM_ALLCOMPONENTS 0x00000000 /// Broadcast to all system components. /// /// /// BSM_ALLDESKTOPS 0x00000010 /// Broadcast to all desktops. Requires the SE_TCB_NAME privilege. /// /// /// BSM_APPLICATIONS 0x00000008 /// Broadcast to applications. /// /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: PBSMINFO /// A pointer to a BSMINFO structure that contains additional information if the request is denied and dwFlags is set to BSF_QUERY. /// /// /// Type: Type: long /// If the function succeeds, the return value is a positive value. /// If the function is unable to broadcast the message, the return value is –1. /// /// If the dwFlags parameter is BSF_QUERY and at least one recipient returned BROADCAST_QUERY_DENY to the corresponding /// message, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// /// If BSF_QUERY is not specified, the function sends the specified message to all requested recipients, ignoring values /// returned by those recipients. /// /// /// If the caller's thread is on a desktop other than that of the window that denied the request, the caller must call /// SetThreadDesktop (hdesk) to query anything on that window. Also, the caller must call CloseDesktop on the returned /// hdesk handle. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-broadcastsystemmessageexa long BroadcastSystemMessageExA( // DWORD flags, LPDWORD lpInfo, UINT Msg, WPARAM wParam, LPARAM lParam, PBSMINFO pbsmInfo ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] public static extern long BroadcastSystemMessageEx(BSF flags, ref BSM lpInfo, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam, ref BSMINFO pbsmInfo); /// /// Dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function. /// /// /// Type: const MSG* /// A pointer to a structure that contains the message. /// /// /// Type: Type: LRESULT /// /// 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. /// /// /// /// /// The MSG structure must contain valid message values. If the parameter points to a WM_TIMER message and /// the lParam parameter of the WM_TIMER message is not NULL, lParam points to a function that is called instead of the /// window procedure. /// /// /// Note that the application is responsible for retrieving and dispatching input messages to the dialog box. Most applications use /// the main message loop for this. However, to permit the user to move to and to select controls by using the keyboard, the /// application must call IsDialogMessage. For more information, see Dialog Box Keyboard Interface. /// /// Examples /// For an example, see Creating a Message Loop. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-dispatchmessage LRESULT DispatchMessage( const MSG *lpMsg ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] public static extern IntPtr DispatchMessage(in MSG lpMsg); /// /// Frees the memory specified by the lParam parameter of a posted Dynamic Data Exchange (DDE) message. An application receiving a /// posted DDE message should call this function after it has used the UnpackDDElParam function to unpack the lParam value. /// /// /// Type: UINT /// The posted DDE message. /// /// /// Type: LPARAM /// The lParam parameter of the posted DDE message. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// An application should call this function only for posted DDE messages. /// This function frees the memory specified by the lParam parameter. It does not free the contents of lParam. /// // https://docs.microsoft.com/en-us/windows/desktop/api/dde/nf-dde-freeddelparam BOOL FreeDDElParam( UINT msg, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dde.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FreeDDElParam(uint msg, IntPtr lParam); /// Determines whether there are mouse-button or keyboard messages in the calling thread's message queue. /// /// Type: Type: BOOL /// If the queue contains one or more new mouse-button or keyboard messages, the return value is nonzero. /// If there are no new mouse-button or keyboard messages in the queue, the return value is zero. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getinputstate BOOL GetInputState( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetInputState(); /// /// /// Retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted /// message is available for retrieval. /// /// Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning. /// /// /// Type: LPMSG /// A pointer to an MSG structure that receives message information from the thread's message queue. /// /// /// Type: HWND /// A handle to the window whose messages are to be retrieved. The window must belong to the current thread. /// /// If hWnd is NULL, GetMessage 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 /// NULL, both window messages and thread messages are processed. /// /// /// If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd value is /// NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or PostThreadMessage. /// /// /// /// Type: UINT /// /// The integer value of the lowest message value to be retrieved. Use WM_KEYFIRST (0x0100) to specify the first keyboard /// message or WM_MOUSEFIRST (0x0200) to specify the first mouse message. /// /// Use WM_INPUT here and in wMsgFilterMax to specify only the WM_INPUT messages. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering /// is performed). /// /// /// /// Type: UINT /// /// The integer value of the highest message value to be retrieved. Use WM_KEYLAST to specify the last keyboard message or /// WM_MOUSELAST to specify the last mouse message. /// /// Use WM_INPUT here and in wMsgFilterMin to specify only the WM_INPUT messages. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering /// is performed). /// /// /// /// Type: Type: BOOL /// If the function retrieves a message other than WM_QUIT, the return value is nonzero. /// If the function retrieves the WM_QUIT message, the return value is zero. /// /// If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an /// invalid pointer. To get extended error information, call GetLastError. /// /// Because the return value can be nonzero, zero, or -1, avoid code like this: /// /// The possibility of a -1 return value in the case that hWnd is an invalid parameter (such as referring to a window that has /// already been destroyed) means that such code can lead to fatal application errors. Instead, use code like this: /// /// /// /// An application typically uses the return value to determine whether to end the main message loop and exit the program. /// /// The GetMessage function retrieves messages associated with the window identified by the hWnd parameter or any of its /// children, as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and /// wMsgFilterMax parameters. Note that an application can only use the low word in the wMsgFilterMin and wMsgFilterMax parameters; /// the high word is reserved for the system. /// /// /// Note that GetMessage always retrieves WM_QUIT messages, no matter which values you specify for wMsgFilterMin and wMsgFilterMax. /// /// /// During this call, the system delivers pending, non-queued messages, that is, messages sent to windows owned by the calling thread /// using the SendMessage, SendMessageCallback, SendMessageTimeout, or SendNotifyMessage function. Then the first queued message that /// matches the specified filter is retrieved. The system may also process internal events. If no filter is specified, messages are /// processed in the following order: /// /// /// /// Sent messages /// /// /// Posted messages /// /// /// Input (hardware) messages and system internal events /// /// /// Sent messages (again) /// /// /// WM_PAINT messages /// /// /// WM_TIMER messages /// /// /// To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters. /// GetMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until processed. /// /// If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not /// responding and replaces it with a ghost window that has the same z-order, location, size, and visual attributes. This allows the /// user to move it, resize it, or even close the application. However, these are the only actions available because the application /// is actually not responding. When in the debugger mode, the system does not generate a ghost window. /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The output is in the mode of the window that the message is targeting. The /// calling thread is not taken into consideration. /// /// Examples /// For an example, see Creating a Message Loop. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmessage BOOL GetMessage( LPMSG lpMsg, HWND hWnd, UINT // wMsgFilterMin, UINT wMsgFilterMax ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetMessage(out MSG lpMsg, [Optional] HWND hWnd, [Optional] uint wMsgFilterMin, [Optional] uint wMsgFilterMax); /// /// Retrieves the extra message information for the current thread. Extra message information is an application- or driver-defined /// value associated with the current thread's message queue. /// /// /// Type: Type: LPARAM /// The return value specifies the extra information. The meaning of the extra information is device specific. /// /// To set a thread's extra message information, use the SetMessageExtraInfo function. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmessageextrainfo LPARAM GetMessageExtraInfo( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern IntPtr GetMessageExtraInfo(); /// /// Retrieves the cursor position for the last message retrieved by the GetMessage function. /// To determine the current position of the cursor, use the GetCursorPos function. /// /// /// Type: Type: DWORD /// /// The return value specifies the x- and y-coordinates of the cursor position. The x-coordinate is the low order short and /// the y-coordinate is the high-order short. /// /// /// /// /// As noted above, the x-coordinate is in the low-order short of the return value; the y-coordinate is in the high-order /// short (both represent signed values because they can take negative values on systems with multiple monitors). If the /// return value is assigned to a variable, you can use the MAKEPOINTS macro to obtain a POINTS structure from the return value. You /// can also use the GET_X_LPARAM or GET_Y_LPARAM macro to extract the x- or y-coordinate. /// /// /// Important Do not use the LOWORD or HIWORD macros to extract the x- and y- coordinates of the cursor position because these /// macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- /// coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmessagepos DWORD GetMessagePos( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern uint GetMessagePos(); /// /// Retrieves the message time for the last message retrieved by the GetMessage function. The time is a long integer that specifies /// the elapsed time, in milliseconds, from the time the system was started to the time the message was created (that is, placed in /// the thread's message queue). /// /// /// Type: Type: LONG /// The return value specifies the message time. /// /// /// /// The return value from the GetMessageTime function does not necessarily increase between subsequent messages, because the /// value wraps to wraps to the minimum value for a long integer if the timer count exceeds the maximum value for a long integer. /// /// /// To calculate time delays between messages, subtract the time of the first message from the time of the second message (ignoring /// overflow) and compare the result of the subtraction against the desired delay amount. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmessagetime LONG GetMessageTime( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern int GetMessageTime(); /// Retrieves the type of messages found in the calling thread's message queue. /// /// Type: UINT /// The types of messages for which to check. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// QS_ALLEVENTS (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY) /// An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue. /// /// /// QS_ALLINPUT (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE) /// Any message is in the queue. /// /// /// QS_ALLPOSTMESSAGE 0x0100 /// A posted message (other than those listed here) is in the queue. /// /// /// QS_HOTKEY 0x0080 /// A WM_HOTKEY message is in the queue. /// /// /// QS_INPUT (QS_MOUSE | QS_KEY | QS_RAWINPUT) /// An input message is in the queue. /// /// /// QS_KEY 0x0001 /// A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue. /// /// /// QS_MOUSE (QS_MOUSEMOVE | QS_MOUSEBUTTON) /// A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). /// /// /// QS_MOUSEBUTTON 0x0004 /// A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). /// /// /// QS_MOUSEMOVE 0x0002 /// A WM_MOUSEMOVE message is in the queue. /// /// /// QS_PAINT 0x0020 /// A WM_PAINT message is in the queue. /// /// /// QS_POSTMESSAGE 0x0008 /// A posted message (other than those listed here) is in the queue. /// /// /// QS_RAWINPUT 0x0400 /// A raw input message is in the queue. For more information, see Raw Input. Windows 2000: This flag is not supported. /// /// /// QS_SENDMESSAGE 0x0040 /// A message sent by another thread or application is in the queue. /// /// /// QS_TIMER 0x0010 /// A WM_TIMER message is in the queue. /// /// /// /// /// Type: Type: DWORD /// /// 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 /// GetQueueStatus, GetMessage, or PeekMessage function. /// /// /// /// /// The presence of a QS_ flag in the return value does not guarantee that a subsequent call to the GetMessage or PeekMessage /// function will return a message. GetMessage and PeekMessage perform some internal filtering that may cause the /// message to be processed internally. For this reason, the return value from GetQueueStatus should be considered only a hint /// as to whether GetMessage or PeekMessage should be called. /// /// /// The QS_ALLPOSTMESSAGE and QS_POSTMESSAGE flags differ in when they are cleared. QS_POSTMESSAGE is cleared /// when you call GetMessage or PeekMessage, whether or not you are filtering messages. QS_ALLPOSTMESSAGE is cleared when you /// call GetMessage or PeekMessage without filtering messages (wMsgFilterMin and wMsgFilterMax are 0). This can be /// useful when you call PeekMessage multiple times to get messages in different ranges. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getqueuestatus DWORD GetQueueStatus( UINT flags ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern uint GetQueueStatus(QS flags); /// /// /// Determines whether the current window procedure is processing a message that was sent from another thread (in the same process or /// a different process) by a call to the SendMessage function. /// /// To obtain additional information about how the message was sent, use the InSendMessageEx function. /// /// /// Type: Type: BOOL /// /// If the window procedure is processing a message sent to it from another thread using the SendMessage function, the return value /// is nonzero. /// /// /// If the window procedure is not processing a message sent to it from another thread using the SendMessage function, the return /// value is zero. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-insendmessage BOOL InSendMessage( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InSendMessage(); /// /// Determines whether the current window procedure is processing a message that was sent from another thread (in the same process or /// a different process). /// /// /// Type: LPVOID /// Reserved; must be NULL. /// /// /// Type: Type: DWORD /// /// If the message was not sent, the return value is ISMEX_NOSEND (0x00000000). Otherwise, the return value is one or more of /// the following values. /// /// /// /// Return code/value /// Description /// /// /// ISMEX_CALLBACK 0x00000004 /// The message was sent using the SendMessageCallback function. The thread that sent the message is not blocked. /// /// /// ISMEX_NOTIFY 0x00000002 /// The message was sent using the SendNotifyMessage function. The thread that sent the message is not blocked. /// /// /// ISMEX_REPLIED 0x00000008 /// The window procedure has processed the message. The thread that sent the message is no longer blocked. /// /// /// ISMEX_SEND 0x00000001 /// /// The message was sent using the SendMessage or SendMessageTimeout function. If ISMEX_REPLIED is not set, the thread that sent the /// message is blocked. /// /// /// /// /// To determine if the sender is blocked, use the following test: // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-insendmessageex DWORD InSendMessageEx( LPVOID lpReserved ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern ISMEX InSendMessageEx([Optional] IntPtr lpReserved); /// Determines whether the last message read from the current thread's queue originated from a WOW64 process. /// /// The function returns TRUE if the last message read from the current thread's queue originated from a WOW64 process, and FALSE otherwise. /// /// /// /// This function is useful to helping you develop 64-bit native applications that can receive private messages sent from 32-bit /// client applications, if the messages are associated with data structures that contain pointer-dependent data. In these /// situations, you can call this function in your 64-bit native application to determine if the message originated from a WOW64 /// process and then thunk the message appropriately. /// /// Examples /// /// For compatibility with operating systems that do not support this function, call GetProcAddress to detect whether /// IsWow64Message is implemented in User32.dll. If GetProcAddress succeeds, it is safe to call this function. /// Otherwise, WOW64 is not present. Note that this technique is not a reliable way to detect whether the operating system is a /// 64-bit version of Windows because the User32.dll in current versions of 32-bit Windows also contains this function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-iswow64message BOOL IsWow64Message( ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "bc0ac424-3c5b-41bf-9dae-bcb405d5b548")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Message(); /// /// /// Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses. The objects can /// include input event objects, which you specify using the dwWakeMask parameter. /// /// To enter an alertable wait state, use the MsgWaitForMultipleObjectsEx function. /// /// /// The number of object handles in the array pointed to by pHandles. The maximum number of object handles is /// MAXIMUM_WAIT_OBJECTS minus one. If this parameter has the value zero, then the function waits only for an input event. /// /// /// /// An array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The /// array can contain handles of objects of different types. It may not contain multiple copies of the same handle. /// /// If one of these handles is closed while the wait is still pending, the function's behavior is undefined. /// The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights. /// /// /// If this parameter is TRUE, the function returns when the states of all objects in the pHandles array have been set to /// signaled and an input event has been received. If this parameter is FALSE, the function returns when the state of any one /// of the objects is set to signaled or an input event has been received. In this case, the return value indicates the object whose /// state caused the function to return. /// /// /// The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the specified objects are /// signaled or the interval elapses. If dwMilliseconds is zero, the function does not enter a wait state if the specified objects /// are not signaled; it always returns immediately. If dwMilliseconds is INFINITE, the function will return only when the /// specified objects are signaled. /// /// /// /// The input types for which an input event object handle will be added to the array of object handles. This parameter can be any /// combination of the following values. /// /// /// /// Value /// Meaning /// /// /// QS_ALLEVENTS 0x04BF /// /// An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue. This value is a combination of QS_INPUT, /// QS_POSTMESSAGE, QS_TIMER, QS_PAINT, and QS_HOTKEY. /// /// /// /// QS_ALLINPUT 0x04FF /// /// Any message is in the queue. This value is a combination of QS_INPUT, QS_POSTMESSAGE, QS_TIMER, QS_PAINT, QS_HOTKEY, and QS_SENDMESSAGE. /// /// /// /// QS_ALLPOSTMESSAGE 0x0100 /// A posted message is in the queue. This value is cleared when you call GetMessage or PeekMessage without filtering messages. /// /// /// QS_HOTKEY 0x0080 /// A WM_HOTKEY message is in the queue. /// /// /// QS_INPUT 0x407 /// An input message is in the queue. This value is a combination of QS_MOUSE, QS_KEY, and QS_RAWINPUT. /// /// /// QS_KEY 0x0001 /// A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue. /// /// /// QS_MOUSE 0x0006 /// /// A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). This value is a combination of /// QS_MOUSEMOVE and QS_MOUSEBUTTON. /// /// /// /// QS_MOUSEBUTTON 0x0004 /// A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). /// /// /// QS_MOUSEMOVE 0x0002 /// A WM_MOUSEMOVE message is in the queue. /// /// /// QS_PAINT 0x0020 /// A WM_PAINT message is in the queue. /// /// /// QS_POSTMESSAGE 0x0008 /// /// A posted message is in the queue. This value is cleared when you call GetMessage or PeekMessage, whether or not you are filtering messages. /// /// /// /// QS_RAWINPUT 0x0400 /// A raw input message is in the queue. For more information, see Raw Input. /// /// /// QS_SENDMESSAGE 0x0040 /// A message sent by another thread or application is in the queue. /// /// /// QS_TIMER 0x0010 /// A WM_TIMER message is in the queue. /// /// /// /// /// /// If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following /// values. (Note that WAIT_OBJECT_0 is defined as 0 and WAIT_ABANDONED_0 is defined as 0x00000080L.) /// /// /// /// Return code/value /// Description /// /// /// WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount– 1) /// /// If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled. If bWaitAll is FALSE, the /// return value minus WAIT_OBJECT_0 indicates the pHandles array index of the object that satisfied the wait. /// /// /// /// WAIT_OBJECT_0 + nCount /// /// New input of the type specified in the dwWakeMask parameter is available in the thread's input queue. Functions such as /// PeekMessage, GetMessage, and WaitMessage mark messages in the queue as old messages. Therefore, after you call one of these /// functions, a subsequent call to MsgWaitForMultipleObjects will not return until new input of the specified type arrives. This /// value is also returned upon the occurrence of a system event that requires the thread's action, such as foreground activation. /// Therefore, MsgWaitForMultipleObjects can return even though no appropriate input is available and even if dwWakeMask is set to 0. /// If this occurs, call GetMessage or PeekMessage to process the system event before trying the call to MsgWaitForMultipleObjects again. /// /// /// /// WAIT_ABANDONED_0 to (WAIT_ABANDONED_0 + nCount– 1) /// /// If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled and at least one of the /// objects is an abandoned mutex object. If bWaitAll is FALSE, the return value minus WAIT_ABANDONED_0 indicates the pHandles array /// index of an abandoned mutex object that satisfied the wait. Ownership of the mutex object is granted to the calling thread, and /// the mutex is set to nonsignaled. If the mutex was protecting persistent state information, you should check it for consistency. /// /// /// /// WAIT_TIMEOUT 258L /// The time-out interval elapsed and the conditions specified by the bWaitAll and dwWakeMask parameters were not satisfied. /// /// /// WAIT_FAILED (DWORD)0xFFFFFFFF /// The function has failed. To get extended error information, call GetLastError. /// /// /// /// /// /// The MsgWaitForMultipleObjects function determines whether the wait criteria have been met. If the criteria have not been /// met, the calling thread enters the wait state until the conditions of the wait criteria have been met or the time-out interval elapses. /// /// /// When bWaitAll is TRUE, the function does not modify the states of the specified objects until the states of all objects /// have been set to signaled. For example, a mutex can be signaled, but the thread does not get ownership until the states of the /// other objects have also been set to signaled. In the meantime, some other thread may get ownership of the mutex, thereby setting /// its state to nonsignaled. /// /// /// When bWaitAll is TRUE, the function's wait is completed only when the states of all objects have been set to signaled and /// an input event has been received. Therefore, setting bWaitAll to TRUE prevents input from being processed until the state /// of all objects in the pHandles array have been set to signaled. For this reason, if you set bWaitAll to TRUE, you should /// use a short timeout value in dwMilliseconds. If you have a thread that creates windows waiting for all objects in the pHandles /// array, including input events specified by dwWakeMask, with no timeout interval, the system will deadlock. This is because /// threads that create windows must process messages. DDE sends message to all windows in the system. Therefore, if a thread creates /// windows, do not set the bWaitAll parameter to TRUE in calls to MsgWaitForMultipleObjects made from that thread. /// /// /// When bWaitAll is FALSE, this function checks the handles in the array in order starting with index 0, until one of the /// objects is signaled. If multiple objects become signaled, the function returns the index of the first handle in the array whose /// object was signaled. /// /// /// MsgWaitForMultipleObjects does not return if there is unread input of the specified type in the message queue after the /// thread has called a function to check the queue. This is because functions such as PeekMessage, GetMessage, GetQueueStatus, and /// WaitMessage check the queue and then change the state information for the queue so that the input is no longer considered new. A /// subsequent call to MsgWaitForMultipleObjects will not return until new input of the specified type arrives. The existing /// unread input (received prior to the last time the thread checked the queue) is ignored. /// /// /// The function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects /// whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one. For more /// information, see the documentation for the individual synchronization objects. /// /// /// The MsgWaitForMultipleObjects function can specify handles of any of the following object types in the pHandles array: /// /// /// /// Change notification /// /// /// Console input /// /// /// Event /// /// /// Memory resource notification /// /// /// Mutex /// /// /// Process /// /// /// Semaphore /// /// /// Thread /// /// /// Waitable timer /// /// /// /// The QS_ALLPOSTMESSAGE and QS_POSTMESSAGE flags differ in when they are cleared. QS_POSTMESSAGE is cleared /// when you call GetMessage or PeekMessage, whether or not you are filtering messages. QS_ALLPOSTMESSAGE is cleared when you /// call GetMessage or PeekMessage without filtering messages (wMsgFilterMin and wMsgFilterMax are 0). This can be useful when /// you call PeekMessage multiple times to get messages in different ranges. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-msgwaitformultipleobjects DWORD MsgWaitForMultipleObjects( // DWORD nCount, const HANDLE *pHandles, BOOL fWaitAll, DWORD dwMilliseconds, DWORD dwWakeMask ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "0629f1b3-6805-43a7-9aeb-4f80939ec62c")] public static extern uint MsgWaitForMultipleObjects(uint nCount, HANDLE[] pHandles, [MarshalAs(UnmanagedType.Bool)] bool fWaitAll, uint dwMilliseconds, QS dwWakeMask); /// /// /// Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure /// call (APC) is queued to the thread, or the time-out interval elapses. The array of objects can include input event objects, which /// you specify using the dwWakeMask parameter. /// /// /// /// /// The number of object handles in the array pointed to by pHandles. The maximum number of object handles is /// MAXIMUM_WAIT_OBJECTS minus one. If this parameter has the value zero, then the function waits only for an input event. /// /// /// /// /// An array of object handles. For a list of the object types whose handles you can specify, see the Remarks section later in this /// topic. The array can contain handles to multiple types of objects. It may not contain multiple copies of the same handle. /// /// If one of these handles is closed while the wait is still pending, the function's behavior is undefined. /// The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights. /// /// /// /// The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the specified objects are /// signaled, an I/O completion routine or APC is queued, or the interval elapses. If dwMilliseconds is zero, the function does not /// enter a wait state if the criteria is not met; it always returns immediately. If dwMilliseconds is INFINITE, the function /// will return only when the specified objects are signaled or an I/O completion routine or APC is queued. /// /// /// /// /// The input types for which an input event object handle will be added to the array of object handles. This parameter can be one or /// more of the following values. /// /// /// /// Value /// Meaning /// /// /// QS_ALLEVENTS 0x04BF /// /// An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue. This value is a combination of QS_INPUT, /// QS_POSTMESSAGE, QS_TIMER, QS_PAINT, and QS_HOTKEY. /// /// /// /// QS_ALLINPUT 0x04FF /// /// Any message is in the queue. This value is a combination of QS_INPUT, QS_POSTMESSAGE, QS_TIMER, QS_PAINT, QS_HOTKEY, and QS_SENDMESSAGE. /// /// /// /// QS_ALLPOSTMESSAGE 0x0100 /// A posted message is in the queue. This value is cleared when you call GetMessage or PeekMessage without filtering messages. /// /// /// QS_HOTKEY 0x0080 /// A WM_HOTKEY message is in the queue. /// /// /// QS_INPUT 0x407 /// An input message is in the queue. This value is a combination of QS_MOUSE, QS_KEY, and QS_RAWINPUT. /// /// /// QS_KEY 0x0001 /// A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue. /// /// /// QS_MOUSE 0x0006 /// /// A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). This value is a combination of /// QS_MOUSEMOVE and QS_MOUSEBUTTON. /// /// /// /// QS_MOUSEBUTTON 0x0004 /// A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). /// /// /// QS_MOUSEMOVE 0x0002 /// A WM_MOUSEMOVE message is in the queue. /// /// /// QS_PAINT 0x0020 /// A WM_PAINT message is in the queue. /// /// /// QS_POSTMESSAGE 0x0008 /// /// A posted message is in the queue. This value is cleared when you call GetMessage or PeekMessage, whether or not you are filtering messages. /// /// /// /// QS_RAWINPUT 0x0400 /// A raw input message is in the queue. For more information, see Raw Input. /// /// /// QS_SENDMESSAGE 0x0040 /// A message sent by another thread or application is in the queue. /// /// /// QS_TIMER 0x0010 /// A WM_TIMER message is in the queue. /// /// /// /// /// The wait type. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// /// The function returns when any one of the objects is signaled. The return value indicates the object whose state caused the /// function to return. /// /// /// /// MWMO_ALERTABLE 0x0002 /// /// The function also returns if an APC has been queued to the thread with QueueUserAPC while the thread is in the waiting state. /// /// /// /// MWMO_INPUTAVAILABLE 0x0004 /// /// The function returns if input exists for the queue, even if the input has been seen (but not removed) using a call to another /// function, such as PeekMessage. /// /// /// /// MWMO_WAITALL 0x0001 /// /// The function returns when all objects in the pHandles array are signaled and an input event has been received, all at the same time. /// /// /// /// /// /// /// If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following /// values. (Note that WAIT_OBJECT_0 is defined as 0 and WAIT_ABANDONED_0 is defined as 0x00000080L.) /// /// /// /// Return code/value /// Description /// /// /// WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount - 1) /// /// If the MWMO_WAITALL flag is used, the return value indicates that the state of all specified objects is signaled. Otherwise, the /// return value minus WAIT_OBJECT_0 indicates the pHandles array index of the object that caused the function to return. /// /// /// /// WAIT_OBJECT_0 + nCount /// /// New input of the type specified in the dwWakeMask parameter is available in the thread's input queue. Functions such as /// PeekMessage, GetMessage, GetQueueStatus, and WaitMessage mark messages in the queue as old messages. Therefore, after you call /// one of these functions, a subsequent call to MsgWaitForMultipleObjectsEx will not return until new input of the specified type /// arrives. This value is also returned upon the occurrence of a system event that requires the thread's action, such as foreground /// activation. Therefore, MsgWaitForMultipleObjectsEx can return even though no appropriate input is available and even if /// dwWakeMask is set to 0. If this occurs, call GetMessage or PeekMessage to process the system event before trying the call to /// MsgWaitForMultipleObjectsEx again. /// /// /// /// WAIT_ABANDONED_0 to (WAIT_ABANDONED_0 + nCount - 1) /// /// If the MWMO_WAITALL flag is used, the return value indicates that the state of all specified objects is signaled and at least one /// of the objects is an abandoned mutex object. Otherwise, the return value minus WAIT_ABANDONED_0 indicates the pHandles array /// index of an abandoned mutex object that caused the function to return. Ownership of the mutex object is granted to the calling /// thread, and the mutex is set to nonsignaled. If the mutex was protecting persistent state information, you should check it for consistency. /// /// /// /// WAIT_IO_COMPLETION 0x000000C0L /// The wait was ended by one or more user-mode asynchronous procedure calls (APC) queued to the thread. /// /// /// WAIT_TIMEOUT 258L /// The time-out interval elapsed, but the conditions specified by the dwFlags and dwWakeMask parameters were not met. /// /// /// WAIT_FAILED (DWORD)0xFFFFFFFF /// The function has failed. To get extended error information, call GetLastError. /// /// /// /// /// /// The MsgWaitForMultipleObjectsEx function determines whether the conditions specified by dwWakeMask and dwFlags have been /// met. If the conditions have not been met, the calling thread enters the wait state until the conditions of the wait criteria have /// been met or the time-out interval elapses. /// /// /// When dwFlags is zero, this function checks the handles in the array in order starting with index 0, until one of the objects is /// signaled. If multiple objects become signaled, the function returns the index of the first handle in the array whose object was signaled. /// /// /// MsgWaitForMultipleObjectsEx does not return if there is unread input of the specified type in the message queue after the /// thread has called a function to check the queue, unless you use the MWMO_INPUTAVAILABLE flag. This is because functions /// such as PeekMessage, GetMessage, GetQueueStatus, and WaitMessage check the queue and then change the state information for the /// queue so that the input is no longer considered new. A subsequent call to MsgWaitForMultipleObjectsEx will not return /// until new input of the specified type arrives, unless you use the MWMO_INPUTAVAILABLE flag. If this flag is not used, the /// existing unread input (received prior to the last time the thread checked the queue) is ignored. /// /// /// The function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects /// whose signaled state caused the function to return. For example, the system decreases the count of a semaphore object by one. For /// more information, see the documentation for the individual synchronization objects. /// /// /// The MsgWaitForMultipleObjectsEx function can specify handles of any of the following object types in the pHandles array: /// /// /// /// Change notification /// /// /// Console input /// /// /// Event /// /// /// Memory resource notification /// /// /// Mutex /// /// /// Process /// /// /// Semaphore /// /// /// Thread /// /// /// Waitable timer /// /// /// /// The QS_ALLPOSTMESSAGE and QS_POSTMESSAGE flags differ in when they are cleared. QS_POSTMESSAGE is cleared /// when you call GetMessage or PeekMessage, whether or not you are filtering messages. QS_ALLPOSTMESSAGE is cleared when you /// call GetMessage or PeekMessage without filtering messages (wMsgFilterMin and wMsgFilterMax are 0). This can be /// useful when you call PeekMessage multiple times to get messages in different ranges. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-msgwaitformultipleobjectsex DWORD // MsgWaitForMultipleObjectsEx( DWORD nCount, const HANDLE *pHandles, DWORD dwMilliseconds, DWORD dwWakeMask, DWORD dwFlags ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "1774b721-3ad4-492e-96af-b71de9066f0c")] public static extern uint MsgWaitForMultipleObjectsEx(uint nCount, HANDLE[] pHandles, uint dwMilliseconds, QS dwWakeMask, MWMO dwFlags); /// Packs a Dynamic Data Exchange (DDE) lParam value into an internal structure used for sharing DDE data between processes. /// /// Type: UINT /// The DDE message to be posted. /// /// /// Type: UINT_PTR /// A value that corresponds to the 16-bit Windows low-order word of an lParam parameter for the DDE message being posted. /// /// /// Type: UINT_PTR /// A value that corresponds to the 16-bit Windows high-order word of an lParam parameter for the DDE message being posted. /// /// /// Type: LPARAM /// The return value is the lParam value. /// /// /// /// The return value must be posted as the lParam parameter of a DDE message; it must not be used for any other purpose. After the /// application posts a return value, it need not perform any action to dispose of the lParam parameter. /// /// An application should call this function only for posted DDE messages. /// // https://docs.microsoft.com/en-us/windows/desktop/api/dde/nf-dde-packddelparam LPARAM PackDDElParam( UINT msg, UINT_PTR uiLo, // UINT_PTR uiHi ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dde.h", MSDNShortId = "")] public static extern IntPtr PackDDElParam(uint msg, IntPtr uiLo, IntPtr uiHi); /// /// Dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist). /// /// /// Type: LPMSG /// A pointer to an MSG structure that receives message information. /// /// /// Type: HWND /// A handle to the window whose messages are to be retrieved. The window must belong to the current thread. /// /// If hWnd is NULL, 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 /// NULL, both window messages and thread messages are processed. /// /// /// 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 PostMessage (when the hWnd parameter is NULL) or PostThreadMessage. /// /// /// /// Type: UINT /// /// The value of the first message in the range of messages to be examined. Use WM_KEYFIRST (0x0100) to specify the first /// keyboard message or WM_MOUSEFIRST (0x0200) to specify the first mouse message. /// /// /// If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering /// is performed). /// /// /// /// Type: UINT /// /// The value of the last message in the range of messages to be examined. Use WM_KEYLAST to specify the last keyboard message /// or WM_MOUSELAST to specify the last mouse message. /// /// /// If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering /// is performed). /// /// /// /// Type: UINT /// Specifies how messages are to be handled. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// PM_NOREMOVE 0x0000 /// Messages are not removed from the queue after processing by PeekMessage. /// /// /// PM_REMOVE 0x0001 /// Messages are removed from the queue after processing by PeekMessage. /// /// /// PM_NOYIELD 0x0002 /// /// Prevents the system from releasing any thread that is waiting for the caller to go idle (see WaitForInputIdle). Combine this /// value with either PM_NOREMOVE or PM_REMOVE. /// /// /// /// /// By default, all message types are processed. To specify that only certain message should be processed, specify one or more of the /// following values. /// /// /// /// Value /// Meaning /// /// /// PM_QS_INPUT (QS_INPUT << 16) /// Process mouse and keyboard messages. /// /// /// PM_QS_PAINT (QS_PAINT << 16) /// Process paint messages. /// /// /// PM_QS_POSTMESSAGE ((QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER) << 16) /// Process all posted messages, including timers and hotkeys. /// /// /// PM_QS_SENDMESSAGE (QS_SENDMESSAGE << 16) /// Process all sent messages. /// /// /// /// /// Type: Type: BOOL /// If a message is available, the return value is nonzero. /// If no messages are available, the return value is zero. /// /// /// /// PeekMessage retrieves messages associated with the window identified by the hWnd parameter or any of its children as /// specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and wMsgFilterMax /// parameters. Note that an application can only use the low word in the wMsgFilterMin and wMsgFilterMax parameters; the high word /// is reserved for the system. /// /// /// Note that PeekMessage always retrieves WM_QUIT messages, no matter which values you specify for wMsgFilterMin and wMsgFilterMax. /// /// /// During this call, the system delivers pending, non-queued messages, that is, messages sent to windows owned by the calling thread /// using the SendMessage, SendMessageCallback, SendMessageTimeout, or SendNotifyMessage function. Then the first queued message that /// matches the specified filter is retrieved. The system may also process internal events. If no filter is specified, messages are /// processed in the following order: /// /// /// /// Sent messages /// /// /// Posted messages /// /// /// Input (hardware) messages and system internal events /// /// /// Sent messages (again) /// /// /// WM_PAINT messages /// /// /// WM_TIMER messages /// /// /// To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters. /// /// The PeekMessage function normally does not remove WM_PAINT messages from the queue. WM_PAINT messages remain in the /// queue until they are processed. However, if a WM_PAINT message has a NULL update region, PeekMessage does /// remove it from the queue. /// /// /// If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not /// responding and replaces it with a ghost window that has the same z-order, location, size, and visual attributes. This allows the /// user to move it, resize it, or even close the application. However, these are the only actions available because the application /// is actually not responding. When an application is being debugged, the system does not generate a ghost window. /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The output is in the mode of the window that the message is targeting. The /// calling thread is not taken into consideration. /// /// Examples /// For an example, see Examining a Message Queue. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-peekmessagea BOOL PeekMessageA( LPMSG lpMsg, HWND hWnd, // UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PeekMessage(out MSG lpMsg, [Optional] HWND hWnd, [Optional] uint wMsgFilterMin, [Optional] uint wMsgFilterMax, [Optional] PM wRemoveMsg); /// /// /// Places (posts) a message in the message queue associated with the thread that created the specified window and returns without /// waiting for the thread to process the message. /// /// To post a message in the message queue associated with a thread, use the PostThreadMessage function. /// /// /// Type: HWND /// A handle to the window whose window procedure is to receive the message. The following values have special meanings. /// /// /// Value /// Meaning /// /// /// HWND_BROADCAST ((HWND)0xffff) /// /// The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped /// windows, and pop-up windows. The message is not posted to child windows. /// /// /// /// NULL /// /// The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread. /// /// /// /// /// Starting with Windows Vista, message posting is subject to UIPI. The thread of a process can post messages only to message queues /// of threads in processes of lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be posted. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError /// returns ERROR_NOT_ENOUGH_QUOTA when the limit is hit. /// /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// Messages in a message queue are retrieved by calls to the GetMessage or PeekMessage function. /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// /// If you send a message in the range below WM_USER to the asynchronous message functions ( PostMessage, SendNotifyMessage, /// and SendMessageCallback), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions will /// return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used. /// /// Do not post the WM_QUIT message using PostMessage; use the PostQuitMessage function. /// /// An accessibility application can use PostMessage to post WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// /// There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application /// exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the /// following registry key. /// /// HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWindowsUSERPostMessageLimit /// The minimum acceptable value is 4000. /// Examples /// /// The following example shows how to post a private window message using the PostMessage function. Assume you defined a /// private window message called WM_COMPLETE: /// /// You can post a message to the message queue associated with the thread that created the specified window as shown below: /// For more examples, see Initiating a Data Link. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postmessagea BOOL PostMessageA( HWND hWnd, UINT Msg, // WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PostMessage([Optional] HWND hWnd, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam); /// /// Indicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message. /// /// /// Type: int /// The application exit code. This value is used as the wParam parameter of the WM_QUIT message. /// /// /// /// The PostQuitMessage function posts a WM_QUIT message to the thread's message queue and returns immediately; the function /// simply indicates to the system that the thread is requesting to quit at some time in the future. /// /// /// When the thread retrieves the WM_QUIT message from its message queue, it should exit its message loop and return control to the /// system. The exit value returned to the system must be the wParam parameter of the WM_QUIT message. /// /// Examples /// For an example, see Posting a Message. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postquitmessage void PostQuitMessage( int nExitCode ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern void PostQuitMessage([Optional] int nExitCode); /// /// Posts a message to the message queue of the specified thread. It returns without waiting for the thread to process the message. /// /// /// Type: DWORD /// The identifier of the thread to which the message is to be posted. /// /// 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. For more information, see the Remarks section. /// /// /// 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. /// /// /// 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 ERROR_INVALID_THREAD_ID. /// /// /// 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 ERROR_INVALID_THREAD_ID. /// /// /// /// Type: UINT /// The type of message to be posted. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError /// returns 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 ERROR_NOT_ENOUGH_QUOTA when the message limit is hit. /// /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails. /// Use the following method to handle this situation. /// /// /// /// Create an event object, then create the thread. /// /// /// Use the WaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage. /// /// /// /// In the thread to which the message will be posted, call PeekMessage as shown here to force the system to create the message queue. /// /// /// /// Set the event, to indicate that the thread is ready to receive posted messages. /// /// /// /// The thread to which the message is posted retrieves the message by calling the GetMessage or PeekMessage function. The /// hwnd member of the returned MSG structure is NULL. /// /// /// Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated /// with a window cannot be dispatched by the DispatchMessage function. Therefore, if the recipient thread is in a modal loop (as /// used by MessageBox or DialogBox), the messages will be lost. To intercept thread messages while in a modal loop, use a /// thread-specific hook. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// /// There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application /// exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the /// following registry key. /// /// HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWindowsUSERPostMessageLimit /// The minimum acceptable value is 4000. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postthreadmessagea BOOL PostThreadMessageA( DWORD // idThread, UINT Msg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PostThreadMessage(uint idThread, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam); /// /// Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or /// posting messages. /// /// /// Type: LPCTSTR /// The message to be registered. /// /// /// Type: Type: UINT /// If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The RegisterWindowMessage function is typically used to register messages for communicating between two cooperating applications. /// /// /// If two different applications register the same message string, the applications return the same message value. The message /// remains registered until the session ends. /// /// /// Only use RegisterWindowMessage when more than one application must process the same message. For sending private messages /// within a window class, an application can use any integer in the range WM_USER through 0x7FFF. (Messages in this range are /// private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, /// LISTBOX, and COMBOBOX may use values in this range.) /// /// Examples /// For an example, see Finding Text. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registerwindowmessagea UINT RegisterWindowMessageA( LPCSTR // lpString ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] public static extern uint RegisterWindowMessage(string lpString); /// Replies to a message sent from another thread by the SendMessage function. /// /// Type: LRESULT /// The result of the message processing. The possible values are based on the message sent. /// /// /// Type: Type: BOOL /// If the calling thread was processing a message sent from another thread or process, the return value is nonzero. /// If the calling thread was not processing a message sent from another thread or process, the return value is zero. /// /// /// /// By calling this function, the window procedure that receives the message allows the thread that called SendMessage to continue to /// run as though the thread receiving the message had returned control. The thread that calls the ReplyMessage function also /// continues to run. /// /// /// If the message was not sent through SendMessage or if the message was sent by the same thread, ReplyMessage has no effect. /// /// Examples /// For an example, see Sending a Message. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-replymessage BOOL ReplyMessage( LRESULT lResult ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ReplyMessage(IntPtr lResult); /// /// Enables an application to reuse a packed Dynamic Data Exchange (DDE) lParam parameter, rather than allocating a new packed /// lParam. Using this function reduces reallocations for applications that pass packed DDE messages. /// /// /// Type: LPARAM /// The lParam parameter of the posted DDE message being reused. /// /// /// Type: UINT /// The identifier of the received DDE message. /// /// /// Type: UINT /// The identifier of the DDE message to be posted. The DDE message will reuse the packed lParam parameter. /// /// /// Type: UINT_PTR /// The value to be packed into the low-order word of the reused lParam parameter. /// /// /// Type: UINT_PTR /// The value to be packed into the high-order word of the reused lParam parameter. /// /// /// Type: LPARAM /// The return value is the new lParam value. /// /// /// /// The return value must be posted as the lParam parameter of a DDE message; it must not be used for any other purpose. Once the /// return value is posted, the posting application need not perform any action to dispose of the lParam parameter. /// /// /// Use ReuseDDElParam instead of FreeDDElParam if the lParam parameter will be reused in a responding message. /// ReuseDDElParam returns the lParam appropriate for reuse. /// /// /// This function allocates or frees lParam parameters as needed, depending on the packing requirements of the incoming and outgoing /// messages. This reduces reallocations in passing DDE messages. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/dde/nf-dde-reuseddelparam LPARAM ReuseDDElParam( LPARAM lParam, UINT msgIn, // UINT msgOut, UINT_PTR uiLo, UINT_PTR uiHi ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dde.h", MSDNShortId = "")] public static extern IntPtr ReuseDDElParam(IntPtr lParam, uint msgIn, uint msgOut, IntPtr uiLo, IntPtr uiHi); /// /// /// 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. /// /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [System.Security.SecurityCritical] public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In, Optional] IntPtr wParam, [In, Out, Optional] IntPtr lParam); /// /// /// 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. /// /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [System.Security.SecurityCritical] public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In, Optional] IntPtr wParam, string lParam); /// /// /// 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. /// /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [System.Security.SecurityCritical] public static extern IntPtr SendMessage(HWND hWnd, uint msg, ref int wParam, [In, Out] StringBuilder lParam); /// /// /// 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. /// /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [System.Security.SecurityCritical] public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In, Optional] IntPtr wParam, [In, Out] StringBuilder lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// Type: WPARAM /// Additional message-specific information. /// Type: LPARAM /// Additional message-specific information. /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam) where TMsg : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), IntPtr.Zero, IntPtr.Zero); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, TWP wParam, [Optional] IntPtr lParam) where TMsg : struct, IConvertible where TWP : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), IntPtr.Zero); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This must be a type that can be marshaled to memory. /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, in TWP wParam, [Optional] IntPtr lParam) where TMsg : struct, IConvertible where TWP : struct { using var wmem = SafeCoTaskMemHandle.CreateFromStructure(wParam); return SendMessage(hWnd, Convert.ToUInt32(msg), wmem, lParam); } /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, TWP wParam, string lParam) where TMsg : struct, IConvertible where TWP : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, [In, Optional] IntPtr wParam, string lParam) where TMsg : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, [In, Optional] IntPtr wParam, StringBuilder lParam) where TMsg : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, TWP wParam, StringBuilder lParam) where TMsg : struct, IConvertible where TWP : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This can be any type that converts to . /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, [Optional] IntPtr wParam, TLP lParam) where TMsg : struct, IConvertible where TLP : struct, IConvertible => SendMessage(hWnd, Convert.ToUInt32(msg), wParam, (IntPtr)Convert.ToInt64(lParam)); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This must be a type that can be marshaled to memory. /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, [Optional] IntPtr wParam, ref TLP lParam) where TMsg : struct, IConvertible where TLP : struct => SendMessage(hWnd, Convert.ToUInt32(msg), wParam, ref lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This can be any type that converts to . /// The type of the parameter. This must be a type that can be marshaled to memory. /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, TWP wParam, ref TLP lParam) where TMsg : struct, IConvertible where TWP : struct, IConvertible where TLP : struct => SendMessage(hWnd, Convert.ToUInt32(msg), (IntPtr)Convert.ToInt64(wParam), ref lParam); /// /// /// 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. /// /// /// The type of the message. This can be any type that converts to . /// The type of the parameter. This must be a type that can be marshaled to memory. /// The type of the parameter. This must be a type that can be marshaled to memory. /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value specifies the result of the message processing; it depends on the message sent. /// /// /// When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied). /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshalling. /// /// /// If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the /// specified window was created by a different thread, the system switches to that thread and calls the appropriate window /// procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The /// sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming /// nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. /// For more information on nonqueued messages, see Nonqueued Messages. /// /// /// An accessibility application can use SendMessage to send WM_APPCOMMAND messages to the shell to launch applications. This /// functionality is not guaranteed to work for other types of applications. /// /// Examples /// For an example, see Displaying Keyboard Input. /// // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")] public static IntPtr SendMessage(HWND hWnd, TMsg msg, in TWP wParam, ref TLP lParam) where TMsg : struct, IConvertible where TWP : struct where TLP : struct { using var wmem = SafeCoTaskMemHandle.CreateFromStructure(wParam); return SendMessage(hWnd, Convert.ToUInt32(msg), wmem, ref lParam); } private static IntPtr SendMessage(HWND hWnd, uint msg, IntPtr wParam, ref TLP lParam) { // If this must mbe manually marshaled, do it if (typeof(IVanaraMarshaler).IsAssignableFrom(typeof(TLP))) return ManualMarshalSM(hWnd, msg, wParam, ref lParam); // Try to pin first as this is most efficient. // This will fail just like checking for blit-ability, so take the hit once. try { using var lpin = new PinnedObject(lParam); return SendMessage(hWnd, msg, wParam, lpin); } catch (ArgumentException) { // If not blitable, manually marshal return ManualMarshalSM(hWnd, msg, wParam, ref lParam); } catch { // For all other exceptions, throw error. throw; } static IntPtr ManualMarshalSM(HWND hWnd, uint msg, IntPtr wParam, ref TLP lParam) { using var lmem = SafeCoTaskMemHandle.CreateFromStructure(lParam); var lret = SendMessage(hWnd, msg, wParam, lmem); lParam = lmem.ToStructure(); return lret; } } /// /// Sends the specified message to a window or windows. It calls the window procedure for the specified window and returns /// immediately if the window belongs to another thread. After the window procedure processes the message, the system calls the /// specified callback function, passing the result of the message processing and an application-defined value to the callback function. /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: SENDASYNCPROC /// /// A pointer to a callback function that the system calls after the window procedure processes the message. For more information, /// see SendAsyncProc. /// /// /// If hWnd is HWND_BROADCAST ((HWND)0xffff), the system calls the SendAsyncProc callback function once for each top-level window. /// /// /// /// Type: ULONG_PTR /// An application-defined value to be sent to the callback function pointed to by the lpCallBack parameter. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// If the target window belongs to the same thread as the caller, then the window procedure is called synchronously, and the /// callback function is called immediately after the window procedure returns. If the target window belongs to a different thread /// from the caller, then the callback function is called only when the thread that called SendMessageCallback also calls /// GetMessage, PeekMessage, or WaitMessage. /// /// /// If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage, SendNotifyMessage, and /// SendMessageCallback), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions /// will return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used. /// /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendmessagecallbacka BOOL SendMessageCallbackA( HWND hWnd, // UINT Msg, WPARAM wParam, LPARAM lParam, SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SendMessageCallback(HWND hWnd, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam, Sendasyncproc lpResultCallBack, UIntPtr dwData); /// Sends the specified message to one or more windows. /// /// Type: HWND /// A handle to the window whose window procedure will receive the message. /// /// If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including /// disabled or invisible unowned windows. The function does not return until each window has timed out. Therefore, the total wait /// time can be up to the value of uTimeout multiplied by the number of top-level windows. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Any additional message-specific information. /// /// /// Type: LPARAM /// Any additional message-specific information. /// /// /// Type: UINT /// The behavior of this function. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// SMTO_ABORTIFHUNG 0x0002 /// /// The function returns without waiting for the time-out period to elapse if the receiving thread appears to not respond or "hangs." /// /// /// /// SMTO_BLOCK 0x0001 /// Prevents the calling thread from processing any other requests until the function returns. /// /// /// SMTO_NORMAL 0x0000 /// The calling thread is not prevented from processing other requests while waiting for the function to return. /// /// /// SMTO_NOTIMEOUTIFNOTHUNG 0x0008 /// The function does not enforce the time-out period as long as the receiving thread is processing messages. /// /// /// SMTO_ERRORONEXIT 0x0020 /// /// The function should return 0 if the receiving window is destroyed or its owning thread dies while the message is being processed. /// /// /// /// /// /// Type: UINT /// /// The duration of the time-out period, in milliseconds. If the message is a broadcast message, each window can use the full /// time-out period. For example, if you specify a five second time-out period and there are three top-level windows that fail to /// process the message, you could have up to a 15 second delay. /// /// /// /// Type: PDWORD_PTR /// The result of the message processing. The value of this parameter depends on the message that is specified. /// /// /// Type: Type: LRESULT /// /// If the function succeeds, the return value is nonzero. SendMessageTimeout does not provide information about individual /// windows timing out if HWND_BROADCAST is used. /// /// /// If the function fails or times out, the return value is 0. To get extended error information, call GetLastError. If /// GetLastError returns ERROR_TIMEOUT, then the function timed out. /// /// Windows 2000: If GetLastError returns 0, then the function timed out. /// /// /// /// The function calls the window procedure for the specified window and, if the specified window belongs to a different thread, does /// not return until the window procedure has processed the message or the specified time-out period has elapsed. If the window /// receiving the message belongs to the same queue as the current thread, the window procedure is called directly—the time-out value /// is ignored. /// /// /// This function considers that a thread is not responding if it has not called GetMessage or a similar function within five seconds. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendmessagetimeouta LRESULT SendMessageTimeoutA( HWND // hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] public static extern IntPtr SendMessageTimeout(HWND hWnd, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam, SMTO fuFlags, uint uTimeout, ref IntPtr lpdwResult); /// /// /// 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. /// /// /// /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of /// lesser or equal integrity level. /// /// /// /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// Additional message-specific information. /// Additional message-specific information. /// The return value specifies the result of the message processing; it depends on the message sent. // LRESULT WINAPI SendMessage( _In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam); https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto, EntryPoint = "SendMessage")] [PInvokeData("Winuser.h", MSDNShortId = "ms644950")] [System.Security.SecurityCritical] public static unsafe extern void* SendMessageUnsafe(void* hWnd, uint msg, void* wParam, void* lParam); /// /// Sends the specified message to a window or windows. If the window was created by the calling thread, SendNotifyMessage /// calls the window procedure for the window and does not return until the window procedure has processed the message. If the window /// was created by a different thread, SendNotifyMessage passes the message to the window procedure and returns immediately; /// it does not wait for the window procedure to finish processing the message. /// /// /// Type: HWND /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, /// overlapped windows, and pop-up windows; but the message is not sent to child windows. /// /// /// /// Type: UINT /// The message to be sent. /// For lists of the system-provided messages, see System-Defined Messages. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage, SendNotifyMessage, /// and SendMessageCallback), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions will /// return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used. /// /// /// Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a /// unique message for inter-application communication. /// /// /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= /// WM_USER) to another process, you must do custom marshaling. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendnotifymessagea BOOL SendNotifyMessageA( HWND hWnd, // UINT Msg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SendNotifyMessage(HWND hWnd, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam); /// /// Sets the extra message information for the current thread. Extra message information is an application- or driver-defined value /// associated with the current thread's message queue. An application can use the GetMessageExtraInfo function to retrieve a /// thread's extra message information. /// /// /// Type: LPARAM /// The value to be associated with the current thread. /// /// /// Type: Type: LPARAM /// The return value is the previous value associated with the current thread. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmessageextrainfo LPARAM SetMessageExtraInfo( LPARAM // lParam ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern IntPtr SetMessageExtraInfo(IntPtr lParam); /// /// 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 GetMessage or PeekMessage function. /// /// /// Type: const MSG* /// /// A pointer to an MSG structure that contains message information retrieved from the calling thread's message queue by using the /// GetMessage or PeekMessage function. /// /// /// /// Type: Type: BOOL /// /// If the message is translated (that is, a character message is posted to the thread's message queue), the return value is nonzero. /// /// /// If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is nonzero, regardless of the translation. /// /// /// 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. /// /// /// /// The TranslateMessage function does not modify the message pointed to by the lpMsg parameter. /// /// WM_KEYDOWN and WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. WM_SYSKEYDOWN and WM_SYSKEYUP combinations produce /// a WM_SYSCHAR or WM_SYSDEADCHAR message. /// /// TranslateMessage produces WM_CHAR messages only for keys that are mapped to ASCII characters by the keyboard driver. /// /// If applications process virtual-key messages for some other purpose, they should not call TranslateMessage. For instance, /// an application should not call TranslateMessage if the TranslateAccelerator function returns a nonzero value. Note that /// the application is responsible for retrieving and dispatching input messages to the dialog box. Most applications use the main /// message loop for this. However, to permit the user to move to and to select controls by using the keyboard, the application must /// call IsDialogMessage. For more information, see Dialog Box Keyboard Interface. /// /// Examples /// For an example, see Creating a Message Loop. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-translatemessage BOOL TranslateMessage( const MSG *lpMsg ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool TranslateMessage(in MSG lpMsg); /// Unpacks a Dynamic Data Exchange (DDE)lParam value received from a posted DDE message. /// /// Type: UINT /// The posted DDE message. /// /// /// Type: LPARAM /// /// The lParam parameter of the posted DDE message that was received. The application must free the memory object specified by the /// lParam parameter by calling the FreeDDElParam function. /// /// /// /// Type: PUINT_PTR /// A pointer to a variable that receives the low-order word of lParam. /// /// /// Type: PUINT_PTR /// A pointer to a variable that receives the high-order word of lParam. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// PackDDElParam eases the porting of 16-bit DDE applications to 32-bit DDE applications. // https://docs.microsoft.com/en-us/windows/desktop/api/dde/nf-dde-unpackddelparam BOOL UnpackDDElParam( UINT msg, LPARAM lParam, // PUINT_PTR puiLo, PUINT_PTR puiHi ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dde.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnpackDDElParam(uint msg, IntPtr lParam, out IntPtr puiLo, out IntPtr puiHi); /// /// Yields control to other threads when a thread has no other messages in its message queue. The WaitMessage function /// suspends the thread and does not return until a new message is placed in the thread's message queue. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// Note that WaitMessage does not return if there is unread input in the message queue after the thread has called a function /// to check the queue. This is because functions such as PeekMessage, GetMessage, GetQueueStatus, WaitMessage, /// MsgWaitForMultipleObjects, and MsgWaitForMultipleObjectsEx check the queue and then change the state information for the queue so /// that the input is no longer considered new. A subsequent call to WaitMessage will not return until new input of the /// specified type arrives. The existing unread input (received prior to the last time the thread checked the queue) is ignored. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-waitmessage BOOL WaitMessage( ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool WaitMessage(); /// Contains information about a window that denied a request from BroadcastSystemMessageEx. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-__unnamed_struct_2 typedef struct { UINT cbSize; HDESK // hdesk; HWND hwnd; LUID luid; } BSMINFO, *PBSMINFO; [PInvokeData("winuser.h")] [StructLayout(LayoutKind.Sequential)] public struct BSMINFO { /// /// Type: UINT /// The size, in bytes, of this structure. /// public uint cbSize; /// /// Type: HDESK /// /// A desktop handle to the window specified by hwnd. This value is returned only if BroadcastSystemMessageEx specifies /// BSF_RETURNHDESK and BSF_QUERY. /// /// public HDESK hdesk; /// /// Type: HWND /// A handle to the window that denied the request. This value is returned if BroadcastSystemMessageEx specifies BSF_QUERY. /// public HWND hwnd; /// /// Type: LUID /// A locally unique identifier (LUID) for the window. /// public uint luid; } } }