Traditional Application Loop Example

Top  Previous  Next

Every Windows program consists of an application event loop.  Events such as mouse messages, keyboard messages, timer notifications, etc. are passed through the application's event loop.  If you are familiar with  Windows programming using the 'C'  language, almost every program has the following construct or something similar for starting the application's message loop:

 

MSG msg;

...

while (GetMessage(&msg, NULL, 0, 0)) {

   TranslateMessage(&msg);

   DispatchMessage(&msg);

}

 

Note that the example above is as simple as possible:  there are no calls to Windows API functions such as IsDialogMessage or TranslateAccelerator.

 

There are also many variations of the 'background' processing loops that use a combination of PeekMessage and GetMessage that generally accomplish the same thing as the above example code.