Can you explain message routing and message loop ?

October 28, 2007 · Filed Under Placement Questions, VC++ Interview Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

When a window is visible on the screen it undergoes various stages such as CreateWindow, ShowWindow, etc. Once the window is displayed on the screen it must now make itself ready to take keyboard and mouse input from the user. Windows maintains a message queue for each windows program currently running under windows. When an input occurs, the OS translates this event into a message that it places into the windows message queue. A program receives messages from the message queue by executing a block of code known as the message loop.

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

The GetMessage call passes to windows a pointer to the message and these fields of the message are filled by windows.

The TranslateMessage call passes the msg structure back to windows for some keyboard translation.
The DispatchMessage call passes the message to windows which sends the message to appropriate windows procedure for processing the message. So this means that windows call the window procedure

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email