MESSAGE Structure
The MESSAGE structure contains message information from a thread's message queue. It is used by functions such as GetMessage, PeekMessage, and MsgWaitForMultipleObjects.
Syntax
typedef struct tagMESSAGE {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MESSAGE, *LPMESSAGE;
Members
| Member | Type | Description |
|---|---|---|
| hwnd | HWND | Handle to the window that receives the message. |
| message | UINT | Message identifier (e.g., WM_PAINT, WM_KEYDOWN). |
| wParam | WPARAM | Additional message information. The content depends on the message value. |
| lParam | LPARAM | Additional message information. The content depends on the message value. |
| time | DWORD | Timestamp when the message was posted. |
| pt | POINT | Cursor position, in screen coordinates, when the message entry was retrieved. |
Example
#include <windows.h>
#include <stdio.h>
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR pCmdLine, int nCmdShow)
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
// Convert MSG to MESSAGE for illustration
MESSAGE m;
m.hwnd = msg.hwnd;
m.message = msg.message;
m.wParam = msg.wParam;
m.lParam = msg.lParam;
m.time = msg.time;
m.pt = msg.pt;
// Log the message details
wprintf(L"Message: %04X, hwnd: %p, wParam: %p, lParam: %p, time: %lu, pt: (%ld,%ld)\\n",
m.message, m.hwnd, (void*)m.wParam, (void*)m.lParam,
m.time, m.pt.x, m.pt.y);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}