DispatchMessage function

Syntax


LRESULT DispatchMessage(
    const MSG *lpmsg
);
        

Parameters

lpmsg Pointer to an MSG structure that contains the message to be dispatched.

Return value

Returns the value returned by the window procedure that processes the message. If an error occurs, the return value is zero. Call GetLastError for extended error information.

Remarks

The DispatchMessage function sends a message to a window procedure. It is typically called after retrieving a message with GetMessage or PeekMessage. The function does not perform any checks on the validity of the message; the caller must ensure that the message is appropriate for dispatch.

Example


// Simple message loop using DispatchMessage
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
return (int)msg.wParam;

// Window procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        // handle other messages...
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}
        

See also