inifile.h

来自「能够对INI文件方便的读写」· C头文件 代码 · 共 64 行

H
64
字号
// IniFile.h: interface for the CIniFile class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_INIFILE_H__YangZeQuan_163_Com__INCLUDED_)
#define AFX_INIFILE_H__YangZeQuan_163_Com__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdlib.h>
#include <Windows.h>

class CIniFile
{
public:
	CIniFile();
	virtual ~CIniFile();
	
	// 文件
	BOOL	SetFileName(LPCTSTR pszFileName);
	LPCTSTR	GetFileName() const;

	BOOL	SetFileNameByCurDir(LPCTSTR pszTitleName = NULL);
	BOOL	SetFileNameByExeDir(LPCTSTR pszTitleName = NULL);

	// Section
	BOOL	SetSection(LPCTSTR pszSection);
	LPCTSTR	GetSection() const;
	BOOL    DeleteSection(LPCTSTR pszSection);

#ifdef _MFC_VER
	int GetAllSection(CStringArray& arrSection);
	int GetAllKey(CStringArray& arrKey);
#endif

	// Key
	BOOL    DeleteKey(LPCTSTR pszKey);
	
	BOOL	WriteString(LPCTSTR pszKey, LPCTSTR pszValue);
	BOOL	WriteInt(LPCTSTR pszKey, int iValue);
		
	// 取出一个值,如果原来没有此值,则得到的是默认值
	// 如果 bWrite为TRUE, 再将该值保存到文件中
	LPCTSTR GetString(LPCTSTR pszKey, LPCTSTR pszDefult = _T(""), BOOL bWrite = FALSE );
	BOOL   GetString(LPCTSTR pszKey, LPCTSTR pszDefult, LPTSTR pszValue, int iSize);
	int    GetInt(LPCTSTR pszKey, int iDefault = 0, BOOL bWrite = FALSE);
	
private:
	TCHAR m_szFileName[MAX_PATH+1];
	TCHAR m_szSection[MAX_PATH+1];
	TCHAR m_szTempValue[MAX_PATH+1];

public: // 辅助工具函数
#ifdef _MFC_VER
	static int StringSplit(const CString& strSource, const CString& strSplit, CStringArray& arrResult, BOOL bTrim = TRUE);
	static int StringSplitEx(LPCTSTR pszSource, LPCTSTR pszMultiSplit, CStringArray &arrResult, BOOL bTrim = TRUE);
#endif	
	static BOOL CreateDirectoryEx(LPCTSTR pszPath);
};

#endif // !defined(AFX_INIFILE_H__YangZeQuan_163_Com__INCLUDED_)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?