DispatchMessageA function

LRESULT DispatchMessageA(const MSG *lpmsg);

The DispatchMessageA function dispatches a message to the appropriate window procedure (typically by calling the SendMessage or PostMessage function).

Syntax


BOOL DispatchMessageA(
const MSG *lpmsg
);

Parameters

Parameter Description
lpmsg

A pointer to a MSG structure that contains the message to be dispatched. The MSG structure must contain the handle of the window that will receive the message. If this parameter is NULL, the function behaves as if it received a message with a handle of NULL.

Return value

If the message is processed, the return value is the value returned by the window procedure. If the message is not processed, the return value is 0.

Remarks

The DispatchMessageA function retrieves the message from the thread's message queue and sends it to the appropriate window procedure. The application uses this function in its message loop to process messages.

If the message is a WM_QUIT message, DispatchMessageA retrieves the exit parameter passed in the MSG structure.

The system forwards messages to the appropriate thread for processing.

Requirements

Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Header winuser.h
Library user32.lib
DLL user32.dll

See also

GetMessageA
PeekMessageA
TranslateAcceleratorA
TranslateMessage
Window Procedures

Example Usage

The following code snippet demonstrates a typical message loop:


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}