?
Solved

Check To See If Popup Dialog Exists

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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