CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 1999
    Posts
    2

    How to prevent ESC from closing a dialog app?



    This part does a less-than-decent job:


    void CMyProgDlg::OnCancel()

    {

    // do nothing

    }


    This will prevent the dialog box from closing due to a user pressing

    the ESC key. Unfortunately, this will also prevent other methods of

    exiting the dialog app, including Alt-F4 and pressing the "X" button

    at the top right corner. I want the user to still be able to quit using

    these methods (but not using ESC).


    So, the question is : is there some way to specifically intercept

    the ESC key before the IDCANCEL is issued to close the dialog box?




  2. #2
    Join Date
    Mar 1999
    Posts
    6

    Re: How to prevent ESC from closing a dialog app?



    Try this.

    Overide PreTranslateMessage, check WM_KEYDOWN message,

    and return TRUE if key is ESC


    Walter An

  3. #3
    Join Date
    Mar 1999
    Posts
    2

    Re: How to prevent ESC from closing a dialog app?



    Thanks Walter for pointing me in the right direction.

    Here's the code I've got now:


    BOOL CMyProgDlg::PreTranslateMessage(LPMSG lpmsg)

    {

    if (lpmsg->message == WM_KEYDOWN)

    if (lpmsg->wParam == VK_ESCAPE) return TRUE;

    return FALSE;

    }


    Short and sweet, and it works.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured