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. MFC related problem

MFC related problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
11 Posts 5 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.
  • D ddspliting

    hey all! i am an amateur in VC++! i ve got a problem and that is by pressing Enter Key of keyboard, my program shuts down as i guess its by default! Now my program uses a text box and what i want is is when i write something and press Enter! the Enter key activate an Event Handler! or a specified function say displaying the text what is written in the text box in other list box etc! plzz anyone who can help in this regard! also is there any way to creat my own event handler???? Like for Enter key? as there is one for helpinfo with WM_HELPINFO which activates if F1 is pressed! I ll be grateful if anyone lead me to the solution! whats wrong wit'cha?

    A Offline
    A Offline
    Ali Rafiee
    wrote on last edited by
    #2

    In a Dialog box the enter key causes the OnOK method to get called. There are a couple of ways you can do this, you can do your processing in OnOK but not call CDialog::OnOK, and to make the OK button work again, you will need to add an event handler for the ok button and in there call CDialog::OnOK. Or you can catch the WM_KEYDOWN message for the VK_ENTER key in PreTranslateMessage and do your processing there, but don't call CDialog::PreTranslateMessage when the enter key is pressed.

    AliR. Visual C++ MVP

    D 1 Reply Last reply
    0
    • D ddspliting

      hey all! i am an amateur in VC++! i ve got a problem and that is by pressing Enter Key of keyboard, my program shuts down as i guess its by default! Now my program uses a text box and what i want is is when i write something and press Enter! the Enter key activate an Event Handler! or a specified function say displaying the text what is written in the text box in other list box etc! plzz anyone who can help in this regard! also is there any way to creat my own event handler???? Like for Enter key? as there is one for helpinfo with WM_HELPINFO which activates if F1 is pressed! I ll be grateful if anyone lead me to the solution! whats wrong wit'cha?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #3

      ddspliting wrote:

      I ll be grateful if anyone lead me to the solution!

      See here and here.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      D 1 Reply Last reply
      0
      • A Ali Rafiee

        In a Dialog box the enter key causes the OnOK method to get called. There are a couple of ways you can do this, you can do your processing in OnOK but not call CDialog::OnOK, and to make the OK button work again, you will need to add an event handler for the ok button and in there call CDialog::OnOK. Or you can catch the WM_KEYDOWN message for the VK_ENTER key in PreTranslateMessage and do your processing there, but don't call CDialog::PreTranslateMessage when the enter key is pressed.

        AliR. Visual C++ MVP

        D Offline
        D Offline
        ddspliting
        wrote on last edited by
        #4

        well i didn get ya ! wat i wanna do is to use tht Enter key for activating any of my desired button! Like say a button Send! if i write something in the text box and press Enter! it works if i ve CLICKED Send! i ll be grateful if u clearify it a bit!

        1 Reply Last reply
        0
        • D David Crow

          ddspliting wrote:

          I ll be grateful if anyone lead me to the solution!

          See here and here.


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          D Offline
          D Offline
          ddspliting
          wrote on last edited by
          #5

          well thnxx david! but see this! switch (nChar) { case VK_RETURN: OnBsend(); } so if VK_RETURN is the case then call OnBsend() function! am i right? but if now i press Enter ! then still the program closes!!? please reflect light on tht

          D 1 Reply Last reply
          0
          • D ddspliting

            well thnxx david! but see this! switch (nChar) { case VK_RETURN: OnBsend(); } so if VK_RETURN is the case then call OnBsend() function! am i right? but if now i press Enter ! then still the program closes!!? please reflect light on tht

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #6

            What is happening in the OnOK() handler()?


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            D 1 Reply Last reply
            0
            • D David Crow

              What is happening in the OnOK() handler()?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              D Offline
              D Offline
              ddspliting
              wrote on last edited by
              #7

              well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key? u know clicking Send Button while working in a TextBox is cumbersome! just like chat in msn messenger or yahoo ones window! where when we press Enter! or wat u call RETURN the message is sent or we can say tht Send button is activated!

              D 1 Reply Last reply
              0
              • D ddspliting

                well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key? u know clicking Send Button while working in a TextBox is cumbersome! just like chat in msn messenger or yahoo ones window! where when we press Enter! or wat u call RETURN the message is sent or we can say tht Send button is activated!

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                ddspliting wrote:

                well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key?

                So did you bother to read this?


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                L D 2 Replies Last reply
                0
                • D David Crow

                  ddspliting wrote:

                  well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key?

                  So did you bother to read this?


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #9

                  Read? What programmers read? Pfffffffft we "write" .... code. We don't need no stinkin readin

                  M 1 Reply Last reply
                  0
                  • L led mike

                    Read? What programmers read? Pfffffffft we "write" .... code. We don't need no stinkin readin

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #10

                    :sigh:

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    1 Reply Last reply
                    0
                    • D David Crow

                      ddspliting wrote:

                      well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key?

                      So did you bother to read this?


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      D Offline
                      D Offline
                      ddspliting
                      wrote on last edited by
                      #11

                      Sorry! I read tht a bit late! and my problem is solved now! thanxx to u David and to the codeproject! Really Nice Service! top that! :)

                      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