But maybe a little better than what I was expecting... The "ESC" handle is great but the "RETURN" takes over some events like when a button is pressed(by the keyboard RETURN key)...
If I don't handle the "RETURN"... the application works fine when I'm on a button, but the dialog box will close if I'm on a CListBox for example...
I thought you might still have the problem with the enter key.
The solution to this is:
1. add a variable in your dialog class:
bool bEnterKey;
make sure to initialize it to false.
2. change your PreTranslateMessage to :
BOOL CTestDlgDlg:reTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN){
if( pMsg->wParam == VK_ESCAPE) return true;
else if (pMsg->wParam == VK_RETURN) bEnterKey = true;
}
return CDialog:reTranslateMessage(pMsg);
}
3. overide the IDOK message handler if it is not.
add the code below to it:
... it works great for some forms, but for others, it seems that the ESC or RETURN just don't used these override methods... I have no idea why for now... (I've tested this by putting "cout << "ok" << endl;" in the OnOK override method)
I've put the code that I thought was useful... For this case, the ESC key calls OnCancel(that's ok)... but when I'm on a CTreeCtrl(or any other control that don't use the RETURN key) in my dialog box and I push RETURN... it's the OnClick event of the BtnOk that is call... seems kind of weird.... thanks for the help.
there is a default button setting in your dialog. usually this is your ok button unless you change it to other buttons. when you move the focus to the controls other than buttons, the border of your default button changes to black. Thus when you press the enter key, the message will be mapped to the click envent of your default button.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.