Sheep
Sheep

Reputation: 49

How to initialize a modal dialog ? (C++ / MFC)

I would like to fill some fields of my dialog when it's shown. Consequently, I would like to follow those steps:

  1. construct the dialog object
  2. call DoModal()
  3. initialize its fields

However, I can pass to the instruction following DoModal() only when the dialog is closed. Consequently, how can I initialize my dialog's fields?

I tried to override DoModal():

int MyDialog::DoModal()
{
    int a = CDialogEx::DoModal();
    InitDialog();

    return a;
}

but it's the same issue: InitDialog() is called when the dialog is closed...

Upvotes: 0

Views: 2118

Answers (1)

Ivan Sheihets
Ivan Sheihets

Reputation: 830

Create the dialog object, than add OnInitDialog on your dialog, this method will calls before showing dialog (OnInitDialog msdn). Add variables to your dialog (int a;)

Call dailog:

CDialog dlg;
dlg.a = 10;
dlg.DoModal();

Upvotes: 3

Related Questions