SetRegistryKey的作用

来源:互联网 发布:网络歌手招聘信息 编辑:程序博客网 时间:2024/05/21 08:39

在利用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"

http://apps.hi.baidu.com/share/detail/34874018

原创粉丝点击