DispatchMessage

The DispatchMessage function dispatches a message to the appropriate window procedure (typically by calling the DefWindowProc function).

LRESULT DispatchMessage(
  const MSG *lpmsg
);

Parameters

Parameter Type and Description
lpmsg const MSG *
A pointer to a MSG structure that contains information about the message.

Return Value

The return value is the result of the message processing and depends on the message being dispatched. If the message is processed by the system, the return value is typically ignored.

Remarks

The DispatchMessage function removes the message from the application's message queue and calls the appropriate window procedure to process the message. Typically, an application calls GetMessage to retrieve a message from the queue, and then calls DispatchMessage to send the message to the window procedure.

DispatchMessage is part of the core message loop mechanism in Windows applications. It ensures that messages are delivered to the correct window and processed accordingly.

The message loop structure usually looks like this:

MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
}