Solved

MinimizeAll method for MDI children

Posted on 1998-06-18
15
616 Views
Last Modified: 2010-08-05
Using MSVC 5 w/ MFC, how does one incorporate a MinimizeAll method for a MDI implmentation? The more detailed question is how to iterate on MDI children and guarantee you will hit them all?

This was suggested...

You can get the active MDI child by calling CMDIFrameWnd.MDIGetActive(). Then you can iterate using pMDIChild->GetWindow(HWND_NEXT) sending messages or calling member functions as you like.

Which is what I actually had done, but there is a problem...

void CMainFrame::OnWindowMinimizeAll()
{
  CMDIChildWnd* pMDIChild = MDIGetActive();
  CMDIChildWnd* pFirstActive = pMDIChild;
  while (pMDIChild)
  {
    pMDIChild->CloseWindow(); // Minimizes
    pMDIChild =  (CMDIChildWnd*)pMDIChild->GetNextWindow();
    if (pMDIChild == pFirstActive)
      break;
  }

However this will not actually do the job. If any window is activated other than the last, the loop will not hit each child. There is probably something wrong w/ the loop termination criteria, but something has to be there or the iteration will never terminate. The fundamental issue witht he suggested approach is that the 1st window in the window management list is not the same as the active MDI child, so iterating from active window forward doesn't guarantee all children are processed (at least w/ my loops above)
0
Comment
Question by:fontainej
  • 9
  • 4
  • 2
15 Comments
 
LVL 2

Expert Comment

by:Belgarat
Comment Utility
You can get the active MDI child by calling CMDIFrameWnd.MDIGetActive(). Then you can iterate using pMDIChild->GetWindow(HWND_NEXT) sending messages or calling member functions as you like.

0
 

Author Comment

by:fontainej
Comment Utility
Edited text of question
0
 

Author Comment

by:fontainej
Comment Utility
Edited text of question
0
 

Author Comment

by:fontainej
Comment Utility
Edited text of question
0
 

Author Comment

by:fontainej
Comment Utility
Edited text of question
0
 
LVL 3

Expert Comment

by:gaohong
Comment Utility
It hit me once. Using MDIGetActive() will not work.
You need to do is get its parent window first, then

hChild = GetWindow(GW_CHILD);
//mini for first
//loop here
hNext = GetWindow(hChild, GW_HWNDNEXT);
//mini
hChild = hNext;
0
 

Author Comment

by:fontainej
Comment Utility
From gaohong...

It hit me once. Using MDIGetActive() will not work.
You need to do is get its parent window first, then

hChild = GetWindow(GW_CHILD);
//mini for first
//loop here
hNext = GetWindow(hChild, GW_HWNDNEXT);
//mini
hChild = hNext;

is not quite working. Here is the current implementation which is trying to minimize windows that are children of frame (parent of MDI child), but these windows include menus, toolbars, etc and not just MDI children. I'm sure I'm just interpreting the suggestion incorrectly, to avoid ambiguity it would be helpful if someone would just modify the following self-explanatory code so it will work. I'll up the points to 100 to the 1st working solution as this has been ridiculously tedious. THIS SHOULD BE VERY EASY (I did it in borland easy enough but OWL maintains its MDI child lists differently than MFC).


void CMainFrame::OnWindowMinimizeAll()
{
  HWND hFirstChild = ::GetWindow(*this,GW_CHILD);
  HWND hChild = hFirstChild;
  ::ShowWindow(hChild, SW_MINIMIZE);
  while (hChild)
  {
    HWND hNext = ::GetWindow(hChild, GW_HWNDNEXT);
    ::ShowWindow(hChild, SW_MINIMIZE);
    hChild = hNext;
  }
}
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:gaohong
Comment Utility
You miss understood the MDI architecture. MDIFrame only has MDIClient as child, while MDIChild's parent is MDIClient.

      void CMainFrame::OnWindowMinimizeAll()
      {
        CMDIChildWnd *activeChild = MDIGetActive();

        if(activeChild)
          {
           CWnd *client = activeChild->GetParent();
           if(client)
             {
        HWND hFirstChild = client->GetWindow(*this,GW_CHILD);
        HWND hChild = hFirstChild;
        ::ShowWindow(hChild, SW_MINIMIZE);
        while (hChild)
        {
          HWND hNext = client->GetWindow(hChild, GW_HWNDNEXT);
          ::ShowWindow(hChild, SW_MINIMIZE);
          hChild = hNext;
        }
        }
        }
      }

0
 

Author Comment

by:fontainej
Comment Utility
From gaohong...

It hit me once. Using MDIGetActive() will not work.
You need to do is get its parent window first, then

hChild = GetWindow(GW_CHILD);
//mini for first
//loop here
hNext = GetWindow(hChild, GW_HWNDNEXT);
//mini
hChild = hNext;

is not quite working. Here is the current implementation which is trying to minimize windows that are children of frame (parent of MDI child), but these windows include menus, toolbars, etc and not just MDI children. I'm sure I'm just interpreting the suggestion incorrectly, to avoid ambiguity it would be helpful if someone would just modify the following self-explanatory code so it will work. I'll up the points to 100 to the 1st working solution as this has been ridiculously tedious. THIS SHOULD BE VERY EASY (I did it in borland easy enough but OWL maintains its MDI child lists differently than MFC).


void CMainFrame::OnWindowMinimizeAll()
{
  HWND hFirstChild = ::GetWindow(*this,GW_CHILD);
  HWND hChild = hFirstChild;
  ::ShowWindow(hChild, SW_MINIMIZE);
  while (hChild)
  {
    HWND hNext = ::GetWindow(hChild, GW_HWNDNEXT);
    ::ShowWindow(hChild, SW_MINIMIZE);
    hChild = hNext;
  }
}
0
 
LVL 2

Expert Comment

by:Belgarat
Comment Utility
Sorry fontainej, but first try to learn how to use your WWW browser :-)
0
 

Author Comment

by:fontainej
Comment Utility
Thanks a lot gaohong, this is one of those where a little sleep last night would have been advantageous. Here is a compiled solution that is working if anyone else has this question...

void CMainFrame::OnWindowMinimizeAll()
{
  CMDIChildWnd *activeChild = MDIGetActive();
  ASSERT(activeChild);

  CWnd *client = activeChild->GetParent();
  ASSERT(client);
 
  CWnd*  hChild = client->GetWindow(GW_CHILD);
  while (hChild)
  {
    CWnd* hNext = hChild->GetWindow(GW_HWNDNEXT);
    hChild->ShowWindow(SW_MINIMIZE);
    hChild = hNext;
  }
}
0
 

Author Comment

by:fontainej
Comment Utility
Thanks a lot gaohong, this is one of those where a little sleep last night would have been advantageous. Here is a compiled solution that is working if anyone else has this question...

void CMainFrame::OnWindowMinimizeAll()
{
  CMDIChildWnd *activeChild = MDIGetActive();
  ASSERT(activeChild);

  CWnd *client = activeChild->GetParent();
  ASSERT(client);
 
  CWnd*  hChild = client->GetWindow(GW_CHILD);
  while (hChild)
  {
    CWnd* hNext = hChild->GetWindow(GW_HWNDNEXT);
    hChild->ShowWindow(SW_MINIMIZE);
    hChild = hNext;
  }
}
0
 
LVL 3

Expert Comment

by:gaohong
Comment Utility
Did I get points or you are still open the question. IMO, my
solution is A solution
0
 

Author Comment

by:fontainej
Comment Utility
gaohong, sorry this is my first use of the site and i thought i did award the points. apparently, since i rejected answer before there is no option for me to accept answer at this time. please just resubmit or whatever is required and i'll happily award the points. thanks.
0
 
LVL 3

Accepted Solution

by:
gaohong earned 100 total points
Comment Utility

text above
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

11 Experts available now in Live!

Get 1:1 Help Now