Re: Pressing Enter in Dialog
Your problem relates to the default button. When you press enter, MFC routes the enter key as a click on the default button (which is by default the OK button, ID of IDOK) and your dialog boxes OnOK() function gets called.
You can get around this by overriding the default OnOK() and make sure it doesn't call the CDialog::OnOK() function (which closes the dialog box). Then when you do need to close the dialog box, you can have your own OK button that calls the CDialog::OnOK() function as required.
Roger Allen
Re: Pressing Enter in Dialog
I have a similar problem- maybe you can help.
I have a dialog with a default button. Return key does not call the OnOK. Is there another flag to set to enable that processing? The dialog is modal with a list box, password field, and OK, and Cancel buttons.
Dave
Re: Pressing Enter in Dialog
From what I remember, if you have a default button set, which is not the OK button, then pressing enter will cause windows to assume a press of that button. If you need to route it through the OK button, you will either have to make the OK button your default button, or you will have to override the PreTranslateMessage for you dialog box and trap the ENTER key to do the processing you require at the right time. Example code is:
BOOL CDialogClass::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
TRACE("%d %d\n", pMsg->wParam, pMsg->lParam) ;
switch (pMsg->wParam)
{
case VK_ENTER : // enter
// do you processing fro special occurance here
// return true if you dealt with the message
return true ;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
HTH
Roger Allen