Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / MFC

XDialogImport - How to share dialogs between projects

Rate me:
Please Sign up or sign in to vote.
4.88/5 (28 votes)
18 Jun 2003CPOL8 min read 87.8K   1.4K   68  
XDialogImport describes a simple and effective method for sharing frequently-used dialogs between projects, using some documented and some poorly documented techniques.
#include "stdafx.h"
#include "About.h"
#include "AboutRes.h"
#include "version.h"

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

CAboutDlg::CAboutDlg() : CDialog(_T("IDD_ABOUTBOX"))
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_APP_VERSION, m_Version);
	DDX_Control(pDX, IDC_COPYRIGHT, m_Copyright);
	DDX_Control(pDX, IDC_ABOUT_EMAIL, m_ctrlEmail);
	//}}AFX_DATA_MAP
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CString strTitle;
	if (!strTitle.LoadString(AFX_IDS_APP_TITLE))
		strTitle.Empty();

	CString strCaption;
	strCaption = _T("About ");
	strCaption += strTitle;
	SetWindowText(strCaption);

	// get our version
	WORD wFileVersion[4];
	CVersion version;
	version.Init();
	version.GetFileVersion(&wFileVersion[0], 
						   &wFileVersion[1], 
						   &wFileVersion[2], 
						   &wFileVersion[3]);

#define BETA_VERSION		// usually this define would be in stdafx.h

#ifdef _DEBUG
	CString strDebug(_T("Debug  "));
#else
	CString strDebug(_T(""));
#endif

#ifdef BETA_VERSION
	CString strBeta(_T("beta"));
#else
	CString strBeta(_T(""));
#endif

	CString strVersion = _T("");
	strVersion.Format(_T("%s  Version %d.%d.%d  Build %d  %s%s"),
		strTitle, 
		wFileVersion[0], wFileVersion[1], wFileVersion[2], wFileVersion[3], 
		strDebug, strBeta);
	m_Version.SetWindowText(strVersion);
	TRACE(_T("strVersion=%s\n"), strVersion);

	CString strCopyright(_T(""));
	version.GetLegalCopyright(strCopyright);
	m_Copyright.SetWindowText(strCopyright);

	CString strEmail(_T(""));
	version.GetStringInfo(_T("E-mail"), strEmail);
	TRACE(_T("strEmail=%s\n"), strEmail);

	CString strEmailUrl(_T(""));
	strEmailUrl = _T("mailto:");
	strEmailUrl += strEmail;

	m_ctrlEmail.SetURL(strEmailUrl);
	
	CenterWindow();

	return TRUE;
}

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) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions