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. Cancelling ESC in dialogs

Cancelling ESC in dialogs

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

    How do I cancel the ESCAPE key in a modeless dialog...? Do I override OnCancel or PreTranslateMessage or perhaps something totally different...? Thanx! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

    P A J R 4 Replies Last reply
    0
    • A alex barylski

      How do I cancel the ESCAPE key in a modeless dialog...? Do I override OnCancel or PreTranslateMessage or perhaps something totally different...? Thanx! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      Create a handler for the WM_CHAR message inside of the PreTranslateMessage function, because the ESCAPE key is processed in the IsDialogMessage function for a dialog. This is the function that dispatches the message to the window, therefore you will have to process the WM_CHAR message before this function is called.

      A 1 Reply Last reply
      0
      • P Paul M Watt

        Create a handler for the WM_CHAR message inside of the PreTranslateMessage function, because the ESCAPE key is processed in the IsDialogMessage function for a dialog. This is the function that dispatches the message to the window, therefore you will have to process the WM_CHAR message before this function is called.

        A Offline
        A Offline
        alex barylski
        wrote on last edited by
        #3

        Thanx Kilo! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

        1 Reply Last reply
        0
        • A alex barylski

          How do I cancel the ESCAPE key in a modeless dialog...? Do I override OnCancel or PreTranslateMessage or perhaps something totally different...? Thanx! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

          A Offline
          A Offline
          Aaron K B Huang
          wrote on last edited by
          #4

          According to my experience, I would like to override OnCancel() function to handle the key event. It makes your program a little easier to use and fewer codes also. :)

          A 1 Reply Last reply
          0
          • A Aaron K B Huang

            According to my experience, I would like to override OnCancel() function to handle the key event. It makes your program a little easier to use and fewer codes also. :)

            A Offline
            A Offline
            alex barylski
            wrote on last edited by
            #5

            Does that actually work...? can you just return false in OnCancel to prevent escape from doing it's thing...? In anycase...it's pretty hard to beat:

            if(pMsg->message==WM_KEYDOWN){
            //Cancel escape and enter key
            if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) return TRUE;
            }

            Thats easy enough for me. Cheers "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

            A 1 Reply Last reply
            0
            • A alex barylski

              Does that actually work...? can you just return false in OnCancel to prevent escape from doing it's thing...? In anycase...it's pretty hard to beat:

              if(pMsg->message==WM_KEYDOWN){
              //Cancel escape and enter key
              if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE) return TRUE;
              }

              Thats easy enough for me. Cheers "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

              A Offline
              A Offline
              Aaron K B Huang
              wrote on last edited by
              #6

              :| Misunderstanding, friend! I means that I will let the user press esc to quit after I release every resources in OnCancel() function. I donnot want to forbid this feature. I was not talking about coding but a solution. :) And Thanks your code also.:rose:

              1 Reply Last reply
              0
              • A alex barylski

                How do I cancel the ESCAPE key in a modeless dialog...? Do I override OnCancel or PreTranslateMessage or perhaps something totally different...? Thanx! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                J Offline
                J Offline
                Jack Handy
                wrote on last edited by
                #7

                The way I do this is by overriding OnCancel() such as:

                void CMyDlg::OnCancel() {
                GetAsyncKeyState(VK_ESCAPE);
                if (!GetAsyncKeyState(VK_ESCAPE)) {
                CDialog::OnCancel();
                }
                }

                1 Reply Last reply
                0
                • A alex barylski

                  How do I cancel the ESCAPE key in a modeless dialog...? Do I override OnCancel or PreTranslateMessage or perhaps something totally different...? Thanx! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                  R Offline
                  R Offline
                  Rickard Andersson20
                  wrote on last edited by
                  #8

                  Happy birthday HockeyDude! :) :-D :-D ------------------------------------ Rickard Andersson, Suza Computing ICQ#: 50302279 I'm from the winter country SWEDEN! ------------------------------------

                  A 1 Reply Last reply
                  0
                  • R Rickard Andersson20

                    Happy birthday HockeyDude! :) :-D :-D ------------------------------------ Rickard Andersson, Suza Computing ICQ#: 50302279 I'm from the winter country SWEDEN! ------------------------------------

                    A Offline
                    A Offline
                    alex barylski
                    wrote on last edited by
                    #9

                    Thank you kindly. To be honest I totally forgot about that... I guess I should go ask friends/family for gifts now? Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                    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