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:

  1. the dialog has default control (see cdialog::setdefid()). wm_command id of control sent dialog.
  2. 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.

  1. set default control other idok.
  2. set handler wm_command(idok) not call enddialog().
  3. override cdialog::onok() , not call base implementation.

about idcancel, similar there not equivalent setdefid() , esc key hardcoded. avoid dialog being closed:

  1. set handler wm_command(idcancel) not call enddialog().
  2. override cdialog::oncancel() , not call base implementation.

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

html - Accumulated Depreciation of Assets on php -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -