?
Solved

Opening other modal dialog box in OnInitDialog

Posted on 2008-10-14
3
Medium Priority
?
681 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses

752 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