A tab-like sheet control







Download Source Code and Examples


To add the sheet control to CChildFrame in a MDI application:

  1. add a new member CSheetsWnd m_wndSheets to CChildFrame class.
  2. override CChildFrame::OnCreateClient, and inside the function call m_wndSheets.Attach(this). From this moment all child windows from CChildFrame are put in sheet the contol, each view with one page.

To add the sheet control to a CDialog:

  1. add a new member CSheetsWnd m_wndSheets to your dialog class.
  2. create n dialogs in resource editor, each with the WS_CHILD style.
  3. declare n dialog members in you dialog. One of these dialogs must be created with WS_VISIBLE style.
  4. overwrite OnInitDialog in your dialog class, and add m_wndSheets.Attach(this).
  5. call the Create function for each dialog declared as a member variable. (m_dlg1.Create(IDD_DIALOG1, this));

Suppose that your dialog contains one button IDOK and a button IDCANCEL. These buttons are children of your dialog. To eliminate the buttons from the pages sheet control you must derive a new class CSheetsDialog, and overwrite GetFirstView(), GetNextView() virtual functions from CSheetsWndas shown below. Of course, the variable type of m_wndSheets must be changed to the new class CSheetDialog.

The class CSheetsWnd could be easily extended with more features. I will try to put more features to this class.

// Declare this struct for store a set of ID's control. 
struct SCtrlID 
{ 
	CMap m_mapCtrlIDs; 
	SCtrlID() 
	{ 
		m_mapCtrlIDs[IDOK] = TRUE; 
		m_mapCtrlIDs[IDCANCEL] = TRUE; 
	}; 

	// Check if ID is in map or not. 
	BOOL Is(UINT id) 
	{ 
	BOOL bValue = TRUE; 
	return m_mapCtrlIDs.Lookup(id, bValue); 
	} 
 }; 

 // class CSheetsDialog header 
 class CSheetsDialog : public CSheetsWnd 
 { 
 public: 
	 CSheetsDialog(); 
	virtual ~CSheetsDialog(); 
	virtual CWnd* GetNextView(); 
	virtual CWnd* GetFirstView(); 

 private: 
	CWnd* GetNextViewValid(CWnd* pWnd); 
	static SCtrlID m_ctrlID; 
 }; 

 // class CSheetsDialog implementation 
 SCtrlID CSheetsDialog::m_ctrlID; 

 CSheetsDialog::CSheetsDialog() 
 { 
 } 

 CSheetsDialog::~CSheetsDialog() 
 { 
 } 

 CWnd* CSheetsDialog::GetFirstView() 
 { 
	return GetNextViewValid(CSheetsWnd::GetFirstView()); 
 } 

 CWnd* CSheetsDialog::GetNextView() 
 { 
	return GetNextViewValid(CSheetsWnd::GetNextView());; 
 } 

 // Scan if ID of pWnd is not in IDOK or IDCANCEL 
 CWnd* CSheetsDialog::GetNextViewValid(CWnd * pWnd) 
 { 
	while (pWnd && (m_ctrlID.Is(pWnd->GetDlgCtrlID()))) 
		pWnd = CSheetsWnd::GetNextView(); 
	return pWnd; 
 } 

Last updated: 12 August 1998



Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: November 13, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT APIs can be a great source of competitive advantage. The practice of exposing backend services as APIs has become pervasive, however their use varies widely across companies and industries. Some companies leverage APIs to create internal, operational and development efficiencies, while others use them to drive ancillary revenue channels. Many companies successfully support both public and private programs from the same API by varying levels …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds