当前位置: 网学 > 编程文档 > VB > 正文

Win95系统API函数大揭秘

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
应用程序等信息。注册表系统代替了旧版Windows中的多个INI文件。(警
告:如果你对注册表不熟悉,不要随意修改它。如果注册表项目出错,会使机器崩溃,甚至破坏操作系
统本身。)
Win32 API中Reg函数处理对注册表数据库一般的读写过程如下:
1、使用RegOpenKey或RegCreateKey打开或创建一个键;
2、如果上一步成功,使用RegQueryValue(或RegQueryValueEx)读取子键的值,使用RegSetValue(或
RegvSetValueEx)设置子键值,使用RegEnumKey获得所有子键,使用RegDeleteKey删除一个键;
3、完成操作后使用RegCloseKey关闭键。
下述应用程序演示了如何生成键、存放值并取得注册表数据。在HKEY_LOCAL_MACHINE键下面生成三
个子键Test\Mastering vb5、    Windows Width、Windows Height,用于存放上次执行时的窗体尺寸。
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As
Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As
Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey
As Long, ByVal lpValueName As String) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal
hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData
As Any, lpcbData As Long) As Long '' Note that if you declare the lpData parameter as
String, you must pass it By Value.
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey
As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As
Any, ByVal cbData As Long) As Long '' Note that if you declare the lpData parameter as
String, you must pass it By Value.
Const ERROR_SUCCESS = 0&
Const ERROR_BADDB = 1009&
Const ERROR_BADKEY = 1010&
Const ERROR_CANTOPEN = 1011&
Const ERROR_CANTREAD = 1012&
Const ERROR_CANTWRITE = 1013&
Const ERROR_REGISTRY_RECOVERED = 1014&
Const ERROR_REGISTRY_CORRUPT = 1015&
Const ERROR_REGISTRY_IO_FAILED = 1016&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const regkey = "Test\Mastering vb5"

Private Sub Form_Load()
Dim retValue As Long
Dim result As Long
Dim keyValue As String
Dim keyId As Long
Dim subKey As String
Dim bufSize As Long
Label6.Caption = regkey
retValue = RegCreateKey(HKEY_LOCAL_MACHINE, regkey, keyId)
If retValue = 0 Then
subKey = "Windows Width"
retValue = RegQueryValueEx(keyId, subKey, 0&, reg_sz, 0&, bufSize)
If bufSize < 2 Then
keyValue = Me.Width
retValue = RegSetValueEx(keyId, subKey, 0&, reg_sz, ByVal keyValue, Len(keyValue) + 1)
Else
keyValue = String(bufSize + 1, "")
retValue = RegQueryValueEx(keyId, subKey, 0&, reg_sz, bykeyvalue, bufSize)
keyValue = Left$(keyValue, bufSize - 1)
Me.Width = keyValue
End If
Label4.Caption = subKey
Label5.Caption = Me.Width
s

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号