tangxu
2024-12-29 72e75456f8b30ec5b6f355539d9c883b0f810d21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
// THIS FILE IS PART OF Vanara PROJECT
// THE Vanara PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
// COPYRIGHT (C) dahall. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/dahall/Vanara
 
using System;
using System.Runtime.InteropServices;
using System.Text;
 
namespace Vanara.PInvoke
{
    public static partial class User32
    {
        /// <summary>
        /// <para>Retrieves the cursor position for the last message retrieved by the GetMessage function.</para>
        /// <para>To determine the current position of the cursor, use the GetCursorPos function.</para>
        /// </summary>
        /// <returns>
        /// <para>Type: <c>Type: <c>DWORD</c></c></para>
        /// <para>
        /// The return value specifies the x- and y-coordinates of the cursor position. The x-coordinate is the low order <c>short</c> and
        /// the y-coordinate is the high-order <c>short</c>.
        /// </para>
        /// </returns>
        /// <remarks>
        /// <para>
        /// As noted above, the x-coordinate is in the low-order <c>short</c> of the return value; the y-coordinate is in the high-order
        /// <c>short</c> (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.
        /// </para>
        /// <para>
        /// <c>Important</c> 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 <c>LOWORD</c> and <c>HIWORD</c> treat the coordinates as unsigned quantities.
        /// </para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmessagepos DWORD GetMessagePos( );
        [DllImport("user32.dll", SetLastError = false, ExactSpelling = true)]
        [PInvokeData("winuser.h")]
        public static extern uint GetMessagePos();
 
        /// <summary>
        /// <para>
        /// 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.
        /// </para>
        /// <para>To post a message in the message queue associated with a thread, use the PostThreadMessage function.</para>
        /// </summary>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>A handle to the window whose window procedure is to receive the message. The following values have special meanings.</para>
        /// <list type="table">
        /// <listheader>
        /// <term>Value</term>
        /// <term>Meaning</term>
        /// </listheader>
        /// <item>
        /// <term>HWND_BROADCAST ((HWND)0xffff)</term>
        /// <term>
        /// 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.
        /// </term>
        /// </item>
        /// <item>
        /// <term>NULL</term>
        /// <term>
        /// The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread.
        /// </term>
        /// </item>
        /// </list>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="Msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be posted.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>Type: <c>BOOL</c></c></para>
        /// <para>If the function succeeds, the return value is nonzero.</para>
        /// <para>
        /// If the function fails, the return value is zero. To get extended error information, call GetLastError. <c>GetLastError</c>
        /// returns <c>ERROR_NOT_ENOUGH_QUOTA</c> when the limit is hit.
        /// </para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>Messages in a message queue are retrieved by calls to the GetMessage or PeekMessage function.</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshaling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshaling.
        /// </para>
        /// <para>
        /// If you send a message in the range below WM_USER to the asynchronous message functions ( <c>PostMessage</c>, 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.
        /// </para>
        /// <para>Do not post the WM_QUIT message using <c>PostMessage</c>; use the PostQuitMessage function.</para>
        /// <para>
        /// An accessibility application can use <c>PostMessage</c> to post WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para><c>HKEY_LOCAL_MACHINE</c><c>SOFTWARE</c><c>Microsoft</c><c>Windows NT</c><c>CurrentVersion</c><c>Windows</c><c>USERPostMessageLimit</c></para>
        /// <para>The minimum acceptable value is 4000.</para>
        /// <para>Examples</para>
        /// <para>
        /// The following example shows how to post a private window message using the <c>PostMessage</c> function. Assume you defined a
        /// private window message called <c>WM_COMPLETE</c>:
        /// </para>
        /// <para>You can post a message to the message queue associated with the thread that created the specified window as shown below:</para>
        /// <para>For more examples, see Initiating a Data Link.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postmessagea BOOL PostMessageA( HWND hWnd, UINT Msg,
        // WPARAM wParam, LPARAM lParam );
        [DllImport("user32.dll", 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);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        [DllImport("user32.dll", 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);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        [System.Security.SecurityCritical]
        public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In, Optional] IntPtr wParam, string lParam);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        [System.Security.SecurityCritical]
        public static extern IntPtr SendMessage(HWND hWnd, uint msg, ref int wParam, [In, Out] StringBuilder lParam);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        [DllImport("user32.dll", 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);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <typeparam name="TMsg">The type of the message. This can be any type that converts to <see cref="uint"/>.</typeparam>
        /// <param name="hWnd"><para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para></param>
        /// <param name="msg"><para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para></param>
        /// <param name="wParam"><para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para></param>
        /// <param name="lParam"><para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para></param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        public static IntPtr SendMessage<TMsg>(HWND hWnd, TMsg msg, [Optional] IntPtr wParam, [Optional] IntPtr lParam)
            where TMsg : struct, IConvertible
            => SendMessage(hWnd, Convert.ToUInt32(msg), IntPtr.Zero, IntPtr.Zero);
 
        /// <summary>
        /// <para>
        /// Sends the specified message to a window or windows. The <c>SendMessage</c> function calls the window procedure for the specified
        /// window and does not return until the window procedure has processed the message.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <typeparam name="TMsg">The type of the message. This can be any type that converts to <see cref="uint"/>.</typeparam>
        /// <typeparam name="TWP">The type of the <paramref name="wParam"/> parameter. This can be any type that converts to <see cref="long" />.</typeparam>
        /// <param name="hWnd">
        /// <para>Type: <c>HWND</c></para>
        /// <para>
        /// A handle to the window whose window procedure will receive the message. If this parameter is <c>HWND_BROADCAST</c>
        /// ((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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </param>
        /// <param name="msg">
        /// <para>Type: <c>UINT</c></para>
        /// <para>The message to be sent.</para>
        /// <para>For lists of the system-provided messages, see System-Defined Messages.</para>
        /// </param>
        /// <param name="wParam">
        /// <para>Type: <c>WPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <param name="lParam">
        /// <para>Type: <c>LPARAM</c></para>
        /// <para>Additional message-specific information.</para>
        /// </param>
        /// <returns>
        /// <para>Type: <c>LRESULT</c></para>
        /// <para>The return value specifies the result of the message processing; it depends on the message sent.</para>
        /// </returns>
        /// <remarks>
        /// <para>When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).</para>
        /// <para>
        /// Applications that need to communicate using <c>HWND_BROADCAST</c> should use the RegisterWindowMessage function to obtain a
        /// unique message for inter-application communication.
        /// </para>
        /// <para>
        /// The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those &gt;=
        /// <c>WM_USER</c>) to another process, you must do custom marshalling.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// An accessibility application can use <c>SendMessage</c> to send WM_APPCOMMAND messages to the shell to launch applications. This
        /// functionality is not guaranteed to work for other types of applications.
        /// </para>
        /// <para>Examples</para>
        /// <para>For an example, see Displaying Keyboard Input.</para>
        /// </remarks>
        // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage
        [PInvokeData("winuser.h", MSDNShortId = "NF:winuser.SendMessage")]
        public static IntPtr SendMessage<TMsg, TWP>(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);
    }
}