SetRegistryKey的作用

使用CWinApp类的WriteProfileString 、GetProfileString等函数。
1、如果不调用SetRegistryKey(),CWinApp 会把信息保存系统目录的的Test.ini文件中(C:\Windows\Test.ini)
2、如果调用SetRegistryKey(<company name>),CWinApp 会把信息保存系统目录的的注册表中
   HKEY_CURRENT_USER\Software\<company name>\Test\<section name>\<value name>.

注:SetRegistryKey()是CWinApp的保护成员,只能被CWinApp的成员函数调用。而WriteProfileString 、GetProfileString等函数则是公共成员,可以随便调用,一般调用形式如:

theApp->WriteProfileString();      //在Test.cpp中。
AfxGetApp()->WriteProfileString(); 在其它源文件中 

HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\Msg\A

AfxGetApp()->WriteProfileString(L"A",L"B",L"V");

CString set =  AfxGetApp()->GetProfileString(L"A",L"B");



在利用mfc框架的时候,在App应用类的InitInstance()函数中,初始化时总有一个 SetRegistryKey("字符串XXX")。如果你使用注册表保存相关参数,则它为你提供了很便利的方法,当然如果不使用系统注册表,这句可以注释掉。

 

SetRegistryKey 这个函数功能是设置MFC程序的注册表访问键,并把读写 ini 文件的成员函数映射到读写注册表。只要调用一下 SetRegistryKey 并指定注册表键值,那么下面6个成员函数,就被映射到进行注册表读取了~

WriteProfileBinary

Writes binary data to an entry in the application's .INI file.

WriteProfileInt

Writes an integer to an entry in the application's .INI file.

WriteProfileString

Writes a string to an entry in the application's .INI file.

 

GetProfileBinary

Retrieves binary data from an entry in the application's .INI file.

GetProfileInt

Retrieves an integer from an entry in the application's .INI file.

GetProfileString

Retrieves a string from an entry in the application's .INI file.

 

废话少说,举例如下:

BOOL COLContactFinal2005App::InitInstance()

{

SetRegistryKey(_T("COLContact "));

    WriteProfileString(_T("OLTest"),_T("Test1"),_T("abc"));

}

 

执行上述代码将在注册表生成如下键值:

[HKEY_CURRENT_USER\Software\COLContact \OLContactFinal2005\OLTest]

"Test1"="abc"

过SetRegistrykey导致应用程序设置,而不是存储在注册表中。INI文件。

名SetRegistryKey这个函数功能是设置MFC程序的注册表访问键,并把读写INI文件的成员函数映射到读写注册表。只要调用一下名SetRegistryKey并指定注册表键值,那么下面6个成员函数,就被映射到进行注册表读取了〜

WriteProfileBinary写入二进制数据的应用程序的INI文件中的条目。
WriteProfileInt整数写入应用程序的INI文件中的条目。
WriteProfileString将一个字符串写入到应用程序的INI文件中的条目。

GetProfileBinary检索二进制数据从应用程序的INI文件中的一个条目。
GetProfileInt从应用程序的INI文件中的一个条目检索一个整数。
GetProfileString从应用程序的INI文件中的一个条目检索字串。

应用程序“)); / /这里是准备在注册表HKEY_CURRENT_USER / /软件下面生成一个薄利的应用程序strUserName中,strPassword WriteProfileString(的“LOGINFO”,“用户名”,strUserName中)在/ /向注册表HKEY_CURRENT_USER / /软件/ /勃利的应用程序/ / / /分支下写入用户名字符串行键值〜WriteProfileString(“LOGINFO LOGINFO “,”密码“,strPassword);/ /同上~~  strUserName中GetProfileString(的“LOGINFO”,“用户名”);/ /这里是读取HKEY_CURRENT_USER / /软件/ /勃利的应用程序/ / / / LOGINFO分支下的用户名字符串键值到strUserName中〜 strPassword = GetProfileString(的“LOGINFO”,“密码”);在如果不是在CWinApp的派生的类中读写注册表,可以直接用: strUserName中theApp.GetProfileString(的“LOGINFO”,“用户名”) strPassword = theApp.GetProfileString(的“LOGINFO”,“密码”);  strUserName中= AfxGetApp() - > GetProfileString(的“LOGINFO”,“用户名”); 条条大路通罗马。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值