diff --git a/PInvoke/User32/WinUser.Message.cs b/PInvoke/User32/WinUser.Message.cs index 27e3b0d3..1bab9628 100644 --- a/PInvoke/User32/WinUser.Message.cs +++ b/PInvoke/User32/WinUser.Message.cs @@ -1705,6 +1705,167 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PeekMessage(out MSG lpMsg, [Optional] HWND hWnd, [Optional] uint wMsgFilterMin, [Optional] uint wMsgFilterMax, [Optional] PM wRemoveMsg); + /// + /// Dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist). + /// + /// The type of and . + /// + /// 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 ); + [PInvokeData("winuser.h")] + public static bool PeekMessage(out MSG lpMsg, [Optional] HWND hWnd, TMsg wMsgFilterMin, TMsg wMsgFilterMax, [Optional] PM wRemoveMsg) where TMsg : struct, IConvertible => + PeekMessage(out lpMsg, hWnd, Convert.ToUInt32(wMsgFilterMin), Convert.ToUInt32(wMsgFilterMax), wRemoveMsg); + /// /// /// Places (posts) a message in the message queue associated with the thread that created the specified window and returns without @@ -1803,6 +1964,103 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PostMessage([Optional] HWND hWnd, uint Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam); + /// + /// + /// 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 ); + [PInvokeData("winuser.h")] + public static bool PostMessage([Optional] HWND hWnd, TMsg Msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam) where TMsg : struct, IConvertible => + PostMessage(hWnd, Convert.ToUInt32(Msg), wParam, 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. ///