IniFile.h 2.92 KB

#if !defined(AFX_INIFILE_H__INCLUDED_)
#define AFX_INIFILE_H__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//include header file here
#include <afxtempl.h>
/*
int ,long , long long类型的范围值
unsigned   int   0~4294967295   
int   2147483648~2147483647 
unsigned long 0~4294967295
long   2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:18446744073709551615
 __int64的最大值:9223372036854775807
 __int64的最小值:-9223372036854775808
 unsigned __int64的最大值:18446744073709551615
*/

class CIniFile
{
public:
	CIniFile(void);
	CIniFile(LPCTSTR strFileName);
	~CIniFile(void);

private:
	CString	m_strFileName;

public:
	void SetIniFileName(LPCTSTR strFileName);
	
	LPCTSTR GetIniFileName();

	BOOL WriteString(LPCTSTR strSection, LPCTSTR strKey, LPCTSTR strValue);
	BOOL WriteInt(LPCTSTR strSection, LPCTSTR strKey, int iValue);
	//默认保持6位小数点,可以修改
	BOOL WriteDouble(LPCTSTR strSection, LPCTSTR strKey, double fValue);
	//默认保持6位小数点,可以修改
	BOOL WriteFloat(LPCTSTR strSection, LPCTSTR strKey, float fValue);
	BOOL WriteLong(LPCTSTR strSection, LPCTSTR strKey, long n32Value);
	BOOL WriteDWORD(LPCTSTR strSection, LPCTSTR strKey, DWORD u32Value);
	//true--1 false--0
	BOOL WriteBool(LPCTSTR strSection, LPCTSTR strKey, bool bValue);
	
	CString ReadString(LPCTSTR strSection, LPCTSTR strKey, CString strDefault = "ERROR");
	int ReadInt(LPCTSTR strSection, LPCTSTR strKey, int iDefault = -9999999);
	double ReadDouble(LPCTSTR strSection, LPCTSTR strKey, double fDefualt = -0.000001);
	long ReadLong(LPCTSTR strSection, LPCTSTR strKey, long n32Defualt = -9999999);
	DWORD ReadDWORD(LPCTSTR strSection, LPCTSTR strKey, DWORD u32Defualt = 9999999);
	float ReadFloat(LPCTSTR strSection, LPCTSTR strKey, float fDefualt = -0.000001);

	//1为true,其它值为false
	bool ReadBool(LPCTSTR strSection, LPCTSTR strKey, bool bDefualt = false);
	
	//删除某个sectionsection
	BOOL DeleteSection(LPCTSTR strSection);

	//删除某个Section下的某个Key
	BOOL DeleteKey(LPCTSTR strSection,LPCTSTR strKey);

	// 获取所有的Section的列表
	//parameters:
	//CStringArray &SectionList -- 获取到的Section列表(out)
	BOOL GetSectionList(CStringArray &SectionList);
	//获取某个Section下的Key的列表
	//parameters:
	//LPCTSTR strSection --  Section(in)
	//CStringArray &keylist -- 获取到的key 列表(out)
	BOOL GetKeyList(LPCTSTR strSection,CStringArray &KeyList);

	//写Section
	//parameters:
	//LPCTSTR strSection --  Section(in)
	//CStringArray &keylist -- key 列表(in)
	//CStringArray &valuelist -- 对应key的值(in)
	BOOL WriteSection(LPCTSTR strSection,CStringArray &keylist,CStringArray &valuelist);

	//读Section
	//parameters:
	//LPCTSTR strSection --  Section(in)
	//CStringArray &keylist -- key 列表(out)
	//CStringArray &valuelist -- 对应key的值(out)
	BOOL ReadSection(LPCTSTR strSection,CStringArray &keylist,CStringArray &valuelist);
	/**/
};
#endif//#if !defined(AFX_INIFILE_H__INCLUDED_)