Solved

Check To See If Popup Dialog Exists

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
method notes when mouse over in eclipse 5 68
tripleUp challenge 7 67
zeroMAx challenge 20 77
Path of Workbook 3 45
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: 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…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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