Click here to Skip to main content
15,881,380 members
Articles / Web Development / HTML

A Comprehensive CE Class Library to Replace ATL and MFC

Rate me:
Please Sign up or sign in to vote.
4.48/5 (14 votes)
4 Oct 2000CPOL 277.9K   998   70  
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
#include "stdafx.h"
#include "CeTls.h"
#include "CeProperty.h"

CeTlsSlot s_tlsSheet;

///////////////////////////////////////////////////////////////////////////////
// CePropertySheet
///////////////////////////////////////////////////////////////////////////////

CePropertySheet::CePropertySheet()
{
	memset(&m_psh, 0, sizeof m_psh);
	m_psh.dwSize = sizeof PROPSHEETHEADER;

	m_psh.hInstance = CeGetAppInstance(); 
	m_psh.hIcon = NULL; 
	m_psh.nStartPage = 0;

	m_psh.pfnCallback = CePropertySheet::PropSheetProc;

	m_psh.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE;

	m_psh.nPages = 0;
	m_psh.ppsp = NULL;
}

CePropertySheet::~CePropertySheet()
{
	PROPSHEETPAGE* ppsp = (PROPSHEETPAGE*) m_psh.ppsp;
	if (ppsp)
		delete[] ppsp;
	m_psh.ppsp = NULL;
}


BOOL CePropertySheet::Create(LPCTSTR lpszCaption, HWND hParent)
{
	m_psh.hwndParent = hParent;
	m_psh.pszCaption = lpszCaption; 
	m_psh.dwFlags |= PSH_MODELESS;

	// Setup the pointer in the TLS storage
	s_tlsSheet.SetValue(this);

	VERIFY(m_hWnd == (HWND) ::PropertySheet(&m_psh));

	s_tlsSheet.SetValue(NULL);

	return (NULL != m_hWnd);
}


int CePropertySheet::DoModal(LPCTSTR lpszCaption, HWND hParent)
{
	m_psh.hwndParent = hParent;
	m_psh.pszCaption = lpszCaption; 

	// Setup the pointer in the TLS storage
	s_tlsSheet.SetValue(this);

	int nRet = ::PropertySheet(&m_psh);

	s_tlsSheet.SetValue(NULL);

	if (nRet == ID_PSREBOOTSYSTEM)
		TRACE0("REBOOTSYSTEM!!!!!!!\n");
	else if (nRet == ID_PSRESTARTWINDOWS)
		TRACE0("RestartWindows!!!!!!!\n");

	return nRet;
}

int CePropertySheet::DoWizard(LPCTSTR lpszCaption, HWND hParent)
{
	m_psh.hwndParent = hParent;
	m_psh.pszCaption = lpszCaption; 
	m_psh.dwFlags |= PSH_WIZARD;

	// Setup the pointer in the TLS storage
	ASSERT(s_tlsSheet.GetValue() == NULL);
	s_tlsSheet.SetValue(this);

	int nRet = ::PropertySheet(&m_psh);

	s_tlsSheet.SetValue(NULL);

	if (nRet == ID_PSREBOOTSYSTEM)
		TRACE0("REBOOTSYSTEM!!!!!!!\n");
	else if (nRet == ID_PSRESTARTWINDOWS)
		TRACE0("RestartWindows!!!!!!!\n");

	return nRet;
}


BOOL CePropertySheet::AddPage(CePropertyPage* pPage)
{
	PROPSHEETPAGE* ppsp = (PROPSHEETPAGE*) m_psh.ppsp;

	m_psh.ppsp = new PROPSHEETPAGE[m_psh.nPages + 1];

	if (ppsp)
	{
		memcpy((void*)m_psh.ppsp, ppsp, m_psh.nPages * sizeof(PROPSHEETPAGE));
		delete[] ppsp;
	}

	memcpy((void*)&m_psh.ppsp[m_psh.nPages], &pPage->m_psp, sizeof pPage->m_psp);

	m_psh.nPages++;

	return TRUE;
}


int CALLBACK CePropertySheet::PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
{
	// Setup the pointer in the TLS storage
	CePropertySheet* pSheet = (CePropertySheet*) s_tlsSheet.GetValue();

	switch (uMsg)
	{
	case PSCB_INITIALIZED:
		ASSERT(hwndDlg != NULL);
		//
		pSheet->m_lpfnOldWndProc = (WNDPROC) ::GetWindowLong(hwndDlg, DWL_DLGPROC);
		pSheet->m_hWnd = hwndDlg;
		pSheet->m_bModal = false;	// treat as modal always, EndDialog() isn't proper

		//
		// Note: we can't replace the winproc of the propertysheet
		// by the method we have with all the other windows
		// because the propertysheet uses the DWL_USER data element for
		// it's own evil purposes, so we've just left it alone for now
		//
		// reset the user data (this pointer) and the dialog proc
		//
//		lRet = ::SetWindowLong(hwndDlg, DWL_USER, (LONG) pSheet);
//		::SetWindowLong(hwndDlg, DWL_DLGPROC, (LONG) CeDialog::DlgProc);

		// Hook the window proc too???
		//::SetWindowLong(hwndDlg,GWL_WNDPROC,(LONG)::DefDlgProc);
		break;

	case PSCB_PRECREATE:
		ASSERT(hwndDlg == NULL);
		//
		break;
	}

	// documented as void, so just return 0
	return 0;
}

/* virtual */
BOOL CePropertySheet::OnCommand(WPARAM wParam, LPARAM lParam, bool &bHandled)
{
	TRACE2(_T("OnCommand: wParam: 0x%x, lParam: 0x%x\n"), wParam, lParam);

	return CeDialog::OnCommand(wParam, lParam, bHandled);
}

///////////////////////////////////////////////////////////////////////////////
// CePropertyPage
///////////////////////////////////////////////////////////////////////////////


CePropertyPage::~CePropertyPage()
{
}


void CePropertyPage::CommonConstruct(LPCTSTR lpszTemplateName, LPCTSTR lpszCaption)
{
	memset(&m_psp, 0, sizeof m_psp);
	m_psp.dwSize = sizeof m_psp;

	// Where is the template, and which one
	m_psp.pszTemplate = lpszTemplateName;
	m_psp.hInstance = CeGetAppInstance();

	// the dialog proc for the property sheet, the lparam for WM_INITDIALOG is
	// the PROPERTYWSHEETPAGE structure passed in
	m_psp.pfnDlgProc = CePropertyPage::DlgProc;
	m_psp.lParam = (LPARAM) this;

	if (NULL != lpszCaption)
	{
		// if the user specified a title, set the caption
		m_psp.dwFlags |= PSP_USETITLE;
		m_psp.pszTitle = lpszCaption;
	}

	// Add the callback for the hell of it
	m_psp.dwFlags |= PSP_USECALLBACK;
	m_psp.pfnCallback = CePropertyPage::PropSheetPageProc;
}


//
// Catch messages until a WM_INITDIALOG, at which point we'll pass all processing to
// the CeDialog::DlgProc()
//
/*static*/
BOOL CALLBACK CePropertyPage::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	TRACE(_T("hPage = %x, uMsg = 0x%x, wParam = %x, lParam = %x\n"),
		hDlg, uMsg, wParam, lParam);

	if (WM_INITDIALOG == uMsg)
	{
		PROPSHEETPAGE* pPSP = (PROPSHEETPAGE*) lParam;

		CHW_ASSERT(ISVALIDPTR(pPSP, sizeof(PROPSHEETPAGE)));
		CHW_ASSERT(sizeof(PROPSHEETPAGE) == pPSP->dwSize);

		CeDialog* pDlg = (CeDialog*) pPSP->lParam;

		CHW_ASSERT(ISVALIDPTR(pDlg, sizeof CeDialog));

		// reset the DlgProc() substitute our lParam...
		::SetWindowLong(hDlg, DWL_DLGPROC, (LONG) CeDialog::DlgProc);

		return CeDialog::DlgProc(hDlg, uMsg, wParam, pPSP->lParam);
	}

	//
	// we don't know ANYTHING about this window
	// this normally happens for the WM_SETFONT and 0x210 messages
	//
	//TRACE0("WARNING: Received dialog message from UNKNOWN WINDOW\n");
	return FALSE;
}


UINT CALLBACK CePropertyPage::PropSheetPageProc(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
{
	switch (uMsg)
	{
	case PSPCB_CREATE:
		TRACE0("PSPCB_CREATE\n");
		return 1;

	case PSPCB_RELEASE:
		TRACE0("PSPCB_RELEASE\n");
		break;

	default:
		break;
	}

	return 0;
}


/* virtual */
LRESULT CePropertyPage::OnNotify(int nCtrlId, LPNMHDR pNMH, bool& bHandled)
{
	bHandled = true;

	switch (pNMH->code) 
	{
	case PSN_SETACTIVE:		return OnSetActive();
	case PSN_KILLACTIVE:	return OnKillActive();
	case PSN_APPLY:			return OnApply();
	case PSN_QUERYCANCEL:	return OnQueryCancel();

	case PSN_RESET:			OnReset();			break;
	case PSN_HELP:			OnHelp();			break;

	case PSN_WIZBACK:		OnBack();			break;
	case PSN_WIZNEXT:		OnNext();			break;
	case PSN_WIZFINISH:		OnFinish();			break;
	}

	return CeDialog::OnNotify(nCtrlId, pNMH, bHandled);
}

/* virtual */
BOOL CePropertyPage::OnCommand(WPARAM wParam, LPARAM lParam, bool &bHandled)
{
	TRACE0("CePropertyPage::OnCommand()\n");

	bHandled = true;
	return Default();

	//return CeDialog::OnCommand(wParam, lParam, bHandled);
}

/* virtual */
LRESULT CePropertyPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
{
	switch (uMsg)
	{
	case PSM_QUERYSIBLINGS:
		bHandled = true;
		return OnQuerySiblings(wParam, lParam);
	}
	
	return 1;
}

/* virtual */
BOOL CePropertyPage::OnApply()
{
	// default to OK
	TRACE0("CePropertyPage::OnApply()\n");
	return PSNRET_NOERROR;
}

/* virtual */
BOOL CePropertyPage::OnKillActive()
{
	// allow kill active
	TRACE0("CePropertyPage::OnKillActive()\n");
	return 0;
}

/* virtual */
BOOL CePropertyPage::OnSetActive()
{
	// allow set active
	TRACE0("CePropertyPage::OnSetActive()\n");
	return 0;
}

/* virtual */
LRESULT CePropertyPage::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
	TRACE0("CePropertyPage::OnQuerySiblings()\n");
	return 0;
}

/* virtual */
BOOL CePropertyPage::OnQueryCancel()
{
	TRACE0("CePropertyPage::OnQueryCancel()\n");
	return FALSE;	// allow cancel
}

/* virtual */
void CePropertyPage::OnHelp()
{
	TRACE0("CePropertyPage::OnHelp()\n");
}

/* virtual */
void CePropertyPage::OnBack()
{
	TRACE0("CePropertyPage::OnBack()\n");
}

/* virtual */
void CePropertyPage::OnNext()
{
	TRACE0("CePropertyPage::OnNext()\n");
}

/* virtual */
void CePropertyPage::OnReset()
{
	TRACE0("CePropertyPage::OnReset()\n");
}

/* virtual */
void CePropertyPage::OnFinish()
{
	TRACE0("CePropertyPage::OnFinish()\n");
}

/* virtual */
void CePropertyPage::OnCancel()
{
	// override CeDialog, don't call base class
	// (EndDialog shouldn't be called on a Property Page)
	TRACE0("CePropertyPage::OnCancel()\n");
}

/* virtual */
void CePropertyPage::OnOK()
{
	// override CeDialog, don't call base class
	// (EndDialog shouldn't be called on a Property Page)
	TRACE0("CePropertyPage::OnOK()\n");
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions