?
Solved

Opening other modal dialog box in OnInitDialog

Posted on 2008-10-14
3
Medium Priority
?
693 Views
Last Modified: 2013-12-14
I'm working on a single document based application using VC++ 2008 /  Windows XP. I have created a simple CDialog-derived class "CMyDialog" and overridden its OnInitDialog to initialize the controls of my dialog box.

Now, I open CMyDialog using DoModal:

CMyDialog myDialog;
myDialog.DoModal();

The dialog opens as expected. While CMyDialog is opened, the user cannot interact with other windows until the CMyDialog is closed. So far so good.

Under certain conditions, I may need to open another modal dialog box from CMyDialog::OnInitDialog:
BOOL CMyDialog::OnInitDialog()
{
      CDialog::OnInitDialog();

      CMyDialog2 md2;
        md2.DoModal();

      return TRUE;  // return TRUE unless you set the focus to a control
      // EXCEPTION: OCX Property Pages should return FALSE
}

This is where I get confused. Once CMyDialog2 is closed, CMyDialog opens as expected, but it is not "modal" anymore. In other words CMyDialog is opened, but I can also interact with the other windows under it. I would like to understand why this happens and is there a way to prevent it assuming I do want to open other modal dialog box from OnInitDialog?
0
Comment
Question by:ahmaniem
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
alb66 earned 500 total points
ID: 22710570
Try to set CMyDialog as parent for CDialog2:
BOOL CMyDialog::OnInitDialog()
{
	CDialog::OnInitDialog();
 
	CMyDialog2 md2;
        md2.DoModal(this); <------------------------
 
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

Open in new window

0
 

Author Comment

by:ahmaniem
ID: 22710753
Thank you very much,

The parent is given to CDialog::CDialog instead of DoModal, but it pointed me to right direction, thank you.

BOOL CMyDialog::OnInitDialog()
{
        CDialog::OnInitDialog();
 
        CMyDialog2 md2(this); <------------------------
        md2.DoModal();
 
        return TRUE;  // return TRUE unless you set the focus to a control
        // EXCEPTION: OCX Property Pages should return FALSE
}
0
 
LVL 19

Expert Comment

by:alb66
ID: 22710784
ooooooops, I typed on the wrong line after copy and past... ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

862 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