Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check To See If Popup Dialog Exists

Posted on 2001-06-13
4
Medium Priority
?
334 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 150 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

604 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