Solved

Calling DoModal twice in InitInstance fails

Posted on 2002-05-24
4
880 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
Doc'in system (example?) BA 7 115
MaxSpan challenge 9 105
Path of Workbook 3 86
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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