posts - 131, comments - 12, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

读写配置文件(ini)

Posted on 2012-10-18 09:53 盛胜 阅读(338) 评论(0)  编辑 收藏 引用
void CReadWriteIniDlg::OnBnClickedButtonWrite()
{
// TODO: 在此添加控件通知处理程序代码
strName="小米";
Age=2;
strAge.Format("%d",Age);
BOOL bl;
bl=WritePrivateProfileString("information","Name",strName,"E:\\盛胜\\ini\\config.ini");
//::WritePrivateProfileString("information","Name","AK","E:\\盛胜\\ini\\config.ini");
bl=FALSE;
bl=WritePrivateProfileString("information","Age",strAge,"E:\\盛胜\\ini\\config.ini");
}
void CReadWriteIniDlg::OnBnClickedButtonRead()
{
// TODO: 在此添加控件通知处理程序代码
CString strNameR,strAgeR;
GetPrivateProfileString("information","Name","default",strNameR.GetBuffer(MAX_PATH),MAX_PATH,"E:\\盛胜\\ini\\config.ini");
GetPrivateProfileString("information","Age","default",strAgeR.GetBuffer(MAX_PATH),MAX_PATH,"E:\\盛胜\\ini\\config.ini");
//GetBuffer申请申空间
//使用完GetBuffer后,必须使用ReleaseBuffer以更新对象内部数据,否则会发生无法预料的结果。
strNameR.ReleaseBuffer();
strAgeR.ReleaseBuffer();
CString strinfo;
strinfo.Format("information\n%s\n%s",strNameR,strAgeR);
GetDlgItem(IDC_STATIC_READ)->SetWindowText(strinfo);
}
/*
GetPrivateProfileString(
    __in_opt LPCSTR lpAppName,
    __in_opt LPCSTR lpKeyName,
    __in_opt LPCSTR lpDefault,
    __out_ecount_part_opt(nSize, return + 1) LPSTR lpReturnedString,
    __in     DWORD nSize,
    __in_opt LPCSTR lpFileName
    );
例子:GetPrivateProfileString("information","Name","default",strNameR.GetBuffer(MAX_PATH),MAX_PATH,"E:\\盛胜\\ini\\config.ini");
*/
/*
WritePrivateProfileString(
    __in_opt LPCSTR lpAppName,
    __in_opt LPCSTR lpKeyName,
    __in_opt LPCSTR lpString,
    __in_opt LPCSTR lpFileName
    );.
例子:WritePrivateProfileString("information","Name",strName,"E:\\盛胜\\ini\\config.ini");
*/

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理