Enter and Esc
-
Hi there, I have a dialog box (derived from CDialog), which contains an edit control. I want to handle the esc and enter keys at the message handler of the edit control, but the esc and enter messages are being translated by accelerators and the whole dialog box closes. How can I make the keys handled by the edit control? Thanks for advice, Alex Don't try it, just do it! ;-)
-
Hi there, I have a dialog box (derived from CDialog), which contains an edit control. I want to handle the esc and enter keys at the message handler of the edit control, but the esc and enter messages are being translated by accelerators and the whole dialog box closes. How can I make the keys handled by the edit control? Thanks for advice, Alex Don't try it, just do it! ;-)
Alexander M. wrote: ...but the esc and enter messages are being translated by accelerators and the whole dialog box closes. See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Hi there, I have a dialog box (derived from CDialog), which contains an edit control. I want to handle the esc and enter keys at the message handler of the edit control, but the esc and enter messages are being translated by accelerators and the whole dialog box closes. How can I make the keys handled by the edit control? Thanks for advice, Alex Don't try it, just do it! ;-)
the best way is to derive a class from CEdit and handle WM_CHAR. there you can do whatever you want in response to VK_RETURN, VK_ESCAPE. also make sure that in your dialog you have handlers for OK and Cancel. In those handlers comment the part with the call of the base class: void CBDlg::OnOK() { // TODO: Add extra validation here //CDialog::OnOK(); } Now your dialog will not exit when you press enter. same for OnCancel.. PS: Stay away from PreTranslate... as it's design is not for this kind of use.
-
the best way is to derive a class from CEdit and handle WM_CHAR. there you can do whatever you want in response to VK_RETURN, VK_ESCAPE. also make sure that in your dialog you have handlers for OK and Cancel. In those handlers comment the part with the call of the base class: void CBDlg::OnOK() { // TODO: Add extra validation here //CDialog::OnOK(); } Now your dialog will not exit when you press enter. same for OnCancel.. PS: Stay away from PreTranslate... as it's design is not for this kind of use.
Yeah the dialog does not exit... but the CEdit does not receive a WM_CHAR message... I've already tried this, but without success. I will check PreTranslateMessage... lets see what is possible... Don't try it, just do it! ;-)
-
Hi there, I have a dialog box (derived from CDialog), which contains an edit control. I want to handle the esc and enter keys at the message handler of the edit control, but the esc and enter messages are being translated by accelerators and the whole dialog box closes. How can I make the keys handled by the edit control? Thanks for advice, Alex Don't try it, just do it! ;-)
What you need to do is handle the WM_ONGETDLGCODE message for your edit control class. This message tells the dialog box procedure what keys to process for your control and which to skip. For example:
UINT CMyEdit:OnGetDlgCode()
{
return( CEdit::OnGetDlgCode() | DLGC_WANTALLKEYS );
}Then process in OnChar as normal.
-
What you need to do is handle the WM_ONGETDLGCODE message for your edit control class. This message tells the dialog box procedure what keys to process for your control and which to skip. For example:
UINT CMyEdit:OnGetDlgCode()
{
return( CEdit::OnGetDlgCode() | DLGC_WANTALLKEYS );
}Then process in OnChar as normal.
Perfect answer, that was exactly what I wanted to know... thank you very much!!! Don't try it, just do it! ;-)