Wrapping the Dialog Procedure

浪尽此生 提交于 2019-12-08 04:52:28

This gives you less flexibility - It'd be better to call event handlers from the virtual dialog procedure, allowing you to override the behavior for individual subclasses. If you want these "event handlers" to be called by default for all subclasses of ModalDialog, simply don't make the virtual dialog procedure pure virtual - implement it also for ModalDialog, and explicitly call it from subclasses.

ModalDialog::dialogProc(...) {
  switch (...) {
  case ...: onInitDialog(...); break;
  }
}

ModalDialogSubClass::dialogProc(...) {
  switch (...) {
  case ...: break;
  default: return ModalDialog::dialogProc(...);
}

Given this scenario, you could make the decision to not call onInitDialog for a specific base class in the dialogProc for that base class.

Typically, what you want to do in the static procedure is simply:

if (is first message) {
  SetWindowLong...
}
((ModalDialog *) GetWindowLong())->dialogProc(); // Also for the initial message
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!