Click here to Skip to main content
15,892,965 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 184.2K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
// OptionPage.cpp : implementation file
//

#include "stdafx.h"
#include <afxpriv.h>

#if _MSC_VER > 1200  // VC7
  #include <../src/mfc/afximpl.h>
#else
  #include <../src/afximpl.h>
#endif

#include "OptionPage.h"
#include "OptionSheet.h"

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

AFX_STATIC inline BOOL IsDialogEx(const DLGTEMPLATE* pTemplate)
{
	return ((DLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF;
}


/////////////////////////////////////////////////////////////////////////////
// COptionPage dialog

IMPLEMENT_DYNAMIC(COptionPage, CDialog);

COptionPage::COptionPage()
{
	//{{AFX_DATA_INIT(COptionPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

COptionPage::COptionPage(UINT nIDTemplate, UINT nIDCaption )
: CDialog(nIDTemplate)
{
	CommonConstruct(nIDCaption);
}

COptionPage::COptionPage(UINT nIDTemplate, LPCTSTR caption)
: CDialog(nIDTemplate)
{
  CommonConstruct(0);
  m_Caption = caption;
}

COptionPage::COptionPage(LPCTSTR lpszTemplateName, UINT nIDCaption)
: CDialog(lpszTemplateName)
{
	CommonConstruct(nIDCaption);
}

COptionPage::~COptionPage()
{
}

void COptionPage::CommonConstruct(UINT nIDCaption)
{
	if(NULL != GetTemplateName()) {
		BOOL result;
		DLGTEMPLATE* pTemplate;
		CDialogTemplate tmpl;
		LPWORD pw;

		// Load the template
		result = tmpl.Load(GetTemplateName());
		ASSERT(TRUE == result);

		// Get a pointer to the template memory
		pTemplate = (DLGTEMPLATE*)GlobalLock(tmpl.m_hTemplate);
		pw = (LPWORD)pTemplate;

		// Skip it
		if (IsDialogEx(pTemplate)) {
			pw = (WORD*)((DLGTEMPLATEEX*)pTemplate + 1);
		} else {
			pw = (WORD*)(pTemplate + 1);
		}

		// Skip menu name string or ordinal
		if (*pw == 0xffff) {
			pw += 2; // WORDs
		} else {
			while(*pw++);
		}

		// Skip class name string or ordinal
		if (*pw == 0xffff) {
			pw += 2; // WORDs
		} else {
			while(*pw++);
		}

		// Get the caption string
		m_Caption = (wchar_t*)pw;

		// Unlock the template memory
		GlobalUnlock(tmpl.m_hTemplate);
	}

	if(0 != nIDCaption) {
		m_Caption.LoadString(nIDCaption);
	}
}













BOOL COptionPage::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
	return CDialog::Create(lpszTemplateName, pParentWnd);
}


BOOL COptionPage::Create(UINT nIDTemplate, CWnd* pParentWnd)
{
	return CDialog::Create(nIDTemplate, pParentWnd);
}


BOOL COptionPage::CreateIndirect(LPCDLGTEMPLATE lpDialogTemplate,
								 CWnd* pParentWnd,
								 void* lpDialogInit)
{
	return CDialog::CreateIndirect(lpDialogTemplate, pParentWnd, lpDialogInit);
}


BOOL COptionPage::CreateIndirect(HGLOBAL hDialogTemplate, CWnd* pParentWnd)
{
	return CDialog::CreateIndirect(hDialogTemplate, pParentWnd);
}

#define DEFAULT_STYLE	(WS_CHILDWINDOW |	\
						 WS_OVERLAPPED |	\
						 DS_3DLOOK |		\
						 DS_SETFONT |		\
						 DS_CONTROL)

#define DEFAULT_EXSTYLE	(WS_EX_LEFT |			\
						 WS_EX_LTRREADING |		\
						 WS_EX_RIGHTSCROLLBAR |	\
						 WS_EX_WINDOWEDGE |		\
						 WS_EX_CONTROLPARENT)

struct DLGTEMPLATE2 {
	DLGTEMPLATE	tmpl;
	short	stuff[5];
};

BOOL COptionPage::Create(CRect &rect, CWnd *pParentWnd)
{
	ASSERT_VALID(this);
	ASSERT(NULL != pParentWnd);
	ASSERT_KINDOF(CWnd, pParentWnd);


	LPCSTR			pTmplName;
	BOOL			result;
	LPDLGTEMPLATE	pTemplate;
	CDialogTemplate tmpl;
	DLGTEMPLATE2	localTemplate;

	pTmplName = GetTemplateName();

	if(NULL != pTmplName) {
		// Load the template
		result = tmpl.Load(GetTemplateName());
		if(FALSE == result) {
			return FALSE;
		}

		// Fix up the dialog window styles
		pTemplate = (LPDLGTEMPLATE)GlobalLock(tmpl.m_hTemplate);
	} else {
		pTemplate = (DLGTEMPLATE*)&localTemplate;
		memset(&localTemplate, 0, sizeof(localTemplate));
	}

	if(0xffff == ((DLGTEMPLATEEX*)pTemplate)->signature) {
		((DLGTEMPLATEEX*)pTemplate)->style = DEFAULT_STYLE;
		((DLGTEMPLATEEX*)pTemplate)->exStyle = DEFAULT_EXSTYLE;
	} else {
		pTemplate->style = DEFAULT_STYLE;
		pTemplate->dwExtendedStyle = DEFAULT_EXSTYLE;
	}

	if(NULL != pTmplName) {
		GlobalUnlock(tmpl.m_hTemplate);
		// Create a modaless dialog
		CreateIndirect(tmpl.m_hTemplate, pParentWnd);
	} else {
		// Create a modaless dialog
		CreateIndirect(pTemplate, pParentWnd);
	}

	MoveWindow(rect);

	return (NULL != m_hWnd ? TRUE : FALSE);
}



















void COptionPage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COptionPage)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COptionPage, CDialog)
	//{{AFX_MSG_MAP(COptionPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COptionPage message handlers
void COptionPage::GetCaption(CString &str)
{
  str = m_Caption;
}

BOOL COptionPage::OnInitDialog() 
{
	CDialog::OnInitDialog();
		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void COptionPage::SetModified(BOOL bChanged)
{
	COptionSheet *wnd = (COptionSheet*)GetParent();
	ASSERT(NULL != wnd);
	ASSERT_KINDOF(COptionSheet, wnd);
	wnd->SetModified(bChanged);
}


// HANDLED in COptionSheet
BOOL COptionPage::OnApply()
{
	ASSERT_VALID(this);
	OnOK();
	return TRUE;
}


void COptionPage::OnReset()
{
	ASSERT_VALID(this);
	OnCancel();
}


// HANDLED in COptionSheet
void COptionPage::OnOK()
{
	ASSERT_VALID(this);
	//CDialog::OnOK();
}


// HANDLED in COptionSheet
void COptionPage::OnCancel()
{
	ASSERT_VALID(this);
}


// HANDLED in COptionSheet
BOOL COptionPage::OnSetActive()
{
	ASSERT_VALID(this);
	if (!UpdateData(FALSE))
	{
		TRACE0("UpdateData failed during page activation\n");
		return FALSE;
	}
	return TRUE;
}


// HANDLED in COptionSheet
BOOL COptionPage::OnKillActive()
{
	ASSERT_VALID(this);
	if (!UpdateData())
	{
		TRACE0("UpdateData failed during page deactivation\n");
		return FALSE;
	}
	
	return TRUE;
}


// HANDLED in COptionSheet
BOOL COptionPage::OnQueryCancel()
{
	return TRUE;
}


// HANDLED in COptionSheet
LRESULT COptionPage::OnWizardBack()
{
	return 0;
}

// HANDLED in COptionSheet
LRESULT COptionPage::OnWizardNext()
{
	return 0;
}


// HANDLED in COptionSheet
BOOL COptionPage::OnWizardFinish()
{
	return TRUE;
}

UINT COptionPage::GetIconID()
{
	return 0;
}


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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions