Solved

MinimizeAll method for MDI children

Posted on 1998-06-18
15
627 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
[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
  • 9
  • 4
  • 2
15 Comments
 
LVL 2

Expert Comment

by:Belgarat
ID: 1166174
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
ID: 1166175
Edited text of question
0
 

Author Comment

by:fontainej
ID: 1166176
Edited text of question
0
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!

 

Author Comment

by:fontainej
ID: 1166177
Edited text of question
0
 

Author Comment

by:fontainej
ID: 1166178
Edited text of question
0
 
LVL 3

Expert Comment

by:gaohong
ID: 1166179
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
ID: 1166180
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 3

Expert Comment

by:gaohong
ID: 1166181
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
ID: 1166182
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
ID: 1166183
Sorry fontainej, but first try to learn how to use your WWW browser :-)
0
 

Author Comment

by:fontainej
ID: 1166184
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
ID: 1166185
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
ID: 1166186
Did I get points or you are still open the question. IMO, my
solution is A solution
0
 

Author Comment

by:fontainej
ID: 1166187
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
ID: 1166188

text above
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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