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

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds