Link to home
Start Free TrialLog in
Avatar of RJV
RJV

asked on

Hiding a MDI child window

I'm trying to hide a MDI child window, showing it when necessary. I've attempted ShowWindow(SW_HIDE) with no success yet. I'd greatly appreciate effective suggestions of a solution.
RJV
ASKER CERTIFIED SOLUTION
Avatar of AVaulin
AVaulin
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davmarc
davmarc

I think the following should get the frame. Please correct me if I'm wrong (I've removed the assertions):

CMDIFrameWnd *pFrame = (CMDIFrameWnd *)pApp->m_pMainWnd;

CMDIChildWnd* pChild = pFrame->MDIGetActive();

pChild->ShowWindow(SW_HIDE);

I've tried other variations, such as calling ::ShowWindow() with the same result. It returns but the window or frame is still visible.

I'll try the ModifyWindow suggestion to see it that will do the trick. Any further suggestions and examples you might have would be a super help.

RJV

Avatar of RJV

ASKER

Hi AVaulin,

I tried your suggestion. Unfortunately it doesn't work, at least not yet. The child frame is still visible yet, curiously, apparently innacitve. Even a cursor bar in the text stays frozen there. Any ideas of what might be happening?

RJV

Avatar of RJV

ASKER

Add pFrame->MDINext(); between MDIGetActive and ShowWindow methods calls.
Hi AVaulin,

I lost you there. If I add pFrame->MDINext() I should get the child window behind the one I got with  MDIGetActive(), or not? For test purposes there is only one maximized child window. Later there be either one or more child windows, all of which to be hidden.

Meanwhile I just discovered by chance that your first suggestion seems to be working. At least it works as long as one steps through the ModifyStyle( WS_VISIBLE, 0, SWP_HIDEWINDOW) call. Tell the debugger to continue at full speed after that and the child window is gone. Do it outside the debugger (i.e. Ctrl-F5 in VC++ 5.0) and you get the result described above. Thus this seems to be associated to the lack of refreshing the screen, though UpdateWindow() and Invalidate() haven't done the trick yet.

Hope this info helps.
RJV
Avatar of RJV

ASKER

OK! I created new MDI project and added say ID_EDIT_UNDO command handler to CMainFrame class. There are two variants of this command handler below. Each of two variants does what you want (one of them uses my first suggestion, other - second).

/*
---- first variant
*/
void CMainFrame::OnEditUndo()
{
      CMDIChildWnd* wnd = MDIGetActive();
      wnd->ModifyStyle( WS_VISIBLE, 0, SWP_HIDEWINDOW );
      wnd->RedrawWindow();
      RedrawWindow();
}

/*
---- second variant
*/
void CMainFrame::OnEditUndo()
{
      CMDIChildWnd* wnd = MDIGetActive();
      MDINext();
      wnd->ShowWindow(SW_HIDE);
}

Choose variant you like and good luck.
Hi AVaulin,

Your second option (or variant) worked, but not the first. The only difference is that I used the original pFrame method as I couldn't get MDINext() to be recognized as a legitimate function without it. I'm still curious why getting the next child frame works while getting the first does not.

Now I just have to figure out how to keep track of the right view to bring back when necessary. Any suggestions are greatly appreciated.

RJV

PS
I'd also like to commend you on your help as some of the help in the past was quite often off target.