Click here to Skip to main content
15,897,291 members
Articles / Desktop Programming / MFC

CSSplitter: A Splitter with the Ability to Save/Restore its Position

Rate me:
Please Sign up or sign in to vote.
4.89/5 (56 votes)
29 Sep 2018GPL33 min read 140.7K   7.2K   75  
A splitter control derived from CStatic for dialog controls, and that can be used not only within the restricted splitter pane.
// Page1.cpp : implementation file
//

#include "stdafx.h"
#include "SSTest.h"
#include "Page1.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPage1 property page

IMPLEMENT_DYNCREATE(CPage1, CPropertyPage)

CPage1::CPage1() : CPropertyPage(CPage1::IDD)
{
	//{{AFX_DATA_INIT(CPage1)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CPage1::~CPage1()
{
}

void CPage1::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPage1)
	DDX_Control(pDX, IDC_PAGE1_EDIT, m_EditDlg);
	DDX_Control(pDX, IDC_PAGE1_LIST, m_ListDlg);
	DDX_Control(pDX, IDC_PAGE1_TREE, m_TreeDlg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPage1, CPropertyPage)
	//{{AFX_MSG_MAP(CPage1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPage1 message handlers

BOOL CPage1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	CRect rect;
	CWnd* pWnd = GetDlgItem(IDC_PAGE1_STATIC);
	pWnd->GetWindowRect(&rect);
	ScreenToClient(&rect);
	pWnd->DestroyWindow();

	m_LeftDlgSplitterPane.Create(
		WS_CHILD|WS_VISIBLE|/*WS_BORDER|*/WS_CLIPCHILDREN|SS_HORIZ, 		 
		this,
		&m_ListDlg,
		&m_EditDlg,
		IDC_HORIZ_PAGE1,
		rect
	);
	
	m_MainDlgSplitterPane.Create(
		WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPCHILDREN|SS_VERT, 		 
		this,
		&m_TreeDlg,
		&m_LeftDlgSplitterPane,
		IDC_VERT_PAGE1,
		rect,
		80,	// m_nMaxLeft	value
		140 // m_nMaxRight	value
	);	


	m_EditDlg.SetWindowText(_T("Edit Control"));


	m_imgList.Create( IDB_TREE, 16, 3, RGB(192,192,192) );
	m_TreeDlg.SetImageList( &m_imgList, TVSIL_NORMAL );
	m_ListDlg.SetImageList( &m_imgList, LVSIL_SMALL );
	
	CString str;
	HTREEITEM hRoot = m_TreeDlg.InsertItem( "Root", 1, 1 );
	for ( int i = 0; i < 10; i++ ){
		str.Format("%s%d", "Tree_Item_", i+1);   
		m_TreeDlg.InsertItem( str, 0, 1, hRoot );
	}
	m_TreeDlg.Expand( hRoot, TVE_EXPAND );

	for ( i = 0; i < 10; i++ ){
		str.Format("%s%d", "List_Item_", i+1);   
		m_ListDlg.InsertItem( i, str, 2 );
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Ukraine Ukraine
PhD in Physics.
Fields of interest: C/C++, GUI application development using VC++ and MFC; databases such as MS SQL Server, MS Access, and MySQL; Web site development.

Comments and Discussions