config.cpp

来自「SIGP的短信开发API包」· C++ 代码 · 共 72 行

CPP
72
字号
/**
*	config.cpp
*	
*	CMPP3 API Demo Application.
*
*	Copyright 2003-2006	北京风起水流软件工作室
*	
*	http://www.zealware.com
*	
*	princetoad@gmail.com
*
*/

#include "stdafx.h"
#include "config.h"

SMGAppConfig::SMGAppConfig()
{
	m_iniPath = getAppPath();
}

SMGAppConfig::~SMGAppConfig()
{
}

int SMGAppConfig::getConfigKey(CString section, CString configKey, int defaultValue)
{
	char tempChar[MAX_PATH] = "";
	GetPrivateProfileString(section, configKey, "", tempChar, MAX_PATH, m_iniPath);
	defaultValue = atoi(tempChar);
	return defaultValue;
}

CString SMGAppConfig::getConfigKey(CString section, CString configKey, CString defaultValue)
{
	char tempChar[MAX_PATH] = "";
	GetPrivateProfileString(section, configKey, "", tempChar, MAX_PATH, m_iniPath);
	defaultValue = CString(tempChar);
	return defaultValue;
}

CString SMGAppConfig::getAppPath()
{
	char pt[MAX_PATH] = "";
	CString appname = "SGIPAPIDemo";
	GetFullPathName(appname + ".exe", MAX_PATH, pt, NULL);
	CString pathtp(pt);
	pathtp.TrimLeft();
	pathtp.TrimRight();
	int pos = pathtp.ReverseFind('\\');
	pathtp = pathtp.Mid(0, pos);

	CString inipath = "";
	inipath += pathtp;
	inipath += "\\" + appname + ".ini";

	return inipath;
}

BOOL SMGAppConfig::setConfigKey(CString section, CString configKey, CString value)
{
	return WritePrivateProfileString(section, configKey, value, m_iniPath);
}

BOOL SMGAppConfig::setConfigKey(CString section, CString configKey, int value)
{
	CString strValue = _T("");
	strValue.Format("%d", value);

	return WritePrivateProfileString(section, configKey, strValue, m_iniPath);
}

⌨️ 快捷键说明

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