Solved

Maximize MDI Child window when Main window is maximized

Posted on 2004-10-18
16
835 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:osi-sys
  • 9
  • 7
16 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12344785
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
0
 

Author Comment

by:osi-sys
ID: 12344864
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



   
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12344893
Hi Madhavi,
override CMainFrame's ActivateFrame and call active child frame's SHowWindow(SW_SHOWMAXIMIZE)

~Roshan
0
 

Author Comment

by:osi-sys
ID: 12344988
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
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345019
hi,

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

~Roshan
0
 

Author Comment

by:osi-sys
ID: 12345056
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
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345089
Only "void CChildFrame::ActivateFrame(int nCmdShow)" is needed, thatz working for me

~R
0
 

Author Comment

by:osi-sys
ID: 12345119
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345134
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
0
 

Author Comment

by:osi-sys
ID: 12345486
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
0
 

Author Comment

by:osi-sys
ID: 12345505
Hi

I could get it.

Thanks for your help.

Madhavi
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345532
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
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 25 total points
ID: 12345540
:-(
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345618
:-)
where in india?
~R
0
 

Author Comment

by:osi-sys
ID: 12345722
Hyderabad
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 12345759
:-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now