One-day training of Windows APIs (15) postquitmessage Function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.