是不是用WriteProfileString这个函数~帮忙指导一下怎么用`

解决方案 »

  1.   

    在退出的时候,用WritePrivateProfileString把其内容保存到文件即可
    看MSDN不就有用法么?为什么需要人指导
      

  2.   

    一般可以保持到注册表或ini文件中。
    普通文件也可以。
      

  3.   

    退出前保存在ini文件中,下次打开时读取就ok了。
      

  4.   

    也可以用读写注册表的方式来实现:
    (1)退出对话框时,将信息写入到注册表中:(通常在IDOK按钮的响应函数中添加)
    AfxGetApp()->WriteProfileString(_T("Settings"),_T("LocalRecPath"),_localRecPath);//_localRecPath就是要保存的信息,Settings为注册表子键,LocalRecPath即子键的键值名
    (2)在打开对话框时,将注册表中的相关信息读出来:(通常在OnInitDialog函数中添加)
    _localRecPath = AfxGetApp()->GetProfileString(_T("Settings"),_T("LocalRecPath"),_T("C:\\"));//_T("C:\\")为默认值
      

  5.   

    1)ini文件/txt文件/二进制文件之类  2)注册表  3)数据库
      

  6.   

    我开始用SetRegistryKey()函数来设置注册键,但这个函数是CWinApp类的protected类型变量,在自定义的类中访问失败,困惑了,用6楼大侠给的建议,也搞定了~我是新手上路,3ks 大家~
      

  7.   

    你可以看看这个:
    void InitParamSetting::ReadLocalSetInfo(moxu::TString userName)
    {
    HKEY hKey;
    DWORD dwDisposition;
    CString strUserName = userName.c_str();
    CString strSubKey = _T("SoftWare\\accvisio\\VStar\\Local Settings\\");
    strSubKey += strUserName;
    long retCreate=(::RegCreateKeyEx
    (HKEY_CURRENT_USER,strSubKey,0,NULL,
    REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition));
    if (retCreate != ERROR_SUCCESS)
    {
    AfxMessageBox(_T("错误:无法创建或打开指定的键或子键!"));
    return;
    }
    else//创建或打开指定的键或子键成功
    {
    if(dwDisposition==REG_CREATED_NEW_KEY)//建立一个新键(使用默认值)
    {
    _localRecPath = _T("C:\\");
    _maxLocalRecTime = 3600;
    _capPicPath = _T("C:\\");
    _vedioWndLabel = _T("%P_%D_%C_%I");
    _pollTime = 5; _snapTargetIsChecked = 1;
    _snapEvenIsChecked = 1;
    _snapBckIsChecked = 1;
    }
    else if(dwDisposition==REG_OPENED_EXISTING_KEY)//打开了一个已经存在的键(读取相关信息)
    {
    int count = 0;
    TCHAR/*char*/ buffer[256];
    DWORD type = REG_SZ;//定义数据类型
    DWORD dataLen = 256;//定义数据长度
    long retQueryValue = ::RegQueryValueEx(hKey,_T("LocalRecPath"),NULL,&type,(BYTE *)buffer,&dataLen);
    if (retQueryValue == ERROR_SUCCESS)
    {
    _localRecPath.Format(_T("%s"),buffer);
    _localRecPath.TrimRight();
    }
    else
    {
    count++;
    } type = REG_DWORD; 
    dataLen = 4;
    retQueryValue = ::RegQueryValueEx(hKey,_T("MaxLocalRecTime"),NULL,&type,(BYTE *)&_maxLocalRecTime,&dataLen);
    if (retQueryValue != ERROR_SUCCESS)
    {
    count++;
    } wmemcpy(buffer,_T(""),128);
    //memcpy(buffer,"",256);
    type = REG_SZ;
    dataLen = 256;
    retQueryValue = ::RegQueryValueEx(hKey,_T("CapPicPath"),NULL,&type,(BYTE *)buffer,&dataLen);
    if (retQueryValue == ERROR_SUCCESS)
    {
    _capPicPath.Format(_T("%s"),buffer);
    _capPicPath.TrimRight();
    }
    else
    {
    count++;
    } wmemcpy(buffer,_T(""),128);
    //memcpy(buffer,"",256);
    type = REG_SZ;
    dataLen = 256;
    retQueryValue = ::RegQueryValueEx(hKey,_T("VedioWndLabel"),NULL,&type,(BYTE *)buffer,&dataLen);
    if (retQueryValue == ERROR_SUCCESS)
    {
    _vedioWndLabel.Format(_T("%s"),buffer);
    _vedioWndLabel.TrimRight();
    }
    else
    {
    count++;
    } type = REG_DWORD;
    dataLen = 4;
    retQueryValue = ::RegQueryValueEx(hKey,_T("PollTime"),NULL,&type,(BYTE *)&_pollTime,&dataLen);
    if (retQueryValue != ERROR_SUCCESS)
    {
    count++;
    } wmemcpy(buffer,_T(""),128);
    //memcpy(buffer,"",256);
    type = REG_SZ;
    dataLen = 256;
    retQueryValue = ::RegQueryValueEx(hKey,_T("RecDownloadPath"),NULL,&type,(BYTE *)buffer,&dataLen);
    if (retQueryValue == ERROR_SUCCESS)
    {
    _recDownloadPath.Format(_T("%s"),buffer);
    _recDownloadPath.TrimRight();
    }
    else
    {
    count++;
    } //读取智能报警图片显示选项设置信息
    type = REG_DWORD;
    dataLen = 4;
    retQueryValue = ::RegQueryValueEx(hKey,_T("SnapTargetIsChecked"),NULL,&type,(BYTE *)&_snapTargetIsChecked,&dataLen);
    if (retQueryValue != ERROR_SUCCESS)
    {
    count++;
    } type = REG_DWORD;
    dataLen = 4;
    retQueryValue = ::RegQueryValueEx(hKey,_T("SnapEvenIsChecked"),NULL,&type,(BYTE *)&_snapEvenIsChecked,&dataLen);
    if (retQueryValue != ERROR_SUCCESS)
    {
    count++;
    } type = REG_DWORD;
    dataLen = 4;
    retQueryValue = ::RegQueryValueEx(hKey,_T("SnapBckIsChecked"),NULL,&type,(BYTE *)&_snapBckIsChecked,&dataLen);
    if (retQueryValue != ERROR_SUCCESS)
    {
    count++;
    } if (count != 0)
    {
    AfxMessageBox(_T("错误:无法查询有关注册表信息"));
    }
    }
    }
    ::RegCloseKey(hKey);
    }
      

  8.   


    void InitParamSetting::WriteLocalSetInfo(moxu::TString userName)
    {
    HKEY hKey;
    CString strUserName = userName.c_str();
    CString strSubKey = _T("SoftWare\\accvisio\\VStar\\Local Settings\\");
        strSubKey += strUserName;
    //strSubKey += _T("\\"); long retOpenKey = ::RegOpenKeyEx(HKEY_CURRENT_USER,strSubKey,NULL,KEY_WRITE,&hKey);
    if (retOpenKey != ERROR_SUCCESS)
    {
    AfxMessageBox(_T("错误:无法打开指定的键或子键!"));
    return;
    } //将本地相关设置写入注册表
    CString strValue;
    int count = 0;
    long retSetValue = ::RegSetValueEx(hKey,_T("LocalRecPath"), NULL, REG_SZ, (LPBYTE)_localRecPath.GetBuffer(0), (_localRecPath.GetLength()+1)*sizeof(TCHAR));
        if (retSetValue != ERROR_SUCCESS)
        {
            count++;
        }

    retSetValue = ::RegSetValueEx(hKey,_T("MaxLocalRecTime"),NULL,REG_DWORD,(LPBYTE)&_maxLocalRecTime,4);
    if (retSetValue != ERROR_SUCCESS)
    {
    count++;
    }

    retSetValue = ::RegSetValueEx(hKey,_T("CapPicPath"),NULL,REG_SZ,(LPBYTE)_capPicPath.GetBuffer(0),(_capPicPath.GetLength()+1)*sizeof(TCHAR));
    if (retSetValue != ERROR_SUCCESS)
    {
    count++;
    } retSetValue = ::RegSetValueEx(hKey,_T("VedioWndLabel"),NULL,REG_SZ,(LPBYTE)_vedioWndLabel.GetBuffer(0),(_vedioWndLabel.GetLength()+1)*sizeof(TCHAR));
    if (retSetValue != ERROR_SUCCESS)
    {
    count++;
    } retSetValue = ::RegSetValueEx(hKey,_T("PollTime"),NULL,REG_DWORD,(LPBYTE)&_pollTime,4);
    if (retSetValue != ERROR_SUCCESS)
    {
    count++;
    } retSetValue = ::RegSetValueEx(hKey,_T("RecDownloadPath"),NULL,REG_SZ,(LPBYTE)_recDownloadPath.GetBuffer(0),(_recDownloadPath.GetLength()+1)*sizeof(TCHAR));
    if (retSetValue != ERROR_SUCCESS)
    {
    count++;
    } //将智能设备报警图片显示设置写入注册表
    retSetValue = ::RegSetValueEx(hKey,_T("SnapTargetIsChecked"),NULL,REG_DWORD,(LPBYTE)&_snapTargetIsChecked,4);
    if (retSetValue == ERROR_SUCCESS)
    {
    if ((_snapTargetIsChecked < 0)||(_snapTargetIsChecked > 1))
    {
    _snapTargetIsChecked = 1;
    }
    }
    else
    {
    count++;
    } retSetValue = ::RegSetValueEx(hKey,_T("SnapEvenIsChecked"),NULL,REG_DWORD,(LPBYTE)&_snapEvenIsChecked,4);
    if (retSetValue == ERROR_SUCCESS)
    {
    if ((_snapEvenIsChecked < 0)||(_snapEvenIsChecked > 1))
    {
    _snapEvenIsChecked = 1;
    }
    }
    else
    {
    count++;
    } retSetValue = ::RegSetValueEx(hKey,_T("SnapBckIsChecked"),NULL,REG_DWORD,(LPBYTE)&_snapBckIsChecked,4);
    if (retSetValue == ERROR_SUCCESS)
    {
    if ((_snapBckIsChecked < 0)||(_snapBckIsChecked > 1))
    {
    _snapBckIsChecked = 1;
    }
    }
    else
    {
    count++;
    } if (count != 0)
    {
    AfxMessageBox(_T("错误:无法设置有关注册表信息"));
    } ::RegCloseKey(hKey);
    }
      

  9.   

    用CxxxApp类的成员函数WriteProfileString与使用API函数的区别在于:
    CxxxApp类的成员函数WriteProfileString生成的子键是位于当前工程注册表结点的第一级目录下的,而使用API函数生成的子键可以放到指定的位置。
      

  10.   

    在退出的时候,用WritePrivateProfileString把其内容保存到文件即可 
    看MSDN不就有用法么?为什么需要人指导