wxConfig类学习

http://hi.baidu.com/shiqiang_hx/item/4fb7e7fbb1d9060fc6dc45d2

wxConfigBase是配置类的基类,不能直接使用它,必须使用它的派生类:wxFileConfig或wxRegConfig。

包含文件

<wx/config.h> (to let wxWidgets choose a wxConfig class for your platform)
由wxWidgets根据您的平台选择一个wxConfig类
<wx/confbase.h> (base config class)
基础配置类
<wx/fileconf.h> (wxFileConfig class)
配置文件类
<wx/msw/regconf.h> (wxRegConfig class)
WIN32平台的注册表类

wxFileConfig和wxRegConfig只是在基类的基础上增加了一些方法:
例:wxFileConfig扩充了wxFileConfig::Save和wxFileConfig::SetUmask函数,当然还有两个构造函数:
//构造函数1
wxFileConfig(const wxString& appName = wxEmptyString,
               const wxString& vendorName = wxEmptyString,
               const wxString& localFilename = wxEmptyString,
               const wxString& globalFilename = wxEmptyString,
               long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE,
               const wxMBConv& conv = wxConvAuto());
//构造函数2
#if wxUSE_STREAMS
    // ctor that takes an input stream.
wxFileConfig(wxInputStream &inStream, const wxMBConv& conv = wxConvAuto());
#endif // wxUSE_STREAMS
//结束

示例:(huang liu jing的代码)
    wxFileInputStream is(wxT("config.ini"));
    //上边的is代表input stream
    wxFileConfig *conf = new wxFileConfig(is);

    //wxFileConfig *conf = new wxFileConfig(wxEmptyString, wxEmptyString, wxEmptyString, _T("config_huangliujing.ini"), wxCONFIG_USE_GLOBAL_FILE);
    // right now the current path is '/'
    //上句的解释是,在配置文件中当前的读写路径是根。
    conf->Write(_T("Group/RootEntry"), _T("Example"));

    // go to some other place: if the group(s) don't exist, they will be created

    // create an entry in subgroup
    conf->Write(_T("Group/Subgroup/SubgroupEntry"), 3);
    //注意上行与INI文件中对应的项目
    // '..' is understood
    //conf->Write(_T("../GroupEntry"), 2);

    wxFileOutputStream os(wxT("config.ini"));

    conf->Save(os);
    os.Close();
    delete conf;
//示例结束

//上例config.INI文件的内容:
[Group]
RootEntry=Example
[Group/Subgroup]
SubgroupEntry=3

通过上例,wxConfig类读写的配置信息是采用树形结构组织的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值