MFC: Hiding a frame/view in MDI application

I'm trying to code a feature that enables the user to hide a visible document.
I have the following code:

POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
     CView* pView = GetNextView(pos);
     ASSERT_VALID(pView);
     ASSERT(::IsWindow(pView->m_hWnd));
     if (pView->IsWindowVisible())    
     {
          //pView->ShowWindow(SW_HIDE);
          //pView->UpdateWindow();
          CFrameWnd *pFrame = pView->GetParentFrame();
          if (pFrame != NULL)
          {
               //pFrame->ActivateFrame(SW_HIDE);
               //pFrame->InitialUpdateFrame(this,FALSE);

               pFrame->ShowWindow(SW_HIDE);
               pFrame->UpdateWindow();
          }
     }
}

The code that is commented out are some of my unsuccessful attempts.

Thank you in advance.
trishm
trishmAsked:
Who is Participating?
 
ZoppoCommented:
Hi trishm,

it should be enough to hide the frame window, i.e.:

POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
     CView* pView = GetNextView(pos);
     ASSERT_VALID(pView);
     ASSERT(::IsWindow(pView->m_hWnd));
     if (pView->IsWindowVisible())    
     {
          CWnd *pFrame = pView->GetParentFrame();
          if (pFrame != NULL)
          {
               pFrame->ShowWindow(SW_HIDE);
          }
     }
}

I use this in one of my applications succesfully ... if it doesn't work for you please tell in which way it doesn't ...

best regards,

ZOPPO
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
And what exactly is wrong?  
0
 
trishmAuthor Commented:
Zoppo:
You've confirmed that one of my attempts was valid and my problem lies elsewhere.
                 pFrame->ShowWindow(SW_HIDE);
I'm still finding my way around MFC.

More detail on my application:
1. When a document is opened in the main app via File\Open, the document displays within the main app.

2. Then, the file name is displayed in a list contained in a dialog box (external).
Both the dialog box and the code I listed above are in a DLL.

3. The user can select on or more of the file names listed and execute various operatitons on those files.

This is a complex application and I'm new to some of the technologies employed so it's hard to explain the communication between the two. What I can tell you, however, is that other operations executed on the selected document (s) from the dialog box operate correctly. I hope this gives you a clue.

trishm

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ZoppoCommented:
But what's really happening? Doesn't the frame disappear? Did you debug into your code? Is it executed?
0
 
trishmAuthor Commented:
Yes, I stepped through the code and everything executes as expected but the frame does not disappear.
0
 
mahesh1402Commented:
>>Yes, I stepped through the code and everything executes as expected but the frame does not disappear.

As suggested by zoppo above, hiding frame should work with pView->GetParentFrame()->ShowWindow(SW_HIDE)

Otherwise try and check that with pFrame->ActivateFrame(SW_HIDE)

e.g

          CWnd *pFrame = pView->GetParentFrame();
          if (pFrame != NULL)
                 pFrame->ActivateFrame(SW_HIDE);  

//  --OR--

        CWnd *pFrame = pView->GetParentFrame();
          if (pFrame != NULL)
         {
              pFrame->ActivateFrame();  
              pFrame->ShowWindow(SW_HIDE);  
         }

-MAHESH
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>Yes, I stepped through the code and everything executes as expected but the frame does not disappear.


That was the point of my first coment - posted at the same time as that by Zoppo.  Everything looked correct, the frame should not have been visible.


My next thought - Is the frame you want to hide not actually being found - ie. not in the collection you are looking through.
The views you are looking through belong to one document.  Is this document already hidden?
(Is this function actually being called? have you checked?)
0
 
mahesh1402Commented:
That will be verified just by activating frame and hiding as suggested above using pFrame->ActivateFrame() and  calling pFrame->ShowWindow(SW_HIDE);

-MAHESH
0
 
trishmAuthor Commented:
The combination of:
     pFrame->ActivateFrame();
     pFrame->ShowWindow(SW_HIDE);
did the trick.

Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.