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 +