Re: DoModal()



Note, however, that if anyone calls CDialog::OnOK(), they will call YOUR OnOK handler,
because it is a virtual method. Your OnOK() handler then calls CDialog::OnOK, which is
shown below. But if you call EndDialog(IDOK), then your OnOK() handler is NOT called, and
key behavior (such as the call on UpdateData(TRUE)) will not be executed. Therefore, it
should generally be considered inappropriate for YOUR dialog to call EndDialog(IDOK).
joe

On Mon, 12 Jan 2009 12:07:11 -0500, David Wilkinson <no-reply@xxxxxxxxxxxx> wrote:

hamishd wrote:
What is the difference between this->EndDialog(IDOK); and CDialog::OnOK
(); ?

hamishd:

Go to the source:

void CDialog::OnOK()
{
if (!UpdateData(TRUE))
{
TRACE(traceAppMsg, 0, "UpdateData failed during dialog termination.\n");
// the UpdateData routine will set focus to correct item
return;
}
EndDialog(IDOK);
}
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: OnCommand
    ... I saw your note about the OnOK after I posted my response. ... dialogs and therefore haven't faced the property sheet problem in many years, ... is there really a need to do an OnCommand handler? ...
    (microsoft.public.vc.mfc)
  • Re: DoModal()
    ... the generated code for an OnOK handler always calls CDialog::OnOK. ... calling the base class CDialog::OnOKfrom your derived class OnOK() is the ... But of course this violates your rule of never using UpdateData. ...
    (microsoft.public.vc.mfc)
  • Re: DoModal()
    ... Your OnOK() handler then calls CDialog::OnOK, ... I'm not quite sure what you are saying here, but the way I always saw it is that calling the base class CDialog::OnOKfrom your derived class OnOK() is the wrong thing to do. ... But of course this violates your rule of never using UpdateData. ...
    (microsoft.public.vc.mfc)
  • Re: DoModal()
    ... Your OnOK() handler then calls CDialog::OnOK, ... If you chain to the base class version, ... you will make redundant UpdateData and EndDialog calls. ...
    (microsoft.public.vc.mfc)
  • Re: MFC & Class Wizard
    ... in VS.NET, OnOK is a virtual method, but due to terminal brain damage on the part of the ... trick for radio buttons is to set the WS_GROUP flag for all radio buttons, ... >I don't understand why in class wizard that some functions are implemented ...
    (microsoft.public.vc.mfc)