Hi,
I have a modeless dialog. While it is opened I want to prevent the user from being able to close the calling application using the destroy button.
How do I do that?
Printable View
Hi,
I have a modeless dialog. While it is opened I want to prevent the user from being able to close the calling application using the destroy button.
How do I do that?
You could handle the WM_CLOSE message (handles the small X on the top right of the title bar).
In that handler, check if the modeless dialog exists, and if so, do nothing, otherwise allow the close to happen.
A side benefit is that this also handles the ALT-F4 or even the end application from the task manager!
Good luck.
Disabling the close button:
EnableMenuItem (GetSystemMenu(hwnd, FALSE), SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
One disadvantage of using the EnableMenuItem is that this won't stop closing the app from the ALT-F4 or the task manager.
Additionally, by overriding the WM_CLOSE (OnClose) message, you can display a dialog telling the user why he can't close or anything else you want.
Yes.
If we're talking about MFC he can override the OnCancel method.
:) But you cannot block all ways to close the window.
I'm not referring to the OnCancel message - that only handles the button and the escape key.
If you override the WM_CLOSE message, that traps the X in the title bar, exit from the system menu, ALT--F4, and the end task from the task manager.
I don't know, just never cheked it, so you say that the task manager sends WM_CLOSE to applications?
Okay. From my point of view that's good way. I even cannot believe. :)
I know about SC_CLOSE because it looks strange when the close button is enabled but doesn't work. Sometimes the application cannot be closed for some reason and no message box cannot be shown (when you're drawing something huge, for example)
Thanks alot for you solutions. I think the WM_CLOSE is the solution. I had done it in DestroyWindow but this wasn't such a good idea...