?
Solved

How do I resize a CMDIChildWnd that contains splitter windows

Posted on 2003-03-07
8
Medium Priority
?
735 Views
Last Modified: 2013-11-20
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;

}
0
Comment
Question by:tuBrody
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 

Expert Comment

by:aparyani
ID: 8105325
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
 

Author Comment

by:tuBrody
ID: 8121451
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
 

Accepted Solution

by:
aparyani earned 520 total points
ID: 8122221
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
 

Expert Comment

by:aparyani
ID: 8122240
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
 

Author Comment

by:tuBrody
ID: 8129185
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

771 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