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. how can I respond Enter Event in a editbox?

how can I respond Enter Event in a editbox?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 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.
  • A Offline
    A Offline
    Angel Kid
    wrote on last edited by
    #1

    a:((how can I respond Enter Event in a editbox? I have a editbox,and I want to make it do sth. like this: when the Enter key was press,other controls in the dialog can get the value in it,then the editbox clean up the value,nd wait the next input. how can I make this ? Anyone can give me a clear answer?Thanks. YES, I am here.

    V M PJ ArendsP 3 Replies Last reply
    0
    • A Angel Kid

      a:((how can I respond Enter Event in a editbox? I have a editbox,and I want to make it do sth. like this: when the Enter key was press,other controls in the dialog can get the value in it,then the editbox clean up the value,nd wait the next input. how can I make this ? Anyone can give me a clear answer?Thanks. YES, I am here.

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Here is one solution. -create editbox -add a button -set button as default button -when the user presses Enter, the button is press -now you can do whatever you want including clear editbox Kuphryn

      A 1 Reply Last reply
      0
      • V valikac

        Here is one solution. -create editbox -add a button -set button as default button -when the user presses Enter, the button is press -now you can do whatever you want including clear editbox Kuphryn

        A Offline
        A Offline
        Angel Kid
        wrote on last edited by
        #3

        I know this solution,but that's it,I don't want to add a button.I just want to respond the Enter Key.so... YES, I am here.

        P 1 Reply Last reply
        0
        • A Angel Kid

          a:((how can I respond Enter Event in a editbox? I have a editbox,and I want to make it do sth. like this: when the Enter key was press,other controls in the dialog can get the value in it,then the editbox clean up the value,nd wait the next input. how can I make this ? Anyone can give me a clear answer?Thanks. YES, I am here.

          M Offline
          M Offline
          Masaaki Onishi
          wrote on last edited by
          #4

          Hello, the codegurus around the world.;) This is one of the famous questions in MFC. If you push Enter key, the dialog will be closed. One solution is that you can trap Enter key message by PreTranslateMessage before Enter Key message sends to the dialog. And you can check if EditBox actually get the input focus in PreTranslateMessage. Also, Paul Deliacia(?) posts his article in this question in MSDN magazine. Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

          -Masaaki Onishi-

          1 Reply Last reply
          0
          • A Angel Kid

            I know this solution,but that's it,I don't want to add a button.I just want to respond the Enter Key.so... YES, I am here.

            P Offline
            P Offline
            Pavel Klocek
            wrote on last edited by
            #5

            You can derive your own edit control from CEdit and overide handling of keyboard messages. Then You can send a custom notification message to the parent window (dialog, form). See the edit control section here at CP for inspiration. Sonork 100.15206;PavelK

            1 Reply Last reply
            0
            • A Angel Kid

              a:((how can I respond Enter Event in a editbox? I have a editbox,and I want to make it do sth. like this: when the Enter key was press,other controls in the dialog can get the value in it,then the editbox clean up the value,nd wait the next input. how can I make this ? Anyone can give me a clear answer?Thanks. YES, I am here.

              PJ ArendsP Offline
              PJ ArendsP Offline
              PJ Arends
              wrote on last edited by
              #6

              I always do stuff like that in my OnOK() function.

              void CMyDialog::OnOK
              {
              if (GetFocus() == c_MyEditControl)
              {
              // do the stuff needed when the enter key is pressed
              // when my edit control has the focus
              }
              else
              // call base class for default handling
              CDialog::OnOK();
              }


              CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

              Within you lies the power for good; Use it!

              J 1 Reply Last reply
              0
              • PJ ArendsP PJ Arends

                I always do stuff like that in my OnOK() function.

                void CMyDialog::OnOK
                {
                if (GetFocus() == c_MyEditControl)
                {
                // do the stuff needed when the enter key is pressed
                // when my edit control has the focus
                }
                else
                // call base class for default handling
                CDialog::OnOK();
                }


                CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

                J Offline
                J Offline
                JohnnyG
                wrote on last edited by
                #7

                That's a neat tip! :-D

                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