Message loop in Microsoft Windows
From Wikipedia, the free encyclopedia
Microsoft Windows programs are event-based. They act upon messages that the operating system posts to the main application thread. These messages are received by the application by repeatedly calling the GetMessage (or PeekMessage) function in a section of code called the "event loop." The event loop typically appears as follows:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
Though not strictly required, it's conventional for the event loop to call TranslateMessage and DispatchMessage, which transfers the message to the callback procedure associated with the window the message refers to.
While this code has been antiquated by modern frameworks accompanying high-level languages, similar code exists in their foundation to support the message processing that must occur.