1-文件名及文件内容
2-界面设计
3-附源代码
// my fun 2020-10-10
// 获取exe文件的路径
TCHAR* GetAppPath(TCHAR* PathBuf, int BufSize)
{
ZeroMemory(PathBuf, BufSize);
GetModuleFileName(AfxGetApp()->m_hInstance, PathBuf, BufSize-1);
PathRemoveFileSpec(PathBuf);
_tcscat(PathBuf, _T("\\"));
return PathBuf;
}
// 向 ini 文件中写入 int 型的数据,库中没有,故需要自己编写
static void WritePrivateProfileInt(LPCTSTR AppName, LPCTSTR KeyName, int Value, LPCTSTR IniFile)
{
char s[128] = {0};
itoa(Value, s, 10);
WritePrivateProfileString(AppName, KeyName, s, IniFile);
}
void CRWiniDlg::OnBnClickedButtonWrite() // (按键)写入
{
// 获取编辑框的值
CString tmp;
GetDlgItemText(IDC_EDIT_WRITE, tmp);//设置写入旁边的编辑框ID为IDC_EDIT_WRITE
// 保存设置
char m_szAppPath[256] = {0};
GetAppPath(m_szAppPath, sizeof(m_szAppPath));
strcat( m_szAppPath, "Assistor.ini");
WritePrivateProfileString("GLOBAL", "AudioName", tmp, m_szAppPath);//写入string
WritePrivateProfileInt("GLOBAL", "VideoId", 123456, m_szAppPath);//写入int
}
void CRWiniDlg::OnBnClickedButtonRead() // (按键)读出
{
// 读取配置
int m_videotime = 0;
char szTmp[128] = {0};
char m_szAppPath[256] = {0};
GetAppPath(m_szAppPath, sizeof(m_szAppPath));
strcat( m_szAppPath, "Assistor.ini");
GetPrivateProfileString("GLOBAL", "AudioName", "audio", szTmp, sizeof(szTmp)-1, m_szAppPath);//读出string
m_videotime = GetPrivateProfileInt("GLOBAL", "VideoId", 10, m_szAppPath );//读出int
// 将读出的string值放到编辑框
SetDlgItemText(IDC_EDIT_READ, szTmp);//设置读出旁边的编辑框ID为IDC_EDIT_READ
}
// my fun --end