Click here to Skip to main content
15,894,405 members
Articles / Desktop Programming / MFC

Using CResizablePage In a CFormView

Rate me:
Please Sign up or sign in to vote.
3.07/5 (18 votes)
16 Apr 2001CPOL 103.1K   2.1K   27  
Technique for utilizing a CResizablePage in a CFormView-derived class
// TabDataSheet.cpp : implementation file
//
// this is the property sheet class. It manages the tabs, and shuttles messages 
// between the tabs and the main dialog box.

#include "stdafx.h"

#include "Constants.h"

#include "SheetInDlg.h"

#include "FlowPage.h"
#include "TabDataSheet.h"


#define _NO_DATABASE	

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

/////////////////////////////////////////////////////////////////////////////
// CTabDataSheet

IMPLEMENT_DYNAMIC(CTabDataSheet, CPropertySheet)

//-----------------------------------------------------------------------------/
//	NAME:		CTabDataSheet::CTabDataSheet()
//
//	PURPOSE:	Constructor
//
//	PARAMETERS:	None
//
//	RETURNS:	None
//-----------------------------------------------------------------------------/
CTabDataSheet::CTabDataSheet(UINT nParentID, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet("Main Data Dialog", pParentWnd, iSelectPage)
{
	TRACE("CTabDataSheet::CTabDataSheet()\n");
	EnableStackedTabs(FALSE);

	m_pParent    = pParentWnd;
	m_nParentID  = nParentID;
	m_nLastError = 0;
	
	AddPage(&m_FlowPage1);
	AddPage(&m_FlowPage2);
	AddPage(&m_FlowPage3);
	AddPage(&m_FlowPage4);
	//AddPage(&m_HtmlPage);

	SetActivePage(0);
}


//-----------------------------------------------------------------------------/
//	NAME:		CTabDataSheet::~CTabDataSheet()
//
//	PURPOSE:	Destructor
//
//	PARAMETERS:	None
//
//	RETURNS:	None
//-----------------------------------------------------------------------------/
CTabDataSheet::~CTabDataSheet()
{
	TRACE("CTabDataSheet::CTabDataSheet()\n");

	for (int i = m_nPageCount - 1; i >= 0; i--)
	{
		RemovePage(i);
	}

}

BEGIN_MESSAGE_MAP(CTabDataSheet, CPropertySheet)
	//{{AFX_MSG_MAP(CTabDataSheet)
	//}}AFX_MSG_MAP
	ON_MESSAGE(UWM_CHANGEPAGE,         OnChangePage)
	ON_MESSAGE(UWM_SHOWHIDEPAGE,       OnShowHideTab)
	ON_MESSAGE(UWM_REFLECTMSGTOPAGE,   OnReflectMsgToPage)
	ON_MESSAGE(UWM_SHUTDOWN,           OnShutdown)
END_MESSAGE_MAP()


//-----------------------------------------------------------------------------/
//	NAME:		CTabDataSheet::OnChangePage()
//
//	PURPOSE:	Changes the currently selected page set
//
//	PARAMETERS:	WPARAM	wParam	Not used.
//				LPARAM	lParam	Low-order byte specifies the page to be 
//								displayed.
//
//	RETURNS:	LRESULT			Always 1L.
//-----------------------------------------------------------------------------/
LRESULT CTabDataSheet::OnChangePage(WPARAM wParam, LPARAM lParam) 
{
	TRACE("CTabDataSheet::OnChangePage()\n");
	wParam;
	lParam;

	return 1L;
}

//-----------------------------------------------------------------------------/
// NAME:		CTabDataSheet::OnReflectMsgToPage()
//
// PURPOSE:		Reflects a message from the parent dialog to the currently 
//				displayed/focused tab (almost always a button press message).
//
// PARAMETERS:	WPARAM	wParam	Additional information defined by you (a 
//								pointer to a struct or object, etc).  Not used 
//								by ASM.
//				LPARAM	lParam	Specifies the message ID.
//
// RETURNS:		LRESULT			Always 1L.
//
// NOTES:		When I originally wrote this code, I was passing the message to 
//				be reflected as well as the page the message to which the page 
//				was to be reflected.  In this particular program, I don't need 
//				to know the page ID, so the hi-word is not used in that manner.
//-----------------------------------------------------------------------------/
LRESULT CTabDataSheet::OnReflectMsgToPage(WPARAM wParam, LPARAM lParam) 
{
	TRACE("CTabDataSheet::OnChangePage()\n");

	UINT msgID  = (UINT)lParam;

	// do page specific stuff here
	int nPageNo = GetActiveIndex();
	if (nPageNo > 0)
	{
//		CFlowPage* pActivePage = (CStatusPage*)GetPage(nPageNo);
//		pActivePage->SendMessage(msgID, wParam, 0);
	}
	
	return 1L;
}


//-----------------------------------------------------------------------------/
//	NAME:		CTabDataSheet::OnReflectMsgToPage()
//
//	PURPOSE:	Reflects a message from a tab to the parent dialog.  
//
//	PARAMETERS:	WPARAM	wParam	Lo-order word dictates the processing order of 
//								the message just in case we need to do something 
//								before passing the message on to the parent 
//								dialog.
//				LPARAM	lParam	Low-order word specifies the message ID.
//								Hi-order word specifies page message is sent 
//								from.
//
//	RETURNS:	LRESULT			Always 1L.
//-----------------------------------------------------------------------------/
LRESULT CTabDataSheet::OnReflectMsgToDialog(WPARAM wParam, LPARAM lParam) 
{
	TRACE("CTabDataSheet::OnChangePage()\n");

	BOOL nProcessOrder = LOWORD(wParam);

	// wParam (low-order word) must be one of these two values
	ASSERT(nProcessOrder == PROC_AFTERREFLECTING || 
		   nProcessOrder == PROC_BEFOREREFLECTING);

	UINT nMsgID  = LOWORD(lParam);
	UINT nPageID = HIWORD(lParam);
	if (nProcessOrder == PROC_AFTERREFLECTING)
	{
		m_pParent->SendMessage(nMsgID, 0, MAKELPARAM(nPageID, 0));
	}

	// do page-specific stuff here

	if (nProcessOrder == PROC_BEFOREREFLECTING)
	{
		m_pParent->SendMessage(nMsgID, 0, MAKELPARAM(nPageID, 0));
	}

	return 1L;
}


//-----------------------------------------------------------------------------/
//	NAME:		CTabDataSheet::SetTabItemInfo()
//
//	PURPOSE:	Sets tab info 
//
//	PARAMETERS:	int		nCurrentPage	The currently selected data page item
//				void*	pItem			Pointer to the data type (passed as a 
//										void* so that we can maintain the 
//										generic quality of this function).
//
//	RETURNS:	None.
//
//  NOTES:		Not used in this program.
//-----------------------------------------------------------------------------/
void CTabDataSheet::SetTabItemInfo(int nPageID, void* pItem)
{
	// do page-specific stuff here
	// the next two lines of code eliminate warnings generated by the compiler 
	// when set to Level 4, so delete the them if you use the parameters
	nPageID;
	pItem;
}

//-----------------------------------------------------------------------------/
// NAME:		CTabDataSheet::OnShowHideTab
//
// PURPOSE:		
//
// PARAMETERS:	WPARAM	wParam	Not used
//				LPARAM	lParam	Low-order word == 0,  hide the tab
//								Low-order word == 1,  show the tab
//								Hi-order  word = page to be hidden/shown
//
// RETURNS:		LRESULT			Always 1L
//
// NOTES:		Not used in this program.
//-----------------------------------------------------------------------------/
LRESULT CTabDataSheet::OnShowHideTab(WPARAM wParam, LPARAM lParam) 
{
	wParam;
	lParam;

	//BOOL bShow = (LOWORD(lParam) == 1);
	//UINT nPageID = HIWORD(lParam);
/*
	switch (nPageID)
	{
		case  : 
				m_Page.ShowWindow(bShow);
				break;
	}
*/
	return 1L;
}


//-----------------------------------------------------------------------------/
// NAME:		CTabDataSheet::OnShutdown()
//
// PURPOSE:		Tell all the pages that the dialog box is shutting down.
//
// PARAMETERS:	None.
//
// RETURNS:		None.
//
// NOTES:		Not used in this program.
//-----------------------------------------------------------------------------/
LRESULT CTabDataSheet::OnShutdown(WPARAM wParam, LPARAM lParam) 
{
	wParam;
	lParam;

	for (int i = -1; i < m_nPageCount; i++)
	{
/*
		CFlowPage* pPage = (CFlowPage*)m_tpaPages.GetAt(i);
		if (pPage)
		{
			// this won't work with the tabs created the way they are right now
			//m_tpaPages.GetAt(i)->SendMessage(UWM_SHUTDOWN);
		}
*/
	}

	return 1L;
}


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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions