Message loop in Microsoft Windows

Message loop in Microsoft Windows

Microsoft Windows programs are event-based. They act upon messages that the operating system posts to the main thread of the application. These messages are received from the message queue 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.

Modern graphical interface frameworks, such as WinForms, Windows Presentation Foundation, MFC, Delphi, Qt et al. do not typically require applications to directly access the Windows message loop, but instead automatically route events such as key presses and mouse clicks to their appropriate handlers as defined within the framework. Underlying these frameworks, however, the message loop can again be found, and can typically be accessed when more direct control is required.


External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Message passing — This article is about the computer science concept. For other uses, see Message passing (disambiguation). Message passing in computer science is a form of communication used in parallel computing, object oriented programming, and interprocess… …   Wikipedia

  • Event loop — In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program. It works by polling some internal or external event… …   Wikipedia

  • Windows 1.0 — Part of the Microsoft Windows family …   Wikipedia

  • Microsoft Excel — Microsoft Office Excel 2010 running on Windows 7 Developer(s) Microsoft Corporat …   Wikipedia

  • Windows Error Reporting — displaying Problem Details from an issue with Windows Explorer Windows Error Reporting (WER) (codenamed Watson) is a crash reporting technology introduced by Microsoft with Windows XP[1 …   Wikipedia

  • Message a l'envers — Message à l envers ██████████ …   Wikipédia en Français

  • Message À L'envers — ██████████ …   Wikipédia en Français

  • Message à l'envers — ██████████ …   Wikipédia en Français

  • Windows Vista networking technologies — This article is part of a series on Windows Vista New features Overview Technical and core system Security and safety Networking technologies I/O technologies Management and administration Removed features …   Wikipedia

  • Microsoft Assembler — Der Microsoft Macro Assembler (abgekürzt MASM) ist ein von Microsoft entwickelter Assembler für x86 basierende Prozessoren. Er übersetzt Assemblerquelltext in ausführbaren, nativen Maschinencode. Der Microsoft Macro Assembler entwickelte sich… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”