?
Solved

MFC: Hiding a frame/view in MDI application

Posted on 2007-07-26
9
Medium Priority
?
1,220 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:trishm
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 880 total points
ID: 19575723
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 19575735
And what exactly is wrong?  
0
 

Author Comment

by:trishm
ID: 19575962
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 31

Expert Comment

by:Zoppo
ID: 19576078
But what's really happening? Doesn't the frame disappear? Did you debug into your code? Is it executed?
0
 

Author Comment

by:trishm
ID: 19576671
Yes, I stepped through the code and everything executes as expected but the frame does not disappear.
0
 
LVL 22

Assisted Solution

by:mahesh1402
mahesh1402 earned 880 total points
ID: 19580707
>>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
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 240 total points
ID: 19583743
>>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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19583990
That will be verified just by activating frame and hiding as suggested above using pFrame->ActivateFrame() and  calling pFrame->ShowWindow(SW_HIDE);

-MAHESH
0
 

Author Comment

by:trishm
ID: 19592712
The combination of:
     pFrame->ActivateFrame();
     pFrame->ShowWindow(SW_HIDE);
did the trick.

Thank you!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

840 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