Message Loop:
When the program is ready to
use keyboard and mouse input from user, these inputs comes in the form of
“message”. The window maintains a message queue for each program. When input
event occurs, windows translate the event into message i.e. placed in the
program message queue.
A program retrieves these
messages from the queue by executing a block of code known as the “message
loop”.
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
1.
GetMessage:
The GetMessage call begins the message queue. The second,
third, fourth arguments are set to NULL or 0 to indicate that program wants all
messages from program.
If the message field of the message retrieve from the message
queue as anything except WM_QUIT, GetMessage returns a non-zero value.
2.
TranslateMessage:
TranslateMessage takes responsibility of translating key
stroke message to character message.
3.
DispatchMessage:
DispatchMessage
pass the message structure to WndProc. After the WndProc process the Message,
it returns the control to window. The message loop continue with the next
message call.
0 comments:
Post a Comment