Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

2 non-modal CDialogs; getting active Dialog-Window

Posted on 1997-03-07
1
Medium Priority
?
748 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
[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
1 Comment
 
LVL 1

Accepted Solution

by:
MFCGuy earned 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

722 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