📄 inifile.cpp
字号:
// IniFile.cpp: implementation of the CIniFile class.
/********************************************************************************
//解析INI文件
// Written by: YiJian Feng
// Email: netfyee@hotmail.com
// Last Edit: 2003-5-1
---使用
首先必须设置
BOOL SetFileName(CString FileName);
BOOL SetSectionName(CString SectionName);
**********************************************************************************/
#include "stdafx.h"
#include "IniFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////
// Construction/Destruction
/////////////////////////////////////////////////////////////////////
//default constructor
CIniFile::CIniFile()
{
pSl=NULL;
m_szSectionName="";
m_szFileName="";
}
//constructor, can specify pathname here instead of using SetFileName later
CIniFile::CIniFile(CString FileName)
{
pSl=NULL;
m_szSectionName="";
m_szFileName = FileName;
}
//default destructor
CIniFile::~CIniFile()
{
if(pSl)
{
delete pSl;
pSl=NULL;
}
}
/////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////
BOOL CIniFile::SetFileName(CString FileName)
{
m_szFileName = FileName;
return TRUE;
}
CString CIniFile::GetFileName()
{
return m_szFileName;
}
BOOL CIniFile::GetIniValues(CString &value, CString keys, CString DefaultValue)
{
TCHAR str[MAX_PATH];
::GetPrivateProfileString(m_szSectionName, keys,DefaultValue,str,MAX_PATH,m_szFileName);
value = str;
return TRUE;
}
//Set
BOOL CIniFile::SetSectionName(CString SectionName)
{
m_szSectionName = SectionName;
return TRUE;
}
CString CIniFile::GetSectionName()
{
return m_szSectionName;
}
BOOL CIniFile::GetIniValues(UINT &value, CString keys, INT DefaultValue)
{
value = ::GetPrivateProfileInt(m_szSectionName, keys,DefaultValue, m_szFileName);
return TRUE;
}
BOOL CIniFile::SetIniValues(CString value, CString keys)
{
::WritePrivateProfileString(m_szSectionName, keys, value, m_szFileName);
return TRUE;
}
BOOL CIniFile::SetIniValues(int value, CString keys)
{
CString str;
str.Format("%d", value);
::WritePrivateProfileString(m_szSectionName, keys, str, m_szFileName);
return TRUE;
}
BOOL CIniFile::GetSectionValues(CStringList *pSl)
{
TCHAR aaa[BUF_SIZE];
DWORD dwSize=::GetPrivateProfileSection(m_szSectionName, aaa, BUF_SIZE, m_szFileName);
if(dwSize>BUF_SIZE)
{
AfxMessageBox("分配的默认缓冲不够\n请增大IniFile.h-BUF_SIZE");
return FALSE;
}
if (!pSl)
{
pSl=new CStringList();
}
pSl->RemoveAll();
/*没有彻底完成封装*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -