tags:

views:

128

answers:

2

Hi!

I have an MFC application, which i don't want to be closed during the running. I have disabled the "X" icon in the right upper corner, but now if i press the ESC key, or ALT+F4 it still closes.

How can i disable this, so it won't close, if someone press those keys? After the program has finished running i want to reenable them.

Thanks,
kampi

+3  A: 

Can't say for Esc key, but as far as Alt+F4 goes, it sends Close command to the main window. You basically need to override OnClose event and keep it empty (not call base method). That should do the trick.

P.S. Since I haven't touched MFC in many years, it may not be 100% true. Just how I remember it.

Developer Art
Sounds about right for MFC.
AshleysBrain
+5  A: 

If you handle the WM_CLOSE message and throw it away. (i.e. Don't call DefWindowProc), then the window won't close.

You could also register the window class with the CS_NOCLOSE style, to disable all of the normal ways of closing the window.

John Knoeller
Thank you! This worked for me.
kampi