Solved

MinimizeAll method for MDI children

Posted on 1998-06-18
15
625 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
Industry Leaders: 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

730 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