Suppress dialog box Close button and ALT +

Source: Internet
Author: User

In some cases we need to prevent the user from clicking the Close button in the title bar of the window to close the MFC application.

You can delete the Ws_sysmenu style of the window, but the maximize minimize and restore buttons are also deleted and cannot be added. This is the design basis for Windows.

You can simulate a window without a close button by disabling the Close button. Disables the Close button in the WM_CREATE message handler. Use the following code:

CMenu *psysmenu = GetSystemMenu (FALSE); ASSERT (Psysmenu! = NULL); VERIFY (Psysmenu->removemenu (Sc_close, Mf_bycommand));

When this is removed, the close button turns gray and the user cannot click. However, you can still close the program using ALT+F4. The OnSysCommand method that requires overloading CDialog is also disabled for this feature. The code is as follows:

voidMydlg::onsyscommand (UINT NID, LPARAM LPARAM) {if(NID &0xfff0) ==Idm_aboutbox)
{CAboutDlg dlgabout;//if you have a about dialog      Dlgabout.domodal (); }//Add the following code    Else if(NID &0xfff0) ==sc_close)
{//if user clicked the "X"      OnExit (); //---End of code you have added    }Else
  {Cdialog::onsyscommand (NID, LParam); }}

Suppress dialog box Close button and ALT +

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.