Link to home
Start Free TrialLog in
Avatar of osi-sys
osi-sys

asked on

Maximize MDI Child window when Main window is maximized

Hello,


I am working with MDI application.  When I maximize my main window, my child windows should also be maximized. Can anyone please help me to do this?

Thanks

osi-sys
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Override PreCreateWindow, ActivateFrame of CChildFrame and do the following


BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
      // TODO: Modify the Window class or styles here by modifying
      //  the CREATESTRUCT cs

      cs.style &= ~WS_SYSMENU;
      if( !CMDIChildWnd::PreCreateWindow(cs) )
            return FALSE;

      return TRUE;
}


void CChildFrame::ActivateFrame(int nCmdShow)
{
      if (nCmdShow == -1)
        nCmdShow = SW_SHOWMAXIMIZED;
            
      CMDIChildWnd::ActivateFrame(nCmdShow);
}

Good Luck
~R
Avatar of osi-sys
osi-sys

ASKER

Hi roshmon

Thanks for your help.

I did not remove the SYSMENU form CChildFrame  as user should be given the option for minimising and maximizing the child window.

Hence I wrote only this part
void CChildFrame::ActivateFrame(int nCmdShow)
{
     if (nCmdShow == -1)
        nCmdShow = SW_SHOWMAXIMIZED;
         
     CMDIChildWnd::ActivateFrame(nCmdShow);
}
This works fine when the application is started, I am showing main window in maximize mode initially. So child frame also is maximized. But when I click change the main window size and again maximize the main window, the child frame window is not getting maximized.

Can you please suggest how to proceed further?

Thanks
Madhavi



   
Hi Madhavi,
override CMainFrame's ActivateFrame and call active child frame's SHowWindow(SW_SHOWMAXIMIZE)

~Roshan
Avatar of osi-sys

ASKER

Hi Roshan,

ActivateFrame handler of CMainFrame is not called at all. I checked using a messagebox.
ActivateFrame handler of CMDIChildWnd is called only once when new child view is craeted from File ->new .
I want my childd window to be maximized whenever Mainframe window is maximized.

Can you please suggest how to proceed further?

Thanks
Madhavi
hi,

can u make little bit clear, itz working for me..i tried resizing of main frame and maximiz...child is also maximizing...

~Roshan
Avatar of osi-sys

ASKER

Hi Roshan

void CChildFrame::ActivateFrame(int nCmdShow)
{
       if (nCmdShow == -1)
        nCmdShow = SW_SHOWMAXIMIZED;
      AfxMessageBox(_TEXT("Active-------Child"));
      CMDIChildWnd::ActivateFrame(nCmdShow);
}

void CMainFrame::ActivateFrame(int nCmdShow)
{

      CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
      CChildFrame *pChild = (CChildFrame *) pFrame->GetActiveFrame();
      pChild->ShowWindow(SW_MAXIMIZE);
      AfxMessageBox(_TEXT("Active   --Frame"));
      CMDIFrameWnd::ActivateFrame(nCmdShow);
}

I added the above code. For me ActivateFrame of CMainFrame is not getting called.

Madhavi
Only "void CChildFrame::ActivateFrame(int nCmdShow)" is needed, thatz working for me

~R
Avatar of osi-sys

ASKER

Hi

It's only working for the first time at application startup. Later when I resize the child window, and then resize the main window i.e maximize it, child window is not maximized.

Can you please post me the application to jmadhavi@yahoo.com

Thanks
Madhavi
oh now i got... u r resizing the child window after that right?

Map CmainFrame's WM_SIZE (ie. OnSize) and try the skelton code

CView *pView = GetActiveView();
pView->GetParent()->ShowWindow(SW_SHOWMAXIMIZE);


this is just a rought code may need some modification...

btw r u from india?

~Roshan
Avatar of osi-sys

ASKER

Hi,

Yes  I am from India.]

yes I am resizing both the child window and parent window i.e Mainframe window after that . I am trying, but still I'm unable to do it.

Can you please let me know if you find any solution.

Thanks
Madhavi
Avatar of osi-sys

ASKER

Hi

I could get it.

Thanks for your help.

Madhavi
map WM_SIZE of CMainFrame, and try following code

void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
      CMDIFrameWnd::OnSize(nType, cx, cy);
      
      CFrameWnd *pFrame = GetActiveFrame();

      if ( pFrame )
            pFrame->ShowWindow(SW_MAXIMIZE);      
}

~Roshan
ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America 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
:-)
where in india?
~R
Avatar of osi-sys

ASKER

Hyderabad