Solved

2 non-modal CDialogs; getting active Dialog-Window

Posted on 1997-03-07
1
743 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 89
withoutTen challenge 14 142
wordcount challenge 11 164
Problem to App source 6 120
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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