Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop mfc dialog application from closing by pressing ESC

How can I stop mfc dialog application closing by pressing ESC (Escape key). After executing my application if I press ESC key then the window is closed. How can this be stopped? I am using VC++ 6.0.


1 Answers

You can override the OnCancel event and only move forward with the OnCancel call if IDCANCEL is the focused item.

void CMyDialog::OnCancel(void)
{
   if(GetDlgItem(IDCANCEL) ==  GetFocus())
    {  
        CDialog::OnCancel();
        return;
    }
}
like image 175
tschaible Avatar answered Sep 12 '25 00:09

tschaible