-
November 27th, 2003, 01:38 PM
#1
disabling the destroy button
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?
-
November 27th, 2003, 02:42 PM
#2
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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
November 27th, 2003, 03:11 PM
#3
Disabling the close button:
EnableMenuItem (GetSystemMenu(hwnd, FALSE), SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
Good luck
-
November 27th, 2003, 03:16 PM
#4
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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
November 27th, 2003, 03:29 PM
#5
Yes.
If we're talking about MFC he can override the OnCancel method.
But you cannot block all ways to close the window.
Good luck
-
November 27th, 2003, 03:36 PM
#6
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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
November 27th, 2003, 03:45 PM
#7
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)
Good luck
-
November 28th, 2003, 04:24 AM
#8
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|