Solved

Calling DoModal twice in InitInstance fails

Posted on 2002-05-24
4
858 Views
Last Modified: 2013-11-20
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...
0
Comment
Question by:jdyer
  • 2
4 Comments
 
LVL 2

Expert Comment

by:christophm
ID: 7033594
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
0
 
LVL 1

Author Comment

by:jdyer
ID: 7033822

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
0
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 75 total points
ID: 7034148
Comment out this line

m_pMainWnd = &dlg1;

and you will get the functionality you want.

This is because the OnNcDestroy handler of any window checks whether or not it is the main window for the tread.
If it is a quit message is posted to the thread.

It is probably better coding practice to handle the WM_NCDESTROY message yourself and before calling the base CWnd handler ensure that m_pMainWnd is NULL;

0
 
LVL 1

Author Comment

by:jdyer
ID: 7034847

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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now