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. Escape Key

Escape Key

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
8 Posts 4 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.
  • P Offline
    P Offline
    prathuraj
    wrote on last edited by
    #1

    I have two dialogs.In first Dialog i have a one button.When i click that button the next dialog will appear .After that i have pressed the Escape key the both dialog is closed.I want to close only the child dialog. How to do this.plz help me?

    W D 2 Replies Last reply
    0
    • P prathuraj

      I have two dialogs.In first Dialog i have a one button.When i click that button the next dialog will appear .After that i have pressed the Escape key the both dialog is closed.I want to close only the child dialog. How to do this.plz help me?

      W Offline
      W Offline
      William Wang
      wrote on last edited by
      #2

      I have two questions:1: r ur dialog boxes modal? 2: how long time did u keep pressing on the ESC key?

      life is like a box of chocolate,you never know what you r going to get.

      P 2 Replies Last reply
      0
      • W William Wang

        I have two questions:1: r ur dialog boxes modal? 2: how long time did u keep pressing on the ESC key?

        life is like a box of chocolate,you never know what you r going to get.

        P Offline
        P Offline
        prathuraj
        wrote on last edited by
        #3

        how to find model and modeless dialog

        1 Reply Last reply
        0
        • W William Wang

          I have two questions:1: r ur dialog boxes modal? 2: how long time did u keep pressing on the ESC key?

          life is like a box of chocolate,you never know what you r going to get.

          P Offline
          P Offline
          prathuraj
          wrote on last edited by
          #4

          how to find model and modeless dialog

          :rose:

          P 1 Reply Last reply
          0
          • P prathuraj

            how to find model and modeless dialog

            :rose:

            P Offline
            P Offline
            Parthi_Appu
            wrote on last edited by
            #5

            prathuraj wrote:

            how to find model and modeless dialog

            If you used DoModel() API, for the child dialog to show it, then the child dialog is model.Instead if you used other API to show the dialog,say, ShowWindow(..),then its modeless


            Do your Duty and Don't expect the Result
            Rate this Post, if I helped You

            P 1 Reply Last reply
            0
            • P Parthi_Appu

              prathuraj wrote:

              how to find model and modeless dialog

              If you used DoModel() API, for the child dialog to show it, then the child dialog is model.Instead if you used other API to show the dialog,say, ShowWindow(..),then its modeless


              Do your Duty and Don't expect the Result
              Rate this Post, if I helped You

              P Offline
              P Offline
              prathuraj
              wrote on last edited by
              #6

              i used Domodel()

              1 Reply Last reply
              0
              • P prathuraj

                I have two dialogs.In first Dialog i have a one button.When i click that button the next dialog will appear .After that i have pressed the Escape key the both dialog is closed.I want to close only the child dialog. How to do this.plz help me?

                D Offline
                D Offline
                Dustin Henry
                wrote on last edited by
                #7

                By default, the escape key triggers the OnCancel() event of a modal dialog. You must override the OnCancel function in your dialog class. Example from MSDN:

                void MyDialog::OnCancel() 
                {
                   // TODO: Add extra cleanup here
                   
                   // Ensure that you reset all the values back to the
                   // ones before modification. This handler is called
                   // when the user doesn't want to save the changes.
                   
                   if ( AfxMessageBox("Are you sure you want to abort the changes?", 
                         MB_YESNO) == IDNO )
                      return; // Give the user a chance if he has unknowingly hit the
                              // Cancel button. If he says No, return. Don't reset. If
                              // Yes, go ahead and reset the values and close the dialog. 
                
                   CDialog::OnCancel();
                }
                
                W 1 Reply Last reply
                0
                • D Dustin Henry

                  By default, the escape key triggers the OnCancel() event of a modal dialog. You must override the OnCancel function in your dialog class. Example from MSDN:

                  void MyDialog::OnCancel() 
                  {
                     // TODO: Add extra cleanup here
                     
                     // Ensure that you reset all the values back to the
                     // ones before modification. This handler is called
                     // when the user doesn't want to save the changes.
                     
                     if ( AfxMessageBox("Are you sure you want to abort the changes?", 
                           MB_YESNO) == IDNO )
                        return; // Give the user a chance if he has unknowingly hit the
                                // Cancel button. If he says No, return. Don't reset. If
                                // Yes, go ahead and reset the values and close the dialog. 
                  
                     CDialog::OnCancel();
                  }
                  
                  W Offline
                  W Offline
                  William Wang
                  wrote on last edited by
                  #8

                  OnCancel is not only called by hitting ESC key, also called by closing dialog box, for settling this, I think u may overwrite CDialog::PreTranslateMessage funcion like this. BOOL CdlgtestDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->hwnd == m_hWnd || ::IsChild(m_hWnd,pMsg->hwnd) && (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP)) { if(pMsg->wParam == VK_ESCAPE) return TRUE; } return CDialog::PreTranslateMessage(pMsg); }

                  life is like a box of chocolate,you never know what you r going to get.

                  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