关于ini文件的存储于加载,初次遇到,刚接触ini文件,我想我该把它记下,以后提醒自己要常用。
参数保存:
// 参数结构体
struct TextConfig
{
int nVol; //音量
int nStatus; //状态
int nMode; //模式
int nIndex; //序号
};
/* 保存参数*/
int SaveConfig()
{
char szPath[MAX_PATH] = {"swtextplayer.ini"};
FILE* pFile = NULL;
pFile = fopen(szPath, "wb");
if (pFile)
{
TextConfig tcfg;
memset(&tcfg,0, sizeof(tcfg));
tcfg.nVol = m_nVol;
tcfg.nPlayStatus= m_nStatus;
tcfg.nPlayMode = m_nMode;
tcfg.nPlayIndex = m_nCurrentIndex;
fwrite(&tcfg,sizeof(char), sizeof(tcfg), pFile);
fclose(pFile);
}
return 1;
}
/*参数加载*/
int LoadConfig()
{
char szPath[MAX_PATH] = {"swtextplayer.ini"};
FILE* pFile = NULL;
pFile = fopen(szPath, "rb");
if (pFile)
{
TextConfig tcfg;
memset(&tcfg,0, sizeof(tcfg));
fread (&tcfg,sizeof(char), sizeof(tcfg), pFile);
fclose(pFile);
m_nVol = tcfg.nVol ;
m_nStatus = tcfg.nPlayStatus;
m_nMode = tcfg.nPlayMode;
m_nCurrentIndex = tcfg.nPlayIndex;
}
return 1;
}