Click to See Complete Forum and Search --> : CEdit Box Question


ninenblue
June 4th, 2002, 05:38 PM
Hey there!

I just started playing around with VC++ .net and already discovered a problem I can't explain :)
When I create a Dialog-Based Application with only one CEdit Editbox on the Dialog, the compiled Application will close as soon as I press RETURN. How can I prevent/suppress that?
The CEdit property "Want Return" set to "true" does not seem to work here ... any suggestions?
Thanks in advance ... :)

JohnCz
June 6th, 2002, 06:20 PM
This is rather MFC question.

RETURN is automatically translated to WM_COMMAND with ID 0x00000001 – equivalent of pressing OK button. Even if you get rid of the IDOK framework will still supply this message to a dialog and in turn dialog will close.

There is many ways of changing that behavior: deriving own CEdit based class and handle PreTranslateMessage, override PreTranslateMessage in dialog or overriding OnOK virtual member of the CDialog class:


void CDlgReturnFix::OnOK(void)
{
CWnd* pWnd = GetFocus();
if(GetDlgItem(IDOK) == pWnd)
{
CDialog::OnOK();
return;
}
NextDlgCtrl(); //will move focus to next control in tab order
}

djolence
December 27th, 2003, 07:11 AM
You need to set "Default button" option for OK button to FALSE.