Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling DoModal twice in InitInstance fails

Posted on 2002-05-24
4
Medium Priority
?
930 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 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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