Solved

2 non-modal CDialogs; getting active Dialog-Window

Posted on 1997-03-07
1
739 Views
Last Modified: 2013-11-19
Environment: Windows NT 3.51, MS Visual C++ 4.0

My problem:

I have an application with MFC:
There can be TWO non-modal Dialogs visible at the screen at the same time.
The menu item "File | Close" should close the actual ACTIVE Window Dialog.

How can I get a pointer/reference to the ACIVE Dialog ???

My current basic approach solution:

void CTestView::OnFileClose() {

    HWND pActiveWnd = (HWND) GetActiveWindow;
    if (pActiveWnd == m_pDialog1)
       m_pDialog1->DestroyWindow();
    else
       m_pDialog2->DestroyWindow;
}

Definitions:
  class Dialog1 public CDialog {...}
  class Dialog2 public CDialog {...}

  class CTestView public CView {
    private:
      Dialog1 m_pDialog1;
      Dialog2 m_pDialog2;
  }

Unfortunately, at this time the main window i.e. the menu window is the active window and so  I don't get the pointer I wish to receive.
Where is a the best palce to get the pointer of the active Dialog ???

I hope for an answer to this problem.

Thanks   Matthias

0
Comment
Question by:muma0016
1 Comment
 
LVL 1

Accepted Solution

by:
MFCGuy earned 50 total points
ID: 1300526
Try using:
GetWindow(GW_CHILD) and
GetWindow(GW_NEXT) in a loop

This will loop through all the children of your View using the Z-Order so the window that was last active window should be found first.

CWnd* tmpWnd = GetWindow(GW_CHILD);
while (tmpWnd != NULL)
{
   if(tmpWnd == m_pDialog1 || tmpWnd == m_pDialog2)
   {
      tmpWnd->DestroyWindow();
      break;
   }
}


Also, GetActiveWindow does not return an HWND since
you called CWnd::GetActiveWindow() in your code in:
HWND pActiveWnd = (HWND) GetActiveWindow();

Therefore, you tried to compare a CWnd* to an HWND in:
if (pActiveWnd == m_pDialog1)
which wouldn't of worked anyway...

Hope I helped,
MFCGuy
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List out all word 7 318
format the code in java 6 101
Window placement 17 87
pre4 challenge 19 104
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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