Solved

Opening other modal dialog box in OnInitDialog

Posted on 2008-10-14
3
671 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
Comment Utility
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
Comment Utility
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
Comment Utility
ooooooops, I typed on the wrong line after copy and past... ;-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now