Toggling the Splitter Orientation | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.