![]() ![]() |
|
二级VB辅导:用VB实现“一点即填” | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/4/18 14:45:29 文章录入:杜斌 责任编辑:杜斌 | |
|
|
在申请 Email 信箱、主页空间时我们经常要填写表 单,比如要填姓名、住址、身份证号、E-mail 地址、个人 简介等等??每次都重复的填写,好烦哪!
Public Sub savekey(hKey As Long, strPath As String) On Error GoTo ERR_savekey Dim keyhand& r = RegCreateKey(hKey, strPath, keyhand&) r = RegCloseKey(keyhand&) Exit Sub ERR_savekey: MsgBox Err.Number & "- " & Err.Description Resume Next End Sub ’保存字符型键值 Public Sub savestring(hKey As Long, strPath As String, strValue As String, strdata As String) On Error GoTo ERR_savestring Dim keyhand As Long Dim r As Long r = RegCreateKey(hKey, strPath, keyhand) r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata)) r = RegCloseKey(keyhand) Exit Sub ERR_savestring: MsgBox Err.Number & "- " & Err.Description Resume Next End Sub ’保存DWORD型键值 Function SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long) Dim lResult As Long Dim keyhand As Long Dim r As Long r = RegCreateKey(hKey, strPath, keyhand) lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4) r = RegCloseKey(keyhand) End Function ’删除主键 Public Function DeleteKey(ByVal hKey As Long, ByVal strKey As String) Dim r As Long r = RegDeleteKey(hKey, strKey) End Function ’保存默认键值 Function SetDefaultValue(ByVal hKey As Long, ByVal Subkey As String, ByVal Value As String) As Boolean Dim ret As Long, lenS As Long, S As String ret = RegSetValue(hKey, Subkey, REG_SZ, Value, LenB (StrConv(Value, vbFromUnicode)) + 1) SetDefaultValue = (ret = 0) End Function 接着编写窗体部分的代码: Dim lcont As Integer Private Sub Command1_Click() Dim ret As Boolean ’在列表框中添加项目 lcont = ListView1.ListItems.Count + 1 ListView1.ListItems.Add lcont, , txtname ListView1.ListItems(lcont).SubItems(1) = txtcont ’生成以项目名称为文件名的HTML文件 Open App.Path & "\" & txtname & ".htm" For Output As #1 Print #1, "<SCRIPT LANGUAGE=" & """" & _ "JavaScript" & """" & " defer > " & vbCrLf _ & "var parentwin=external.menuArguments;" & _ vbCrLf & "var doc=parentwin.document;" & _ vbCrLf & "var sel=doc.selection;" & vbCrLf & _ "var rng=sel.createRange();" & vbCrLf & _ "if (doc.activeElement.type==" & """" & _ "text" & """" & "||doc.activeElement.type==" & _ """" & "textarea" & """" & _ "||doc.activeElement.type==" & """" & _ "password" & """" & ")" & vbCrLf & _ "rng.text =" & """" & txtcont.Text & _ """" & ";" & vbCrLf & "</SCRIPT>" Close #1 ’在IE右键菜单上添加相应项目 savekey HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext\" & txtname.Text ret = SetDefaultValue(HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext" & "\" & txtname. Text, "file://" & App.Path & "\" & txtname & ".htm") SaveDword HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext" & "\" & txtname, "Contexts", 4 savestring HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext" & "\" & txtname, "iform", txtcont End Sub ’删除Private Sub Command2_Click() DeleteKey HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext" & "\" & ListView1. SelectedItem ListView1.ListItems.Remove ListView1.SelectedItem.Index End Sub Private Sub Form_Load() savekey HKEY_CURRENT_USER, "software\microsoft\internet explorer\menuext" End Sub 三、程序运行 输入完成代码后按 F5 运行,添入必要的信息后就 可使用了,图2 便是演示结 果。赶快打开你的IE试一试 吧!
|
|
![]() ![]() |