How do I resize a CMDIChildWnd that contains splitter windows

I have a MDI child window where a splitter with 3 panes gets created. I want to set the initial size of this child window to some given width and height. For some reason I can not get the window to resize, specially in its height. It always comes up with the same height. I tried through the PreCreateWindow method with no success. I also tried two approaches that are commented below. I don't know what else to do. Please help.(see code below)

BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
     CCreateContext* pContext)
{

     // create splitter window
     if (!m_wndSplitter.CreateStatic(this, 1, 3))
          return FALSE;


     // Desired width & height
     int width = 700;
     int height = 500;    
     int leftwidth = 180;
     width -= leftwidth;



     if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(leftwidth, height), pContext) ||
          !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CGUIView), CSize(width, height), pContext)||
          !m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CSuperTraitView), CSize(0, height), pContext))
     {
          m_wndSplitter.DestroyWindow();
          return FALSE;
     }

     

     // THIS DIDN'T DO IT
     //m_wndSplitter.SetRowInfo(0, height, 0);    
     //m_wndSplitter.SetColumnInfo( 0, leftwidth, height );
     //m_wndSplitter.SetColumnInfo( 1, width, height );
     //m_wndSplitter.SetColumnInfo( 2, 0, height );    
     //m_wndSplitter.RecalcLayout();

     
     // NEITHER DID THIS
     //SetWindowPos(NULL, 0 , 0 , width , height , flags);
     //UpdateWindow();
     

     return TRUE;

}
tuBrodyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aparyaniCommented:
Try overriding PreCreateWindow

See the MSDN info:


To change the default window attributes used by a framework application created with AppWizard, override the window’sPreCreateWindow virtual member function. PreCreateWindow allows an application to access the creation process normally managed internally by theCDocTemplate class. The framework calls PreCreateWindow just prior to creating the window. By modifying theCREATESTRUCT parameter to PreCreateWindow, your application can change the attributes used to create the window.

TheCTRLBARS sample application demonstrates this technique for changing window attributes. Depending on what your application changes in PreCreateWindow, it may be necessary to call the base class implementation of the function.

The following discussion covers the SDI case and the MDI case.

The SDI Case
In a single document interface (SDI) application, the default window style in the framework is a combination of the WS_OVERLAPPEDWINDOW and FWS_ADDTOTITLE styles. FWS_ADDTOTITLE is an MFC-specific style that instructs the framework to add the document title to the window’s caption. To change the window attributes in an SDI application, override the PreCreateWindow function in your class derived from CFrameWnd (which AppWizard names CMainFrame). For example:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    // Create a window without min/max buttons or sizable border
    cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;

    // Size the window to 1/3 screen size and center it
    cs.cy = ::GetSystemMetrics(SM_CYSCREEN) / 3;
    cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 3;
    cs.y = ((cs.cy * 3) - cs.cy) / 2;
    cs.x = ((cs.cx * 3) - cs.cx) / 2;

    // Call the base-class version
    return CFrameWnd::PreCreateWindow(cs);
}

This code creates a main frame window without Minimize and Maximize buttons and without a sizable border. The window is initially centered on the screen.

The MDI Case
A little more work is required to change the window style of a child window in a multiple document interface (MDI) application. By default, an MDI application created with AppWizard uses the defaultCMDIChildWnd class defined in MFC. To change the window style of an MDI child window, you must derive a new class from CMDIChildWnd and replace all references to CMDIChildWnd in your project with references to the new class. Most likely, the only reference to CMDIChildWnd in the application is located in your application's InitInstance member function.

The default window style used in an MDI application is a combination of the WS_CHILD, WS_OVERLAPPEDWINDOW, and FWS_ADDTOTITLE styles. To change the window attributes of an MDI application’s child windows, override thePreCreateWindow function in your class derived from CMDIChildWnd. For example:

BOOL CMyChildWnd::PreCreateWindow(CREATESTRUCT& cs)
{
    // Create a child window without the maximize button
    cs.style &= ~WS_MAXIMIZEBOX;

    // Call the base-class version
    return CMDIChildWnd::PreCreateWindow(cs);
}


0
tuBrodyAuthor Commented:
Thank aparyani. I know about PreCreateWindow, I actually read the article you pasted more than one time. However for some reason, both of the following approaches get my window in a "strage" state. That is, the form's caption bar gets merged with the MDI window (as in regular maximized state), but the rest of the child window does not chage size to maximized. It is very strange, I think it has something to do with the use of the splitter window.

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
   /*
   // Approach 1
   cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED |
          WS_CAPTION | WS_SYSMENU | FWS_ADDTOTITLE|
          WS_THICKFRAME | WS_MINIMIZEBOX |
                WS_MAXIMIZEBOX | WS_MAXIMIZE;
   */

    /*
    // Approach 2
    cs.style |= WS_MAXIMIZE;
    */


   // Call the base-class version
   return CMDIChildWnd::PreCreateWindow(cs);
}

Also, If I instead of attempting to add WS_MAXIMIZE to cs.style try to change cs.cx and cs.cy, there is no effect in the window that appears. That is also very strange. Again I think it has something to do with the creation of the splitters in the OnCreateClient method.

Any more ideas?
0
aparyaniCommented:
Aha, I think I got it.  You should not be returning true in OnCreateClient().

Try this

m_wndSplitter.SetRowInfo(0, height, 0);    
m_wndSplitter.SetColumnInfo( 0, leftwidth, height );
m_wndSplitter.SetColumnInfo( 1, width, height );
m_wndSplitter.SetColumnInfo( 2, 0, height );    

return CMDIChildWnd::OnCreateClient(lpcs, pContext);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aparyaniCommented:
Aha, I think I got it.  You should not be returning true in OnCreateClient().

Try this

m_wndSplitter.SetRowInfo(0, height, 0);    
m_wndSplitter.SetColumnInfo( 0, leftwidth, height );
m_wndSplitter.SetColumnInfo( 1, width, height );
m_wndSplitter.SetColumnInfo( 2, 0, height );    

return CMDIChildWnd::OnCreateClient(lpcs, pContext);
0
tuBrodyAuthor Commented:
I did try it, it does change the size of the window, but it has 2 problems.
- It does not display any of my panes, seems like the splitter window does not even get created, like the base class' OnCreateClient overrides something
- It does not seem to display the window of the size I want.


I noticed another mistake I had which was that the SetColumnInfo function should not receive a "height" as its third parameter, but rather a minimum display width. Anyhow doing the corresponding changes did not change things nor helped my problem.

I was also researching in other sites and I figured that I should not call the base class function of OnCreateClient in my case as you suggest, returning TRUE seems to be the way for splitter window creation (see http://orchard.wccnet.org/~chasselb/win293/ClassNotes/MultipleEverything2.html ). Anyways, I am still stuck on this. Will appreciate any other ideas.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

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.