Click here to Skip to main content
15,891,607 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 697.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.
// InputBox.cpp : implementation file
//

#include "stdafx.h"
#include "InputBox.h"
#include "AsNumericEdit.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInputBox dialog


CInputBox::CInputBox(CWnd* pParent /*=NULL*/)
	: CDialog(CInputBox::IDD, pParent),
	txtValue_(NULL),
	stringMode_(false),
	valueDouble_(0),
	precision_(0)
{
	//{{AFX_DATA_INIT(CInputBox)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CInputBox::~CInputBox()
{
	if (txtValue_) {
		if (txtValue_->GetSafeHwnd())
			txtValue_->Detach();
		delete txtValue_;
	}
}

void CInputBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInputBox)
	DDX_Control(pDX, IDC_LBL_CAPTION, lblCaption_);
	//DDX_Control(pDX, IDC_TXT_VALUE, txtValue_);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CInputBox message handlers

void CInputBox::OnOK() 
{
	cmString tmp;

	txtValue_->GetWindowText(tmp);

	if (stringMode_) {
		valueString_ = tmp;
	} else {
		valueDouble_ = tmp;
	}
	
	CDialog::OnOK();
}

void CInputBox::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CInputBox::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	SetWindowText(title_);
	lblCaption_.SetWindowText(caption_);
	
	CWnd* child;
	CRect rc;

	child = GetDlgItem(IDC_TXT_VALUE);
	child->GetWindowRect(rc);
	ScreenToClient(rc);
	if (stringMode_) {
		txtValue_ = new CEdit;
		
		txtValue_->Attach(CreateWindowEx(WS_EX_STATICEDGE, _T("Edit"), _T(""), WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.Width(), rc.Height(), this->m_hWnd, NULL, AfxGetInstanceHandle(), NULL));
		txtValue_->SetWindowText(valueString_);
	} else {
		CAsNumericEdit* numEdit;

		numEdit = new CAsNumericEdit;
		numEdit->Attach(CreateWindowEx(WS_EX_STATICEDGE, _T("Edit"), _T(""), WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.Width(), rc.Height(), this->m_hWnd, NULL, AfxGetInstanceHandle(), NULL));

		numEdit->SetPrecision(precision_);
		numEdit->SetValue(valueDouble_);

		txtValue_ = numEdit;
	}
	txtValue_->SetFont(GetFont());

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

void CInputBox::Init(const cmString& title, const cmString& caption, const cmString& initialValue)
{
	title_ = title;
	caption_ = caption;
	valueString_ = initialValue;

	stringMode_ = true;
}

void CInputBox::Init(const cmString& title, const cmString& caption, double initialValue, int precision)
{
	title_ = title;
	caption_ = caption;
	valueDouble_ = initialValue;
	precision_ = precision;

	stringMode_ = false;
}

cmString CInputBox::GetValueString() const
{
	return valueString_;
}

double CInputBox::GetValueDouble() const
{
	return valueDouble_;
}

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