In the natural interface, various creatures have their lifecycles. Program It also has its own life cycle. When it was created, it was born. When it was running for a period of time, and ultimately it was about to die, how did the death of the program happen? As previously introduced, The getmessage function uses a loop to continuously detect messages. It is impossible to die after weeks and repetition, but it will detect that the message wm_quit will exit. Now the question is, who sent the wm_quit message? This is what the postquitmessage function does. When you click Close in the upper-right corner of the window, Windows will delete the window from the system, and then a message wm_destroy will be sent to window message processing function windowproc. After windowproc receives this message, the most important thing to do is to call postquitmessage to send an Exit message and end the message loop.
The postquitmessage function is declared as follows:
Winuserapi
Void
Winapi
Postquitmessage (
_ In int nexitcode );
Nexitcode is the exit identifier code, which is put in the wparam parameter of the wm_quit message.
An example of calling this function is as follows:
#001 //
#002 // purpose: to process messages in the main window.
#003 //
#004 // Cai junsheng 2007/07/12 QQ: 9073204
#005 //
#006 lresult callback wndproc (hwnd, uint message, wparam, lparam)
#007 {
#008 int wmid, wmevent;
#009 paintstruct pS;
#010 HDC;
#011
#012 switch (Message)
#013 {
#014 case wm_command:
#015 wmid = loword (wparam );
#016 wmevent = hiword (wparam );
#017 // menu option command response:
#018 switch (wmid)
#019 {
#020 case idm_about:
#021 dialogbox (hinst, makeintresource (idd_aboutbox), hwnd, about );
#022 break;
#023 case idm_exit:
#024 destroywindow (hwnd );
#025 break;
#026 default:
#027 return defwindowproc (hwnd, message, wparam, lparam );
#028}
#029 break;
#030 case wm_paint:
#031 HDC = beginpaint (hwnd, & PS );
#032 //
#033 endpaint (hwnd, & PS );
#034 break;
#035 case wm_destroy:
#036 postquitmessage (0 );
#037 break;
#038 default:
#039 return defwindowproc (hwnd, message, wparam, lparam );
#040}
#041 return 0;
#042}
Row 3 calls the postquitmessage function to process and exit the application.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/07/25/1706634.aspx
If (Msg. Message = Wm_quit)
{
Postmessage (g_hwnd, wm_close, 0 , 0 );
Break ;
}
Wm_destroy->Wm_quit-> Wm_close