Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / ATL

CM_ConfigBuilder 1.2g: Visual Studio 6/Visual Studio 2005/Visual Studio 2008 Code Generator for Application Settings Graphic Management

Rate me:
Please Sign up or sign in to vote.
4.94/5 (126 votes)
12 Feb 2008CPOL17 min read 696.4K   9.8K   262  
CM_ConfigBuilder generates and compiles the required files to manage your application's settings/preferences and to store/retrieve them in XML format.
// PropPage_CppSettings.cpp : implementation file
//

#include "stdafx.h"
#include "AsCfgBuilder.h"
#include "PropPage_CppSettings.h"
#include "XmlProjectSettings_Cpp.h"
#include "XSBrowseFolder.h"
#include "enums.h"

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

#if !defined (BIF_NEWDIALOGSTYLE)
#define BIF_NEWDIALOGSTYLE 64
#endif

/////////////////////////////////////////////////////////////////////////////
// CPropPage_CppSettings property page

IMPLEMENT_DYNCREATE(CPropPage_CppSettings, CPropertyPage)

CPropPage_CppSettings::CPropPage_CppSettings() : 
	CPropertyPage(CPropPage_CppSettings::IDD),
	cppSettings_(NULL)
{
	//{{AFX_DATA_INIT(CPropPage_CppSettings)
	//}}AFX_DATA_INIT
}

CPropPage_CppSettings::~CPropPage_CppSettings()
{
}

void CPropPage_CppSettings::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropPage_CppSettings)
	DDX_Control(pDX, IDC_LBL_RESOURCE_OFFSET, lblResourceOffset_);
	DDX_Control(pDX, IDC_RESOURCE_OFFSET, txtResourceOffset_);
	DDX_Control(pDX, IDC_CMD_BROWSE_PATH2, cmdBrowsePath2_);
	DDX_Control(pDX, IDC_POST_BUILD_DLL_PATH, txtPostBuildPath_);
	DDX_Control(pDX, IDC_TXT_FOLDERS, txtFolders_);
	DDX_Control(pDX, IDC_CHK_ENABLE, chkEnableCpp_);
	DDX_Control(pDX, IDC_GENERATION_PATH, txtGenerationPath_);
	DDX_Control(pDX, IDC_CMD_RESET_SETTINGS, cmdReset_);
	DDX_Control(pDX, IDC_CMD_BROWSE_PATH, cmdBrowsePath_);
	DDX_Control(pDX, IDC_CLASS_PREFIX, txtClassPrefix_);
	DDX_Control(pDX, IDC_CHK_GENERATE_TEST_PROJECT, chkGenerateTestProject_);
	DDX_Control(pDX, IDC_CHK_GENERATE_GUI_CLASSES, chkGenerateGui_);
	DDX_Control(pDX, IDC_CHK_DELETE_PREVIOUSLY_GENERATED_FILES, chkDeleteOldFiles_);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropPage_CppSettings, CPropertyPage)
	//{{AFX_MSG_MAP(CPropPage_CppSettings)
	ON_BN_CLICKED(IDC_CMD_BROWSE_PATH, OnCmdBrowsePath)
	ON_BN_CLICKED(IDC_CHK_GENERATE_TEST_PROJECT, OnChkGenerateTestProject)
	ON_BN_CLICKED(IDC_CHK_GENERATE_GUI_CLASSES, OnChkGenerateGuiClasses)
	ON_BN_CLICKED(IDC_CHK_DELETE_PREVIOUSLY_GENERATED_FILES, OnChkDeletePreviouslyGeneratedFiles)
	ON_EN_CHANGE(IDC_GENERATION_PATH, OnChangeGenerationPath)
	ON_EN_CHANGE(IDC_CLASS_PREFIX, OnChangeClassPrefix)
	ON_BN_CLICKED(IDC_CHK_ENABLE, OnChkEnable)
	ON_BN_CLICKED(IDC_CMD_BROWSE_PATH2, OnCmdBrowsePath2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropPage_CppSettings message handlers

BOOL CPropPage_CppSettings::OnApply() 
{
	StoreData();
	
	return CPropertyPage::OnApply();
}

void CPropPage_CppSettings::SetData(CXmlProjectSettings_Cpp* cppSettings)
{
	cppSettings_ = cppSettings;

	if (GetSafeHwnd())
		DisplaySettings();
}

void CPropPage_CppSettings::StoreData()
{
	assert(cppSettings_);

	if (cppSettings_) {
		CString tmp;

		cppSettings_->SetEnabled(chkEnableCpp_.GetCheck() == TRUE);

		cppSettings_->SetDeleteExistingFiles(chkDeleteOldFiles_.GetCheck() == TRUE);
		cppSettings_->SetGUIGenerationEnabled(chkGenerateGui_.GetCheck() == TRUE);
		cppSettings_->SetTestPrjGenerationEnabled(chkGenerateTestProject_.GetCheck() == TRUE);
	
		txtGenerationPath_.GetWindowText(tmp);
		cppSettings_->SetGenerationPath((const char*)tmp);
		
		txtClassPrefix_.GetWindowText(tmp);
		cppSettings_->SetClassPrefix((const char*) tmp);

		txtPostBuildPath_.GetWindowText(tmp);
		cppSettings_->SetPostBuildPath((const char*)tmp);

		txtResourceOffset_.GetWindowText(tmp);
		cppSettings_->SetResourcesOffset(atoi((const char*)tmp));
	}
}

BOOL CPropPage_CppSettings::OnInitDialog() 
{
	if (!CDialog::OnInitDialog())
		return FALSE;

	DisplaySettings();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPropPage_CppSettings::OnCmdBrowsePath() 
{
	CXSBrowseFolder dlg;
	char path[MAX_PATH];

	// Use the new style
	//dlg.ModifyStyle(BIF_NEWDIALOGSTYLE);
	dlg.SetTitle("Select generation path:");
	
	switch (dlg.Show(GetSafeHwnd(), path)) {
		case CXSBrowseFolder::RET_OK:
			txtGenerationPath_.SetWindowText(path);
			UpdateFoldersDescription();
			break;

		case CXSBrowseFolder::RET_CANCEL:
		case CXSBrowseFolder::RET_NOPATH:
			break;
	}	
}

void CPropPage_CppSettings::OnChkGenerateTestProject() 
{
	SetModified(TRUE);
}

void CPropPage_CppSettings::OnChkGenerateGuiClasses() 
{
	lblResourceOffset_.EnableWindow(chkGenerateGui_.GetCheck());
	txtResourceOffset_.EnableWindow(chkGenerateGui_.GetCheck());

	SetModified(TRUE);
}

void CPropPage_CppSettings::OnChkDeletePreviouslyGeneratedFiles() 
{
	SetModified(TRUE);	
}

void CPropPage_CppSettings::OnChangeGenerationPath() 
{
	SetModified(TRUE);
}

void CPropPage_CppSettings::OnChangeClassPrefix() 
{
	SetModified(TRUE);
}

void CPropPage_CppSettings::DisplaySettings()
{
	if (cppSettings_) {
		char buf[100];

		chkEnableCpp_.SetCheck(cppSettings_->GetEnabled());
		chkDeleteOldFiles_.SetCheck(cppSettings_->GetDeleteExistingFiles());
		chkGenerateGui_.SetCheck(cppSettings_->GetGUIGenerationEnabled());
		chkGenerateTestProject_.SetCheck(cppSettings_->GetTestPrjGenerationEnabled());
	
		txtGenerationPath_.SetWindowText(cppSettings_->GetGenerationPath().c_str());
		txtClassPrefix_.SetWindowText(cppSettings_->GetClassPrefix().c_str());
		txtPostBuildPath_.SetWindowText(cppSettings_->GetPostBuildPath().c_str());
		
		sprintf(buf, "%d", cppSettings_->GetResourcesOffset());
		txtResourceOffset_.SetWindowText(buf);

		((CButton*)GetDlgItem(IDC_CHK_ENABLE))->SetCheck(cppSettings_->GetEnabled());
		UpdateControlsEnable();
		UpdateFoldersDescription();
	}
}

void CPropPage_CppSettings::UpdateControlsEnable()
{
	bool enable;

	enable = ((CButton*)GetDlgItem(IDC_CHK_ENABLE))->GetCheck() == TRUE;

	txtGenerationPath_.EnableWindow(enable);
	txtClassPrefix_.EnableWindow(enable);
	txtPostBuildPath_.EnableWindow(enable);
	txtResourceOffset_.EnableWindow(enable && chkGenerateGui_.GetCheck());
	lblResourceOffset_.EnableWindow(enable && chkGenerateGui_.GetCheck());

	cmdBrowsePath_.EnableWindow(enable);
	cmdBrowsePath2_.EnableWindow(enable);
	cmdReset_.EnableWindow(enable);

	chkDeleteOldFiles_.EnableWindow(enable);
	chkGenerateGui_.EnableWindow(enable);
	chkGenerateTestProject_.EnableWindow(enable);
	
	GetDlgItem(IDC_LBL_GENERATION_PATH)->EnableWindow(enable);
	GetDlgItem(IDC_LBL_CLASS_PREFIX)->EnableWindow(enable);
	GetDlgItem(IDC_LBL_POST_BUILD_PATH)->EnableWindow(enable);
}

void CPropPage_CppSettings::OnChkEnable() 
{
	SetModified();
	UpdateControlsEnable();
}

void CPropPage_CppSettings::UpdateFoldersDescription()
{
	CString generationPath;
	CString description;
	CString sourcePath;
	CString includePath;
	CString libPath;
	CString projectPath;

	txtGenerationPath_.GetWindowText(generationPath);
	
	sourcePath.Format("Source files folder: %s\\src\r\n", (const char*)generationPath);	
	includePath.Format("Header files folder: %s\\include\r\n", (const char*)generationPath);
	libPath.Format("Lib/dll files folder: %s\\lib\r\n", (const char*)generationPath);
	projectPath.Format("Configuration Dll project folder: %s\\project", (const char*)generationPath);

	description +=sourcePath;
	description += includePath;
	description += libPath;
	description += projectPath;

	txtFolders_.SetWindowText(description);
}

void CPropPage_CppSettings::OnCmdBrowsePath2() 
{
	CXSBrowseFolder dlg;
	char path[MAX_PATH];

	// Use the new style
	//dlg.ModifyStyle(BIF_NEWDIALOGSTYLE);
	dlg.SetTitle("Select post build dll destination path:");
	
	switch (dlg.Show(GetSafeHwnd(), path)) {
		case CXSBrowseFolder::RET_OK:
			txtPostBuildPath_.SetWindowText(path);
			UpdateFoldersDescription();
			break;

		case CXSBrowseFolder::RET_CANCEL:
		case CXSBrowseFolder::RET_NOPATH:
			break;
	}	
}

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
Web Developer
Italy Italy
For all Stefano's latest code, binaries and tutorials visit www.codemachines.com

Comments and Discussions