Disabling the "X" button

I would like to know how to disable the "X" button in the upper right corner of a Windows application.
I want the user to be able to exit only using the pull-down menu option File->Exit.

Thanks.
hornAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mikeblasConnect With a Mentor Commented:
That you need to do this suggests there's something wrong with the design of your app--why don't you execut the same code in response to WM_CLOSE and WM_COMMAND(ID_FILE_EXIT)?

Anyway, you can just get the system menu and disable the SC_CLOSE command to make the close command and the non-client button both disabled:

   CMenu* pMenu = GetSystemMenu(FALSE);
   pMenu->EnableMenuItem(SC_CLOSE, MF_DISABLED | MF_GRAYED);

B ekiM

0
 
VEngineerCommented:
If you just simply want to get rid of the 'X' button, you can go into the dialog box properties, styles, and then uncheck "system menu"
This will can the 'X' but it will also can the button in the upper left too.  So all you have is a title bar with the title text.  Menu will still work fine.

0
 
VEngineerCommented:
I'm not sure which solution you are looking for, but if my solution works, please give me some points.. I am running low.
0
 
mikeblasCommented:
Horn asked about disabling the button, not getting rid of it entirely. If you need points, you should answer the question that was asked correctly (like I did), not answer a question you made up yourself.

B ekiM
0
 
hornAuthor Commented:
I am sorry but to be fair, the points have to go to the first one to answer correctly.
Thanks B ekiM.


0
All Courses

From novice to tech pro — start learning today.