我在基本对话框上面加两个Radio Button控件,分别为Radio1,Radio2我想实现的功能是:    如果运行程序选中Radio1,则以后每次运行程序都会默认选中Radio1,如果运行程序选中Radio2,则以后每次运行程序都会默认选中Radio2,概括来说就是每次运行程序后默认选中的是上次程序结束时选中的Radio Button控件。我想通过用.ini文件保存控件信息的方法实现这个功能,但是不知道怎么写,请高手们详细指点,一定要详细啊!

解决方案 »

  1.   

    GetPrivateProfileInt 从私有初始化文件获取整型数值
    GetPrivateProfileString 从私有初始化文件获取字符串型值
    WritePrivateProfileString 写字符串到私有初始化文件
      

  2.   

    char pBuf[512];
    memset(pBuf, 0xCC, sizeof(char)*512);
    ::GetCurrentDirectory(sizeof(char)*512,pBuf);
    CString strPath(pBuf);
    strPath += "\\config.ini";//配置文件名,可以任意写
    //读取选中的按钮,当对话框初始化时调用。
    int iReturn = ::GetPrivateProfileInt("状态","选中",0,strPath);
    //设置选中的按钮,当对话框退出时调用
    假如选中的是m_iSelectOk = 1
    CString str = "";
    str.Format("%d",m_iSelectOk);
    ::WritePrivateProfileString("状态","选中",str,strPath);
      

  3.   

    每次选中是把结果写到文件,每次程序运行从文件中读出标识知道上次选中那个CHECK然后把其置为TURE:下面是把文件自动写到SYSTEM32下的代码:
    写文件:
    //得到系统盘路径
    CString mFilename;
    char systempath[100];
    ::GetSystemDirectory(systempath,50); CString m_strfname;
    CString newdata;
    CString curfilename;
    CString curfilpath;
    //curfilpath = GetCurPath();
    curfilpath = systempath;
    curfilename = "\\servermarshal.ini";
    m_strfname = curfilpath + curfilename;
    //在指定位置创建一个文件
    CStdioFile m_file(m_strfname,CFile::modeCreate|CFile::modeWrite);
    //设置文件长度,
    m_file.SetLength(0);
    //将结点表内容写入指定文件
    m_file.WriteString(strFLG);
    //关闭文件
    m_file.Close(); 读://得到系统盘路径
    CString mFilename;
    char systempath[100];
    ::GetSystemDirectory(systempath,50); CString m_strfname;
    CString newdata;
    CString curfilename;
    CString curfilpath;
    //curfilpath = GetCurPath();
    curfilpath = systempath;
    curfilename = "\\servermarshal.ini";
    m_strfname = curfilpath + curfilename;
    char m_str3[200];
    CFile fis; fis.Open(m_strfname,CFile::modeRead|CFile::typeBinary); if(!fis)
    {
    AfxMessageBox("FAILEDD");
    exit(1);
    }
    else
    {
    int m_newinflongth = fis.Read(m_str3,100);
    m_str3[m_newinflongth]='\0'; newdata = m_str3;
    //AfxMessageBox(newdata);
    }