INI文件操作类

#ifndef _LEARN_OBJECT_H_
#define _LEARN_OBJECT_H_

class CIniFile
{
public:
	CIniFile()
	{
	}
	~CIniFile() { }

private:
	wchar_t		m_path[_MAX_FNAME];

public:
	void InitConfigPath(const wchar_t *filePath)
	{
		memset(m_path, 0, sizeof(m_path));
		wcscpy(m_path, filePath);
	}

	// 获取字符串, 返回字符串个数
	int GetObjValue(const wchar_t *section, const wchar_t *firstKey, wchar_t* outValue, int size)
	{
		int nCount = 0;

		if (section && firstKey)
		{
			memset(outValue, 0, sizeof(outValue));
			nCount = GetPrivateProfileString(section, firstKey, L"0", outValue, size, m_path);
		}
		
		return nCount;
	}

	// 获取int型数值, 返回值即获取值
	int GetObjValue(const wchar_t *section, const wchar_t *firstKey)
	{
		int nRet = 0;
		if (section && firstKey)
		{
			nRet = GetPrivateProfileInt(section, firstKey, 0, m_path);
		}

		return nRet;
	}

	// 获取坐标如point=14,13, 返回值高位为x轴坐标,低位为y轴坐标
	DWORD GetObjValuePoint(const wchar_t *section, const wchar_t *firstKey)
	{
		wchar_t			outValue[16] = {0};
		int				nLen = 0;
		int				nCurPos = 0;
		int				x = 0;
		int				y = 0;
		DWORD			dwRet = 0;

		GetPrivateProfileString(section, firstKey, L"0", outValue, 16, m_path);
		nLen = wcslen(outValue);

		for (int i = 0; i < nLen; i++)
		{
			if (outValue[i] == ',')
			{
				outValue[i] = '\0';
				break;
			}
			nCurPos++;
		}

		x = _ttoi(outValue);
		y = _ttoi(&outValue[++nCurPos]);

		dwRet = MAKELONG(y, x);
		return dwRet;
	
	}

	BOOL SetObjValue(const wchar_t *section, const wchar_t *firstKey, const wchar_t* inValue)
	{
		BOOL bRet = FALSE;

		if (section && firstKey)
		{
			bRet = WritePrivateProfileString(section, firstKey, inValue, m_path);
		}

		return bRet;
	}

	BOOL SetObjValue(const wchar_t *section, const wchar_t *firstKey, int nValue)
	{
		BOOL bRet = FALSE;

		if (section && firstKey && (nValue > 0))
		{
			wchar_t szValue[8] = {0};
			swprintf(szValue, L"%d", nValue);
			bRet = WritePrivateProfileString(section, firstKey, szValue, m_path);
		}

		return bRet;
	}

	BOOL WriteObjSection(const wchar_t *section, const wchar_t *string)
	{
		int bRet = FALSE;
		if (!(section && string))
		{
			return FALSE;
		}

		bRet = WritePrivateProfileSection(section, string, m_path);
		return bRet;
	}

	BOOL DeleteObjSection(const wchar_t *section)
	{
		BOOL bRet = FALSE;
		if (section)
		{
			bRet = WritePrivateProfileString(section, NULL, NULL, m_path);
		}

		return bRet;
	}
};

#endif // _LEARN_OBJECT_H_


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值