文章标题
来源:互联网 发布:苏联巅峰 知乎 编辑:程序博客网 时间:2024/06/05 15:10
Profile.h
// TextFile.h: interface for the CTextFile class.
//
//////////////////////////////////////////////////////////////////////
if !defined(AFX_TEXTFILE_H__0B34BBD2_9145_4797_9DD1_BF7A9B8B2151__INCLUDED_)
define AFX_TEXTFILE_H__0B34BBD2_9145_4797_9DD1_BF7A9B8B2151__INCLUDED_
if _MSC_VER > 1000
pragma once
endif // _MSC_VER > 1000
include “IniFile.h”
class CGlobalInterface
{
protected:
static CString m_strSdScanDirectory;
static CString m_strLanguage;
public:
static void SetSdScanDirectory(CString szDirectory);
static CString GetSdScanDirectory();
static void SetLanguage(CString szLanguage);
static CString GetLanguage();
public:
static CString m_strEcuId;
/** */static TCHAR * PF_GetWordStr(const char *cStr);/** CString to string*/static char * PF_GetCharStr(const TCHAR *wStr);
};
class CProfile
{
public:
static CString GetString(CString sFile,CString sSect,CString sKey
,CString sDftValue,BOOL bCaseSensitive=TRUE);
static INT GetInteger(CString sFile,CString sSect,CString sKey
,INT nDftValue,BOOL bCaseSensitive=TRUE);
static BOOL WriteString(CString sFile,CString sSect,CString sKey
,CString sValue,BOOL bCaseSensitive=TRUE);
static BOOL WriteInteger(CString sFile,CString sSect,CString sKey
,INT nValue,BOOL bCaseSensitive=TRUE);
private:
static CIniFile m_iniF;
static CString m_sLastFile;
};
endif // !defined(AFX_TEXTFILE_H__0B34BBD2_9145_4797_9DD1_BF7A9B8B2151__INCLUDED_)
Profile.cpp
include “stdafx.h”
include “Profile.h”
ifdef _DEBUG
undef THIS_FILE
static char THIS_FILE[]=FILE;
define new DEBUG_NEW
endif
CString CGlobalInterface::m_strSdScanDirectory;
CString CGlobalInterface::m_strLanguage;
define PLATFORM_MAX_BUFFER 4096
TCHAR g_WordBuf[PLATFORM_MAX_BUFFER];
char g_CharBuf[PLATFORM_MAX_BUFFER];
TCHAR * CGlobalInterface::PF_GetWordStr(const char *cStr)
{
int wlen;
wlen=MultiByteToWideChar(CP_ACP,0,cStr,strlen(cStr), (LPWSTR)g_WordBuf,PLATFORM_MAX_BUFFER);g_WordBuf[wlen]=_T('\0');return g_WordBuf;
}
char * CGlobalInterface::PF_GetCharStr(const TCHAR *wStr)
{
int len;
len=WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wStr, wcslen((const wchar_t *)wStr), g_CharBuf, PLATFORM_MAX_BUFFER, NULL, NULL);g_CharBuf[len]='\0';return g_CharBuf;
}
/*—————————————————————————–
功 能:设置显示程序工作目录
参数说明:CString pDirectory-指向工作目录的指针
返 回 值:无
说 明:无
—————————————————————————–*/
void CGlobalInterface::SetSdScanDirectory(CString pDirectory)
{
m_strSdScanDirectory = pDirectory;
}
/*—————————————————————————–
功 能:取得显示程序工作目录
参数说明:无
返 回 值:工作目录绝对路径名
说 明:无
—————————————————————————–*/
CString CGlobalInterface::GetSdScanDirectory()
{
return m_strSdScanDirectory;
}
/*—————————————————————————–
功 能:设置语言代码
参数说明:CString pLanguage-指向设置语言代码字符串的指针
返 回 值:无
说 明:无
—————————————————————————–*/
void CGlobalInterface::SetLanguage(CString pLanguage)
{
m_strLanguage = pLanguage;
}
/*—————————————————————————–
功 能:取得语言代码
参数说明:无
返 回 值:语言代码字符串
说 明:无
—————————————————————————–*/
CString CGlobalInterface::GetLanguage()
{
return m_strLanguage;
}
/static /CIniFile CProfile::m_iniF;
/static /CString CProfile::m_sLastFile(SZ_EMPTY);
/*—————————————————————————–
功 能:读取配置串
参数说明:CString sFile 配置文件名,
CString sSect 段名,
CString sKey 键值,
CString sDftValue 缺省串
返 回 值:读入的字符串
说 明:无
—————————————————————————–*/
/static /
CString CProfile::GetString(CString sFile,CString sSect,CString sKey
,CString sDftValue,BOOL bCaseSensitive/=TRUE/)
{
// sanity check
if(sFile.IsEmpty()||sSect.IsEmpty()||sKey.IsEmpty())
{
return sDftValue;
}
if(sFile.CompareNoCase(m_sLastFile)!=0){ if(m_iniF.ReadFile(CGlobalInterface::PF_GetCharStr(sFile),bCaseSensitive)) { m_sLastFile = sFile; } else { return sDftValue; }}string s_sect = CGlobalInterface::PF_GetCharStr(sSect);string s_key = CGlobalInterface::PF_GetCharStr(sKey);string s_dft_v = CGlobalInterface::PF_GetCharStr(sDftValue);LPCSTR lpStrRet = m_iniF.GetValue(s_sect.c_str(),s_key.c_str(),s_dft_v.c_str(),bCaseSensitive);return (CString)lpStrRet;
}
/*—————————————————————————–
功 能:读取配置数
参数说明:CString sFile 配置文件名,
CString sSect 段名,
CString sKey 键值,
INT iDefaultValue 缺省值
返 回 值:读入的数值
说 明:无
—————————————————————————–*/
/static /
INT CProfile::GetInteger(CString sFile,CString sSect,CString sKey,INT nDftValue
,BOOL bCaseSensitive/=TRUE/)
{
CString s_dft_value;
s_dft_value.Format(_T(“%d”),nDftValue);
CString s_value = GetString(sFile,sSect,sKey,s_dft_value,bCaseSensitive);return atoi(CGlobalInterface::PF_GetCharStr(s_value));
}
/*—————————————————————————–
功 能:写入配置串
参数说明:CString sFile 配置文件名,
CString sSect 段名,
CString sKey 键值,
CString sValue 写入串
返 回 值:成功–TRUE 失败–FALSE
说 明:无
—————————————————————————–*/
/static /
BOOL CProfile::WriteString(CString sFile,CString sSect,CString sKey
,CString sValue,BOOL bCaseSensitive/=TRUE/)
{
// sanity check
if(sFile.IsEmpty()) return FALSE;
if(sSect.IsEmpty()) return FALSE;
if(sKey.IsEmpty()) return FALSE;
if(m_iniF.ReadFile(CGlobalInterface::PF_GetCharStr(sFile),bCaseSensitive)){ m_sLastFile = sFile;}else{ return FALSE;}// always create new if section/key's not existedstring s_sect = CGlobalInterface::PF_GetCharStr(sSect);string s_key = CGlobalInterface::PF_GetCharStr(sKey);string s_v = CGlobalInterface::PF_GetCharStr(sValue);BOOL bRet = m_iniF.SetValue(s_sect.c_str(),s_key.c_str(),s_v.c_str(),TRUE,bCaseSensitive);if (!bRet){ return bRet;}// have to write to file every timebRet = m_iniF.WriteFile(CGlobalInterface::PF_GetCharStr(m_sLastFile));if (!bRet){ return bRet;} return TRUE;
}
/*—————————————————————————–
功 能:写入配置数
参数说明:CString sFile 配置文件名,
CString sSect 段名,
CString sKey 键值,
INT nValue 写入值
返 回 值:成功–TRUE 失败–FALSE
说 明:无
—————————————————————————–*/
/static /
BOOL CProfile::WriteInteger(CString sFile,CString sSect,CString sKey,INT nValue
,BOOL bCaseSensitive/=TRUE/)
{
CString s_value;
s_value.Format(_T(“%d”),nValue);
return WriteString(sFile,sSect,sKey,s_value,bCaseSensitive);
}
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 数码管显示时钟
- 匈牙利算法
- cURL实现模拟登陆+抓取数据
- hybris中配置热部署
- CF 397 C. Table Tennis Game 2
- 文章标题
- angular2中onresize 多次调用 问题
- 【Socket编程一】Java Socket编程入门介绍
- cubemx_systic定时器
- Html中JavaScript对表格的控制,行和列的增删
- 最简单服务器程序UDP(Linux)
- 各种排序算法时间复杂度和空间复杂度表
- learnLinux_命令_1
- Gym 100712K Runtime Error