Click to See Complete Forum and Search --> : Pressing ESC causes Dialog to be hidden
Sophie
May 3rd, 1999, 02:07 PM
Hi,
I have a dialog which is of STYLE : CHILD and BORDER : THIN.
I've inserted into a tab control. My problem is that if I press ESC or Enter my dialog gets hidden. I need to over ride the ONCANCEL & ONOK but I have no clue how. These are no longer command buttons in my dialogs.
Hope you can help me
Michael Decker
May 3rd, 1999, 02:18 PM
ESC is the same thing as hitting the Cancel button (if you had a Cancel button).
As a guess, try selecting the "Control" property under the "More Styles" tab.
Let me know.
Thanks,
Michael...
Ramkumar Ganesan
May 3rd, 1999, 02:24 PM
You can try to see if the DS_CONTROL style is available in the 'More Styles' tab as suggested.. This is available in 32-bit but not in 16-bit. But I guess that may not help to solve this problem. In either case, u need to handle OK and CANCEL buttons. Whether u have these buttons on Ur dialog or not, it does not matter. They are the default ones Windows looks for and all u need to do is to handle them. Let me know how this works.
Regards
Ram
Sophie
May 3rd, 1999, 02:24 PM
Thanks but that didn't solve the problem. I need to be able to override the OnCancel and OnOk. What does the OnCommand do?
Help!
Thank you
Sophie
May 3rd, 1999, 02:37 PM
Thank You that worked.
Troy T
May 3rd, 1999, 05:15 PM
Since it's not exactly clear what's going on here, I'm going to guess that the problem Sophie is having is that when she presses ENTER, or ESC the dialog closes (which is normal unless these keys are overridden in the PreTranslateMessage virtual function).
Here's what to do. Open up the dialog that you're working on in design mode (where you can add a button, etc.) then press "CTRL + W" to get to the ClassWizard, (or go to View|ClassWizard), once inside the class wizard, make sure that the name of your dialog class is showing, and on the left side, choose the name of the dialog class you are working with (ex. "MyDialog"), then on the right side, scroll down until you find "PreTranslateMessage", and then select that. Then choose the "Add Function" button, and it will add it. Then choose "edit", and it will take you to that section of code where it added the function. In that function, you need to add the following code to disable the enter key, and the ESC keys:
if( pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ENTER || pMsg->wParam == VK_ESC) )
return TRUE;
The above code handles both the ENTER key, and the ESC key. It basically states that if the system received a WM_KEYDOWN message, and it was because of the ENTER key, or the ESC key, we're going to do nothing (disable) them.
As I said, I'm not sure of the exact problem, but I think that this is what the solution will be for that problem that Sophie is describing. It sounds like you have the OnOK and OnCancel overridden already. If not, I can help you with that, too..
Good luck!
- Troy
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.