VC如何保存复选框的bool型变量值到ini配置文件中?

请指教
我在vc6.0中建立了基于对话框的MFC应用程序,上面画了很多复选框
我希望这些复选框在我选中后,可以存储到一个ini配置文件中
关闭窗口下次打开也可以调用这个ini文件
可是复选框是bool型的变量怎么保存它的状态呢?CFileDialog是不可以用的吗?
请指教
WritePrivateProfileString
这个我后来是应用了 而且硬是把那个bool型的 存为了Cstring型的
也用了函数GetPrivateProfileString
现在就是不知道怎么用程序让复选框 呈现选中的状态
我的复选框的 bool型变量为m_d1
可是语句m_d1=ture; 应用上去 为什么界面上面的复选框还是没有选中呢

第1个回答  2010-04-20
WritePrivateProfileString 这个API函数可以实现你的愿望,具体查MSDN
可能会用到的另两个函数是:
GetPrivateProfileInt
GetPrivateProfileString

m_d1=ture 之后还有UpdateData(false);
另一种更直接的方法是使用SetCheck()
假如 CheckBox的ID是 IDC_CHECK_VAR ,读到的bool值保存在 bVal 中,则
((CButton*)GetDlgItem(IDC_CHECK_VAR))->SetCheck(bVal)
这样无需更新就能反映 bVal的值

还有就是 为 CheckBox 添加控件类型的变量 如 CButton m_bCheck;
则可以直接 m_bCheck.SetCheck(bVal);

最后,对于bool型的变量 ,用 GetPrivateProfileInt ,读出的值直接转换为bool型变量 , 不要用 GetPrivateProfileString,之所以写的时候用 WritePrivateProfileString 是因为 没有 WritePrivateProfileInt 这样的函数
第2个回答  2010-04-14
bool就当int保存啊

CString GetExePath()
{
CString strPathName;
GetModuleFileName(NULL,strPathName.GetBuffer(256),256);
strPathName.ReleaseBuffer(256);
int nPos = strPathName.ReverseFind('\\');
strPathName = strPathName.Left(nPos + 1);
return strPathName;
}

CString GetConSetting(CString strAppName, CString strKeyName,CString strDefault)
{
const int SIZE = 1000 ;
char szReturn[SIZE] = {0} ;
CString strConFileName = GetExePath() + "con1.ini";
GetPrivateProfileString(strAppName,strKeyName,strDefault,szReturn,SIZE,(LPCTSTR)strConFileName);
return szReturn ;
}

int GetConSetting(CString strAppName, CString strKeyName,int iDefault)
{
CString strDefault;
strDefault.Format("%d",iDefault);
CString strReturn = GetConSetting(strAppName,strKeyName,strDefault);
int iReturn ;
sscanf((LPCTSTR)strReturn,"%d",&iReturn);
return iReturn ;
}

void SetConSetting(CString strAppName, CString strKeyName,CString strValue)
{
CString strConFileName = GetExePath() + "con1.ini";
WritePrivateProfileString(strAppName,strKeyName,strValue,strConFileName);
}

void SetConSetting(CString strAppName, CString strKeyName,int iValue)
{
CString strValue ;
strValue.Format("%d",iValue);
SetConSetting(strAppName,strKeyName,strValue);
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网