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
Solved

Opening other modal dialog box in OnInitDialog

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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
Aptana 3.6 Preview Problem On Mac 35 136
How can I debug SSIS using Visual Studio 2008 2 79
eclipse compiler vs Installed JREs option 3 105
eclipse apache tomcat admin console 52 121
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 columnThat will then direct you to their download page.From that page s…
The viewer will learn how to synchronize PHP projects with a remote server 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.

861 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