Solved

Opening other modal dialog box in OnInitDialog

Posted on 2008-10-14
3
676 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 125 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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

691 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