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

    Trapping ESC in CDialog

    Hi. I need a simple way to make it so that when you hit ESC, the dialog does not exit. I am assuming its something with keydown message, but exactly how to do it i am not sure.

    thanks in advance


  2. #2
    Guest

    Re: Trapping ESC in CDialog

    I think, that pressing ESC in CDialog associated with OnCancel function. So the siplest way, IMO, is to overload OnCancel function that way :

    void CAboutDlg::OnCancel()
    {
    return;
    }




    And, if you need to use cancel button, but without ESC association, you can give it ID different from IDCANCEL, and in the end of your function call CDialog::OnCancel().

    Jack.


  3. #3
    Join Date
    May 1999
    Posts
    22

    Re: Trapping ESC in CDialog

    use OnCommand, When u press Esc Key wParam on OnCommand will have value 2.

    For Example,

    if ur Dialog class is CMydialog, then
    void CMydialog::OnCommand(WPARAM wParam,LPARAM lParam)
    {
    if (wParam==2)
    return FALSE;

    return CDialog::OnCommand(wParam, lParam);
    }

    I am certain this works.
    Chow,


  4. #4
    Join Date
    May 1999
    Posts
    22

    Re: Trapping ESC in CDialog

    Hay, there is another way,
    If u Use OnCommand or OnCancel u will not able to close dialog, with Alt+f4
    Instead of those use this,

    BOOL CProcessApplSysDlg::PreTranslateMessage(MSG* pMsg)
    {
    // TODO: Add your specialized code here and/or call the base class
    BOOL Result=FALSE;
    if(pMsg->message==WM_CHAR)
    {

    OnChar((UINT)pMsg->wParam,(UINT)LOWORD(pMsg->lParam),
    (UINT)HIWORD(pMsg->lParam));
    Result=KeyPressResult((UINT)pMsg->wParam);

    }
    }

    BOOL CProcessApplSysDlg::KeyPressResult(UINT KeyID)
    {
    if(KeyID==2)
    return FALSE;
    else
    return TRUE;
    }

    in this way ESc Key is trapped & Alt+f4 works fine

    I am certain that this will do,

    Chow,
    Nagi,


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