Link to home
Start Free TrialLog in
Avatar of jdyer
jdyer

asked on

Calling DoModal twice in InitInstance fails

Hey Guys,

I think this ought to be an easy one, I'm just tired and rusty. In my InitInstance function of my application, I want to show one dialog box followed by another, ie

CDialog1 dlg1;
CDialog2 dlg2;

m_pMainWnd = &dlg1;

if( dlg1.DoModal() == IDOK )
{
  m_pMainWnd = &dlg2;
  dlg2.DoModal();
}

However, dlg2 never opens (actually I followed it through the Debugger and it opens briefly then closes). [Yes, I *do* get into the _if_ block, don't worry]

What's the deal?? How do I fix this??

Thanks,

 - J

PS If you think it's worth more points, let me know...
Avatar of christophm
christophm

hi jdyer,

Implement the 'OnOK()' for the 'OK' button of the first (dlg1) dialog.

In the 'dlg1.OnOK()' function put this:

void dlg1::OnOK()
{
  // TODO: Add extra validation here
  CDialog2   dlg2;
  dlg2.DoModal();

  CDialog::OnOK();
}

The first dialog will remain visible, the second dialog will display above it, clicking Cancel/OK on the second dialog closes both.
good luck ! - christophm
Avatar of jdyer

ASKER


Chris,

Thanks for your response, but that's not what I'm looking for :-)

I need the funtionality I've described above.

Essentially it would be nice to know WHY the code I've shown above doesn't work. Intuitively it should and sifting through MFC code trying to figure it out is not feasible on my timetable.

That's why I came here... looking for someone who had run into the same problem - and, has solved it.

Regards,

 - J
ASKER CERTIFIED SOLUTION
Avatar of GGRUNDY
GGRUNDY

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdyer

ASKER


GRUNDY,

Thank you. That was the information I was looking for and sort of suspected.

The problem with just commenting out m_pMainWnd is that then you don't get the window displayed on the Windows taskbar. This means it can get "lost" behind other windows and things like that and the user won't even realize s/he has it open.

I like your second suggestion better. I'm accepting it as the answer.

Take care.

 - Justin