Solved

2 non-modal CDialogs; getting active Dialog-Window

Posted on 1997-03-07
1
729 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 36
sumDigits challenge 9 96
Hibernate methods 2 58
MaxSpan challenge 9 65
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. …
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…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now