c++ - How to prevent MFC dialog closing on Enter and Escape keys? -
i know 1 method of preventing mfc dialog closing when enter or esc keys pressed, i'd know more details of process , common alternative methods doing so.
thanks in advance help.
when user presses enter key in dialog 2 things can happen:
- the dialog has default control (see
cdialog::setdefid()
). wm_command id of control sent dialog. - the dialog not have default control. wm_command id = idok sent dialog.
with first option, may happen default control has id equal idok. results same in second option.
by default, class cdialog
has handler wm_command(idok)
call cdialog::onok()
, virtual function, , default calls enddialog(idok)
closes dialog.
so, if want avoid dialog being closed, 1 of following.
- set default control other
idok
. - set handler
wm_command(idok)
not callenddialog()
. - override
cdialog::onok()
, not call base implementation.
about idcancel, similar there not equivalent setdefid()
, esc key hardcoded. avoid dialog being closed:
- set handler
wm_command(idcancel)
not callenddialog()
. - override
cdialog::oncancel()
, not call base implementation.
Comments
Post a Comment