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

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds