RegOpenKeyEx和RegCreateKeyEx函数
来源:互联网 发布:mac 删除移动硬盘文件 编辑:程序博客网 时间:2024/04/30 06:17
由于电脑经常会关闭,或者应用程序也会经常关闭,但有一些参数是经常需要保存。比如当你打开程序,并设置了窗口的大小,想每次打开时都设置窗口为上次打开的大小。这样就需要保存窗口的大小,那么窗口大小的参数保存到那里呢?其实在Windows里最方便的做法,就是保存到注册表里。又比如游戏登录时,总是想保存最后一个登录的用户,那么也需要保存这个用户到注册表里。其实注册表是Windows保存系统配置的数据库,比如不同的语言设置,不同的时区设置,不同的用户登录,不同的权限等等。下面就来学习怎么样使用函数RegOpenKeyEx来打开注册表里的键和用函数RegCreateKeyEx来创建新的键。
函数RegOpenKeyEx和RegCreateKeyEx声明如下:
WINADVAPI
LONG
APIENTRY
RegOpenKeyExA (
__in HKEY hKey,
__in_opt LPCSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
WINADVAPI
LONG
APIENTRY
RegOpenKeyExW (
__in HKEY hKey,
__in_opt LPCWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
#ifdef UNICODE
#define RegOpenKeyEx RegOpenKeyExW
#else
#define RegOpenKeyEx RegOpenKeyExA
#endif // !UNICODE
WINADVAPI
LONG
APIENTRY
RegCreateKeyExA (
__in HKEY hKey,
__in LPCSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
WINADVAPI
LONG
APIENTRY
RegCreateKeyExW (
__in HKEY hKey,
__in LPCWSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPWSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
#ifdef UNICODE
#define RegCreateKeyEx RegCreateKeyExW
#else
#define RegCreateKeyEx RegCreateKeyExA
#endif // !UNICODE
hKey是主键。
lpSubKey是子键。
ulOptions是选项。
samDesired是键的操作。
phkResult是打开的键返回。
lpClass是新键值。
调用函数的例子如下:
#001 //打注册表。HKEY_CURRENT_USER/"Software"/"Wincpp"/"testreg"
#002 //蔡军生
#003 HKEY GetAppRegistryKey(void)
#004 {
#005 HKEY hAppKey = NULL;
#006 HKEY hSoftKey = NULL;
#007 HKEY hCompanyKey = NULL;
#008
#009 //打开HKEY_CURRENT_USER/"Software"。
#010 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("software"), 0, KEY_WRITE|KEY_READ,
#011 &hSoftKey) == ERROR_SUCCESS)
#012 {
#013 DWORD dw;
#014 //创建并打开HKEY_CURRENT_USER/"Software"/"Wincpp"
#015 if (RegCreateKeyEx(hSoftKey, _T("Wincpp"), 0, REG_NONE,
#016 REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
#017 &hCompanyKey, &dw) == ERROR_SUCCESS)
#018 {
#019 //创建并打开HKEY_CURRENT_USER/"Software"/"Wincpp"/"testreg"
#020 RegCreateKeyEx(hCompanyKey, _T("testreg"), 0, REG_NONE,
#021 REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
#022 &hAppKey, &dw);
#023 }
#024 }
#025
#026 //关闭打开的键值。
#027 if (hSoftKey != NULL)
#028 {
#029 RegCloseKey(hSoftKey);
#030 }
#031
#032 if (hCompanyKey != NULL)
#033 {
#034 RegCloseKey(hCompanyKey);
#035 }
#036
#037 return hAppKey;
#038 }
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Business Objects XI R3初览
- 附加数据库时出错。有关详细信息,请单击“消息”列中的超链接
- 鸡翅和鱼的做法
- Axure RP Pro - 相关问题 - 导入时保持变量有效
- rewind () 函数
- RegOpenKeyEx和RegCreateKeyEx函数
- 2008年11月16日_日_阴_为火车票呐喊
- 三五个人十来条枪 如何走出软件作坊成为开发正规军
- 四个开放源代码审查工具【图文】
- 在ACE中使用epoll[zhuan]
- 网络服务器软件开发
- 清华大三女生坠楼身亡 博客签名“DIE”(图)
- scanf () 函数
- 位操作