Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Enable edit control in Dialog access Enter and ESC

Enable edit control in Dialog access Enter and ESC

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
15 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeus_master
    wrote on last edited by
    #1

    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); }

    H F C W E 5 Replies Last reply
    0
    • Z zeus_master

      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); }

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      if your problem is in editbox do you have ES_WANTRETURN in property edit_**


      **_

      whitesky


      Z 1 Reply Last reply
      0
      • Z zeus_master

        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); }

        F Offline
        F Offline
        FarPointer
        wrote on last edited by
        #3

        Try WM_GETDLGCODE Regards, FarPointer Blog:http://farpointer.blogspot.com/

        1 Reply Last reply
        0
        • Z zeus_master

          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); }

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          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

          Z 1 Reply Last reply
          0
          • H Hamid Taebi

            if your problem is in editbox do you have ES_WANTRETURN in property edit_**


            **_

            whitesky


            Z Offline
            Z Offline
            zeus_master
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • Z zeus_master

              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); }

              W Offline
              W Offline
              Weiye Chen
              wrote on last edited by
              #6

              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 --

              Z 1 Reply Last reply
              0
              • W Weiye Chen

                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 --

                Z Offline
                Z Offline
                zeus_master
                wrote on last edited by
                #7

                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

                W 1 Reply Last reply
                0
                • Z zeus_master

                  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

                  W Offline
                  W Offline
                  Weiye Chen
                  wrote on last edited by
                  #8

                  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
                  }

                  1 Reply Last reply
                  0
                  • C Cedric Moonen

                    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

                    Z Offline
                    Z Offline
                    zeus_master
                    wrote on last edited by
                    #9

                    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.

                    C 1 Reply Last reply
                    0
                    • Z zeus_master

                      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.

                      C Offline
                      C Offline
                      Cedric Moonen
                      wrote on last edited by
                      #10

                      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

                      Z 1 Reply Last reply
                      0
                      • Z zeus_master

                        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); }

                        E Offline
                        E Offline
                        Eytukan
                        wrote on last edited by
                        #11

                        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]

                        Z 1 Reply Last reply
                        0
                        • E Eytukan

                          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]

                          Z Offline
                          Z Offline
                          zeus_master
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • C Cedric Moonen

                            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

                            Z Offline
                            Z Offline
                            zeus_master
                            wrote on last edited by
                            #13

                            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. }

                            C 1 Reply Last reply
                            0
                            • Z zeus_master

                              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. }

                              C Offline
                              C Offline
                              Cedric Moonen
                              wrote on last edited by
                              #14

                              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

                              Z 1 Reply Last reply
                              0
                              • C Cedric Moonen

                                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

                                Z Offline
                                Z Offline
                                zeus_master
                                wrote on last edited by
                                #15

                                I tried, and failed...... if there is no better methord,I would have to add the edit proc function in PreTranslateMessage() directly...

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups