Solved

Check To See If Popup Dialog Exists

Posted on 2001-06-13
4
329 Views
Last Modified: 2013-11-20
I am developing an SDI application on Windows NT 4.0 using Visual Studio 6.0, Visual C++.   In this application the Child form calls and creates Modeless Popup Dialog Windows.  I need to check and see if the window exists before I try to Create it again.  The reason for this is that the Child form can call several windows and they will stack up.  If the window does exist I need to move it to the top of the stack of windows.  
0
Comment
Question by:LBoorn
[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
  • 2
4 Comments
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6186413
Try to use FindWindow() function to find if that window exist.
0
 
LVL 1

Accepted Solution

by:
nrajan earned 50 total points
ID: 6186503
The Microsoft recommended way to handle modeless dialogs is as follows. Let us say your modeless dialog class is called MyDialog.

1) In the parent window class declare a member function of type 'pointer to MyDialog', m_pDlg. Initialize this to NULL in the constructor of the parent window. When you want to create the modeless dialog, do so on the HEAP by declaring

if( m_pDlg)
{
m_pDlg = new Mydialog(this);
m_pDlg.Create();
}
m_pDlg.ShowWindow(SW_SHOWNORMAL);

2) Create a method on the main dialog class called, say, DialogClosed() and code it as follows

m_pDlg = NULL;

2) In the MyDialog class constructor store the 'this' pointer received from the parent window into a CWnd pointer say m_pParent.

3) Add the OnCancel(), OnClose() and PostNcDestroy() methods for the MyDialog class. In OnCancel() and OnClose() just call m_pParent->DialogClosed(); and in PostNcDestroy() do a 'delete this;'

Logically this is how the whole thing works. As long as the modeless dialog is open, the m_pDlg member in the parent class is not NULL, therefore the modeless dialog is never created again and again, however the modeless dialog is brought into focus with the ShowWindow call. When the modeless dialog is closed the 'callback' function 'DialogClosed()' is called which sets the pointer to NULL thus allowing the dialog to be created the next time. The PostNcDestroy() method takes care of destyoing the MyDialog object.
I have actually used this in a project and it works beautifully.
good luck
0
 
LVL 1

Expert Comment

by:nrajan
ID: 6186522
Sorry small code bug. The line should be

if( !m_pDlg)
{


0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189693
Agree with nrajan.
That is aproach that I use every time on this problem.
But I suggest to solve posted problem (question) not the better (or best) solution on problem.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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