您的位置:逆风者 VB 正文
原作者:www.upwinder.com 添加时间:2007-09-02 原文发表:2007-08-31 人气:84 来源:未知

本文章共1719字,分2页,当前第1页,快速翻页:
 
首先新建一个工程,在新建的窗体上添加以下控件并设置相应属性
控件名 属性
逆@风@者
Label1 Caption 注册表键值:
Label2 Caption 注册姓名:
Label3 Caption 空
Label4 Caption 注册公司:
Label5 Caption 空
Label6 Caption 空
Text1 Text 空
Text2 Text 空
Command1 Caption 写入注册表
Command2 Caption 退出
然后,在程序的声明部分添加如下代码:
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 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
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
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 REG_SZ = 1
Const regkey = "softwareMy SoftMy program"
接着为各个控件添加代码,代码如下:
Private Sub Command1_Click()
Dim keyvalue As String
Dim retvalue As Long
Dim keyid As Long
retvalue = RegCreateKey(h da0 key_local_machine, regkey, keyid)
keyvalue = Text1.Text
retvalue = RegSetValueEx(keyid, "注册名", 0&, REG_SZ, ByVal keyvalue, Len(keyvalue) 1)
keyvalue = Text2.Text
retvalue = RegSetValueEx(keyid, "注册公司", 0&, REG_SZ, ByVal keyvalue, Len(keyvalue) 1)
If Text1.Text <> "" And Text2.Text <> "" Then
Label3.Caption = Text1.Text
Label5.Caption = Text2.Text
End If
End Sub

Private Sub Command2_Click()
Unload Me
End
End Sub

Private Sub Form_Load()
Dim retvalue As Long
Dim result As Long
Dim keyid As Long
Dim keyvalue As String
Dim subkey As String
Dim bufsize As Long
Label6.Caption = regkey
retvalue = RegCreateKey(hkey_local_machine, regkey, keyid)
If retvalue = 0 Then
subkey = "注册名"
retvalue = RegQueryValueEx(keyid, subkey, 0&, REG_SZ, 0&, bufsize)
If bufsize < 2 Then
keyvalue = ""
retvalue = RegSetValueEx(keyid, subkey, 0&, REG_SZ, ByVal keyvalue, Len(keyvalue) 1)
Else
keyvalue = String(bufsize 1, " ")
retvalue = RegQueryValueEx(keyid, subkey, 0&, REG_SZ, ByVal keyvalue, bufsize)
keyvalue = Left$(keyvalue, bufsize - 1)
Text1.Text = keyvalue
End If
Label3.Caption = keyvalue

subkey = "注册公司"
retvalue = RegQueryValueEx(keyid, subkey, 0&, REG_SZ, 0&, bufsize)
If bufsize < 2 Then
keyvalue = ""
retvalue = RegSetValueEx(keyid, subkey, 0&, REG_SZ, ByVal keyvalue, Len(keyvalue) 1)
Else
keyvalue = String(bufsize 1, " ")
retvalue = RegQueryValueEx(keyid, subkey, 0&, REG_SZ, ByVal keyvalue, bufsize)
keyvalue = Left$(keyvalue, bufsize - 1)
 
本文章更多内容1 - 2 - 下一页>>
相关文章

自动更新工作站的应用程序
VB实现按钮浮动效果
VB6制作Win98风格的工具栏
利用INI文件给程序创建动态菜单
一个用VB实现的鼠标绘图程序
VB 从零开始编外挂(五)
利用VB三维面板控件设计流动条
用VB编程实现图像的熠熠生辉效果
在VB中调用EXCEL
制作自己的网络搜索软件
用VB尝试新的界面风格
在桌面上建立一个 Internet 快捷键
用VB计算1 1=2
桌面屏幕翻转
在VB中如何得到网络中某一台电脑(电脑名)的
一个自动更换墙纸的小软件
利用两种简易方法实现直接打开一个文件
PING一个IP地址(向它发送一个数据包并等待
开启文件属性窗口
Viusal Basic程序员的.NET泛型编程

相关评论


本文章所属分类:首页 VB

  热门关键字: