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 could I disable Escape the dialog

how could I disable Escape the dialog

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 2 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.
  • L Offline
    L Offline
    lonely_life
    wrote on last edited by
    #1

    how could I disable the function when I click escape, dialog auto close. just like overwrite OnOk() function? but it seems there's no OnEscape()

    J 1 Reply Last reply
    0
    • L lonely_life

      how could I disable the function when I click escape, dialog auto close. just like overwrite OnOk() function? but it seems there's no OnEscape()

      J Offline
      J Offline
      Johan Rosengren
      wrote on last edited by
      #2

      The function you are looking for is OnCancel. Add a button with the ID IDCANCEL if you don't already have one, double click it to create a handler (in MSVC++ 6.0). Remove the call to the base class OnCancel and - finally - remove the button if you don't need it (although of course not the handler :-))

      L 1 Reply Last reply
      0
      • J Johan Rosengren

        The function you are looking for is OnCancel. Add a button with the ID IDCANCEL if you don't already have one, double click it to create a handler (in MSVC++ 6.0). Remove the call to the base class OnCancel and - finally - remove the button if you don't need it (although of course not the handler :-))

        L Offline
        L Offline
        lonely_life
        wrote on last edited by
        #3

        hmmm, if I overwrite OnCancel function, Esc key terminating the application is disabled, but I also can't terminate the application by click the top right cross button. What I want is just disable the key meanwhile the cross button still works.

        J 1 Reply Last reply
        0
        • L lonely_life

          hmmm, if I overwrite OnCancel function, Esc key terminating the application is disabled, but I also can't terminate the application by click the top right cross button. What I want is just disable the key meanwhile the cross button still works.

          J Offline
          J Offline
          Johan Rosengren
          wrote on last edited by
          #4

          Then you might want to kill the keypress as early as possible, adding the virtual function PreTranslateMessage:

          BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
          {

          BOOL result = FALSE:
          if( pMsg->message == WM\_KEYDOWN && pMsg->wParam == VK\_ESCAPE )
          	result = TRUE;
          else
          	result = CDialog::PreTranslateMessage(pMsg);
          
          return result;
          

          }

          L 1 Reply Last reply
          0
          • J Johan Rosengren

            Then you might want to kill the keypress as early as possible, adding the virtual function PreTranslateMessage:

            BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
            {

            BOOL result = FALSE:
            if( pMsg->message == WM\_KEYDOWN && pMsg->wParam == VK\_ESCAPE )
            	result = TRUE;
            else
            	result = CDialog::PreTranslateMessage(pMsg);
            
            return result;
            

            }

            L Offline
            L Offline
            lonely_life
            wrote on last edited by
            #5

            yes, this is what I want, thanks

            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