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. Beginner Dialog::OnOK() Question

Beginner Dialog::OnOK() Question

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
5 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.
  • C Offline
    C Offline
    CreekDawg
    wrote on last edited by
    #1

    Hi, I have a dialog based application with the standard "Ok" and "Cancel" buttons at the bottom. After the dialog app loads, if I press the 'enter' key, the app closes (the Dialog::OnOK() Event Fires). How can I override this action? In other words, I want to be able to press the 'enter' key and not close the application (not fire the OnOK() event method). How do I do this? Thanks.

    V J R 3 Replies Last reply
    0
    • C CreekDawg

      Hi, I have a dialog based application with the standard "Ok" and "Cancel" buttons at the bottom. After the dialog app loads, if I press the 'enter' key, the app closes (the Dialog::OnOK() Event Fires). How can I override this action? In other words, I want to be able to press the 'enter' key and not close the application (not fire the OnOK() event method). How do I do this? Thanks.

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

      There are two ways to do this - 1. You can do this by overriding the OnOK function in your dialog class and do NOT call the base class OnOK in that function. 2. In the dialog editor remove the default button property of the OK button. Hope this helps Krishnan

      1 Reply Last reply
      0
      • C CreekDawg

        Hi, I have a dialog based application with the standard "Ok" and "Cancel" buttons at the bottom. After the dialog app loads, if I press the 'enter' key, the app closes (the Dialog::OnOK() Event Fires). How can I override this action? In other words, I want to be able to press the 'enter' key and not close the application (not fire the OnOK() event method). How do I do this? Thanks.

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        Please see Mike Dunn's C++ FAQ, §7.4. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        1 Reply Last reply
        0
        • C CreekDawg

          Hi, I have a dialog based application with the standard "Ok" and "Cancel" buttons at the bottom. After the dialog app loads, if I press the 'enter' key, the app closes (the Dialog::OnOK() Event Fires). How can I override this action? In other words, I want to be able to press the 'enter' key and not close the application (not fire the OnOK() event method). How do I do this? Thanks.

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          Put in your own OnOK(0 for the dialog, and have code liek this:

          CMyDialog::OnOK()
          {
          if (GetFocus() != GetDlgItem(IDOK))
          return ; // only allow exit if OK has the focus
          }

          Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

          L 1 Reply Last reply
          0
          • R Roger Allen

            Put in your own OnOK(0 for the dialog, and have code liek this:

            CMyDialog::OnOK()
            {
            if (GetFocus() != GetDlgItem(IDOK))
            return ; // only allow exit if OK has the focus
            }

            Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

            L Offline
            L Offline
            lucy 0
            wrote on last edited by
            #5

            works perfectly!:-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