Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I prevent a dialog from closing when the user presses Enter or Esc?

0
Posted

How do I prevent a dialog from closing when the user presses Enter or Esc?

0

Let’s first cover why the dialog closes, even if you remove the OK and Cancel buttons. CDialog has two special virtual functions, OnOK() and OnCancel(), which are called when the user presses the Enter or Esc key respectively. The CDialog implementations call EndDialog(), which is why the dialog closes. Since those are special-purpose functions, they do not appear in the dialog’s BEGIN_MESSAGE_MAP/END_MESSAGE_MAP section, and they need to be overridden differently than normal button click handlers. If you still have buttons with IDs IDOK and IDCANCEL, you can use ClassWizard to add BN_CLICKED handlers for those buttons, and it will do the special handling necessary for OnOK() and OnCancel(). If you do not have buttons with those IDs, then you can override the virtual functions manually.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.