Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / C++

CIni

Rate me:
Please Sign up or sign in to vote.
4.94/5 (57 votes)
13 Nov 200328 min read 256.4K   12.4K   182  
A comprehensive INI file handling class.
// BaseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "inidemo.h"
#include "BaseDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBaseDlg dialog

const int BASES[4] = { 2, 8, 10, 16 }; 

/////////////////////////////////////////////////////////////////////////////
// CInputDlg dialog
CBaseDlg::CBaseDlg(int nBase, CWnd* pParent /*=NULL*/)
	: CDialog(CBaseDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBaseDlg)
	m_nIdx = -1;
	//}}AFX_DATA_INIT
	m_nIdx = Base2Idx(nBase);
}


void CBaseDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBaseDlg)
	DDX_CBIndex(pDX, IDC_COMBO1, m_nIdx);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBaseDlg, CDialog)
	//{{AFX_MSG_MAP(CBaseDlg)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBaseDlg message handlers

int CBaseDlg::Base2Idx(int nBase) const
{
	for (int i = 0; i < 4; i++)
	{
		if (BASES[i] == nBase)
			return i;
	}
	return 2;
}

int CBaseDlg::Idx2Base(int nIdx) const
{
	return (nIdx >= 0 && nIdx < 4) ? BASES[nIdx] : 10;
}

int CBaseDlg::GetBase() const
{
	return Idx2Base(m_nIdx);
}

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

Comments and Discussions