Solved

Calling DoModal twice in InitInstance fails

Posted on 2002-05-24
4
900 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 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