Toggling the Splitter Orientation

This is a pair of classes that will allow you to give the user control over the orientation of the splitter in a static splitter window.

The first is CTogSplitterWnd, a CSplitterWnd that contains support for actually toggling the splitter bar. The second, CSplitFrame, is a CMDIChildWnd (though changing this to be any other CFrameWnd shouldn’t be hard).

The CMDIChildWnd derived class provides support for various message handlers to allow the user to get at these functions as well as providing support for closing either pane of the view. It does this by resizing the splitter rather than completely hiding the view, for my application this was more appropriate.

The full code is in the zip file, but here are a few comments about the code.

The actual toggle function is:


void CTogSplitterWnd::Toggle()
{
    if ( BarIsHorizontal() )
    {
        SetWindowLong( GetPane( 1, 0 )->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST + 1 );
        m_nRows = 1;
        m_nCols = 2;
    }
    else
    {
        SetWindowLong( GetPane( 0, 1 )->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST + 16 );
        m_nRows = 2;
        m_nCols = 1;
    }
}

It turns out to be fairly simple, though it took some rooting around in the MFC source to work out how to do it. Whilst I’m sure that this is undocumented, this code is basically the same as the version I wrote for MFC 1.5 many moons ago (SetWindowWord became SetWindowLong if I remember correctly).

There is certainly more code to CSplitFrame since it has to store the location of the splitter bar so that it restores back to its last location. It also depends upon the definition of a number of command IDs that are in the sample resource file.



Comments

  • How to togel with 3 row 1 col

    Posted by Legacy on 01/24/2002 12:00am

    Originally posted by: Ramakrishnan.A

    hi,
    
    

    I tried this sample by adding 3row 1col but it crashed in togel function.

    3 row 1 col -> 1 row 3 col.
    do you have any suggestion.

    Thanks & regards

    Reply
  • Leaks memory.

    Posted by Legacy on 07/27/2000 12:00am

    Originally posted by: Dave R

    This DOES work, and is easy to use.... but if you run w/ memry leak detection enabled, you'll find it leaks every time you switch orientation. Not much - you could probably run forever and get away with it, but it IS a leak. I had more luck w/ Kirk Stowell's solution, which appears as a comment under Oleg Galkin's snippet. Rather than trying to move views around, simply create those you will need for the various orientations, then hide / show rows/columns to get the desired effect.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds