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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • One of the most foolproof ways for an online system to confirm, "Is it really you?" is by adding two-factor authentication. Modern two-factor solutions have evolved to support new, complex technology models that change how we use data, including cloud computing and bring-your-own-device (BYOD). However, not all two-factor authentication solutions are created equal. This guide walks through some of the key area of differentiation between two-factor authentication solutions and provides some concrete criteria …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds