Solved

Check To See If Popup Dialog Exists

Posted on 2001-06-13
4
319 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 88
tripleUp challenge 7 73
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ... 2 102
Path of Workbook 3 59
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

911 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

23 Experts available now in Live!

Get 1:1 Help Now