In Windows, each thread corresponds to a message queue, which is automatically created by the system. Therefore, if you want Program To respond to the mouse and keyboard operation, you need to obtain the message from the message queue and then make the corresponding response function based on the message. The general practice is to write a message loop, which constantly extracts and processes messages from the message queue until the program exits. The example provided by msdn is as follows:
While (Bret = getmessage (& MSG, null, 0, 0 ))! = 0)
{
If (Bret =-1)
{
// Handle the error and possibly exit
}
Else
{
If (hwnddlgmodeless = (hwnd) null |
! Isdialogmessage (hwnddlgmodeless, & MSG )&&
! Translateaccelerator (hwndmain, haccel,
& MSG ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
}
}
getmessage is used to obtain a message from the message queue. Its prototype is as follows
getmessage (lpmsg lpmsg , hwnd hwnd , uint wmsgfiltermin , uint wmsgfiltermax)