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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds