Enable edit control in Dialog access Enter and ESC
-
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
-
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
if your problem is in editbox do you have ES_WANTRETURN in property edit_**
**_
whitesky
-
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
Try WM_GETDLGCODE Regards, FarPointer Blog:http://farpointer.blogspot.com/
-
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
That's why PreTranslateMessage is not a very clean solution. Prefer the solution described in the FAQ[^]. In this way, you still have the complete flow of messages inaltered, it is just the closing of the dialog that is suppressed and you don't need to make tricks to get back your esc and enter messages when you need them.
Cédric Moonen Software developer
Charting control -
if your problem is in editbox do you have ES_WANTRETURN in property edit_**
**_
whitesky
My edit controls are single-line. in fact, what I want is send a message to Parent window, when the focused edits/buttons get Enter/ESC key.
-
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
zeus_master wrote:
if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;
Your logic seems to be wrong. You want the condition to be true right? [modified] By returning true from PreTranslateMessage(...), you are telling your application to bypass any default handling of the message. [modified]
Last modified: Tuesday, June 20, 2006 3:28:49 AM --
-
zeus_master wrote:
if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;
Your logic seems to be wrong. You want the condition to be true right? [modified] By returning true from PreTranslateMessage(...), you are telling your application to bypass any default handling of the message. [modified]
Last modified: Tuesday, June 20, 2006 3:28:49 AM --
GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit)) is for checking current focus on Edit control or not. if it is not on edit control, will return and do nothing,if the focus is on edit control, then do what I want to.... -- modified at 4:35 Tuesday 20th June, 2006 By returning true from PreTranslateMessage(...), you are telling your application to bypass any default handling of the message. yes, or it will close the dialog
-
GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit)) is for checking current focus on Edit control or not. if it is not on edit control, will return and do nothing,if the focus is on edit control, then do what I want to.... -- modified at 4:35 Tuesday 20th June, 2006 By returning true from PreTranslateMessage(...), you are telling your application to bypass any default handling of the message. yes, or it will close the dialog
zeus_master wrote:
GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))
If this return true it means the current focus is in an edit control (could be any edit control). If it return false, it mean focus is not in any edit control.
zeus_master wrote:
f the focus is on edit control, then do what I want to
Then you code should be:
if (GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit)))
{
// do your thing
} -
That's why PreTranslateMessage is not a very clean solution. Prefer the solution described in the FAQ[^]. In this way, you still have the complete flow of messages inaltered, it is just the closing of the dialog that is suppressed and you don't need to make tricks to get back your esc and enter messages when you need them.
Cédric Moonen Software developer
Charting controlthen, how to handle the enter/esc key for Edit control and buttons? And seems that it doesn't enter into the OnChar() at all.
-
then, how to handle the enter/esc key for Edit control and buttons? And seems that it doesn't enter into the OnChar() at all.
zeus_master wrote:
And seems that it doesn't enter into the OnChar() at all.
Then your problem is elsewhere, it has nothing to do with the destruction of the dialog on enter or Esc.
Cédric Moonen Software developer
Charting control -
Surely, the Dialog will close when the Enter and ESC key down. I know reload the PreTranslateMessage(MSG* pMsg) function can avoid the problem. In my project, there are some other controls in the dialog, and I want the Edit controls and buttons can get the Enter/ESC command but not close the Dialog, is there any way? I tried the OnChar(), OnCommad(), there din't work at all. BOOL CEditDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) { if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// pMsg->wParam=NULL ; else { ............... } } } return CDialog::PreTranslateMessage(pMsg); }
I wonder why nobody suggested overriding the "onOk" and "onCancel" functions of the CDialog. :~ , that's the simplest way to get rid of your 'escape' and 'enter'.
--[:jig:]-- [My Current Status]
-
I wonder why nobody suggested overriding the "onOk" and "onCancel" functions of the CDialog. :~ , that's the simplest way to get rid of your 'escape' and 'enter'.
--[:jig:]-- [My Current Status]
thank you for you suggestion, Ceric Moonen suggested me also. now the problem is how do single-line Edit control capture the Enter/Esc key.
-
zeus_master wrote:
And seems that it doesn't enter into the OnChar() at all.
Then your problem is elsewhere, it has nothing to do with the destruction of the dialog on enter or Esc.
Cédric Moonen Software developer
Charting controlyes the code below else is where I need your kindly help. if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// do nothing and ignore the key process else { ............... //add proper code for EDIT control capture the Enter and ESC key. }
-
yes the code below else is where I need your kindly help. if (!GetFocus()->IsKindOf(RUNTIME_CLASS(CEdit))) return true;// do nothing and ignore the key process else { ............... //add proper code for EDIT control capture the Enter and ESC key. }
Why are you doing that in PreTranslateMessage ? I think you can simply add a message handler for WM_CHAR or WM_KEYDOWN for the edit control no ? I'm not sure about that, so you have to check.
Cédric Moonen Software developer
Charting control -
Why are you doing that in PreTranslateMessage ? I think you can simply add a message handler for WM_CHAR or WM_KEYDOWN for the edit control no ? I'm not sure about that, so you have to check.
Cédric Moonen Software developer
Charting controlI tried, and failed...... if there is no better methord,I would have to add the edit proc function in PreTranslateMessage() directly...