
key RETURN to execute a button (NOT to close the Dialog box)
There are a couple things happening here. One is that Enter will
always generate an IDOK. So the trick is not to delete the OnOK
handler, but to have a handler that just does "return". You may have
to do the same for OnCancel if you don't want ESC to close the dialog.
Now you have two choices: you can, instead of making OnOK just return,
do whatever you want the Enter key to do. This is fine if the Enter
key always does the same thing. But if the meaning of the Enter key is
specific to each control, you have to subclass the controls. My own
preference in this case is to have the control send a message to the
parent. The simplest way is to use a user-defined message (I prefer
Registered Window Messages these days), as such:
void CMyEditControl::OnChar(..., UINT uChar, ...)
{
if(uChar == '\r')
{
GetParent()->SendMessage(UWM_SAW_ENTER);
return;
}
CEdit::OnChar(...);
}
Your dialog can then respond to the UWM_SAW_ENTER message and take
whatever action you want. Alternatives to this include sending the
WM_CHAR message to the parent (I tend to avoid this because it can
lead to all sorts of problems; for example, I think in a dialog you
will end up in some confused state as the dialog tries to handle the
WM_CHAR message itself) or sending a WM_COMMAND message up for the
control (it gives you full MFC command routing, but like most attempts
to fake out messages, can cause problems in the future).
joe
On Sun, 02 Aug 1998 05:10:08 -0700, "J.Helmig"
Quote:
>key RETURN to execute a button (NOT to close the Dialog box)
>------------------------------------------------------------
>I work with VC 4.2 on an MFC application.
>I have now a dialog-box, where users have a lot of work
>in an EDIT field. To get more user-speed , I like the ENTER key
>to trigger the procedure on a push-button (update/goto next),
>but instead the Dialog-box closes.
>I deleted already the OK and CANCEL button, but ENTER seems still
>to be running OnOK().
> How can I solve my problem ?
>Thank's for any advise.
>Johannes (medium level MFC experience)
>Brussels/Belgium
Joseph M. Newcomer
http://www3.pgh.net/~newcomer