用VB实现“一点即填”

用VB实现“一点即填”,第1张

用VB实现“一点即填”,第2张

面对这种情况,你可能首先想到的是在网上找一个填表软件。但是,现有的软件要么使用剪贴板传输,要么使用拖放技术,而且因为必须运行填表软件,所以使用起来不是很方便。所以我们决定自己写一个软件,集成到IE的右键菜单里。使用时,只需在要输入的输入项上点击鼠标右键,然后选择相应的项,就会自动输入,实现“一键填写”。

这个程序首先在IE的右键菜单上添加项目,可以通过操作注册表来实现。然后,使用JavaScript程序判断所选择的项目是否是输入框。如果有,填写我们提前保存的数据。下面介绍具体的实现过程。

一、设计界面
进入VB,选择“标准EXE”新建一个项目,选择“项目”菜单下的“部件”,在弹出的对话框中选择“Microsoft Windows Common Controls 6.0”,然后根据下表在窗体上添加控件。完成后的界面如图1所示:控件类型名称属性标签1标题:名称标签2标题:内容文本框txtname文本框txtcont命令按钮命令1标题:添加命令按钮命令2标题:删除列表框li视图1为其添加两列,列标题分别为“名称”和“内容”,并将视图属性更改为3-LV report和GridLines为True。

二。程序源代码

首先在项目中添加一个标准模块并输入以下代码,这些代码用于注册表操作:
'声明必要的API函数和常量
声明函数reg save key Lib " advapi 32 . dll " Alias
" regsavekeya "(Byval HKEY为long,ByVal lpFile为String,ByVal lpSecurityAttributes为Long)
声明函数RegSetValue Lib " advapi 32 . dll " Alias
" RegSetValueA "(by ByVal CB data As Long)
声明函数RegCloseKey Lib " advapi32 . dll "(ByVal hKey
As Long
声明函数RegCreateKey Lib " advapi32 . dll " Alias
" RegCreateKeyA "(ByVal hKey As Long,ByVal lpSubKey As
String,phkResult As Long)声明函数RegDeleteKey Lib " advapi32 . dll " Alias
ByVal lpValueName
As String)Long
Declare Function regopen key Lib " advapi32 . dll " Alias
" regopen keya "(ByVal hKey As Long,ByVal lpSubKey As
String,phkResult As Long)
Declare Function RegSetValueEx Lib " advapi32 . dll " Alias
" RegSetValueExA "(ByVal hKey As Long,ByVal lpValueName As String,ByVal ByVal ulOptions一样长,ByVal samDesired一样长, phkResult As Long)
公共常数HKEY _类_根= &H80000000
公共常数HKEY _当前_用户= &H80000001
公共常数HKEY _ LOCAL _ MACHINE = & h 80000002
公共常数HKEY _用户= & h 800000003
公共常数错误_ NO _更多_项目= 259&
global const key _ all _ access = & h3f dimlngtype as long
dimrtn as long,lbuffer aslong,sbuffer as string
dimlbuffersize as long
'创建新主键的过程进入了讨论组。
Public Sub savekey(hKey为Long,strPath为String)
On ERR _ save key
Dim keyhand &
r = RegCreateKey(hKey,strPath,keyhand &)
r = RegCloseKey(keyhand &)
Exit Sub
ERR _ save key:
MsgBox ERR。数字& "- " & Err。描述
Resume Next
End Sub
'保存字符键值
public sub保存字符串(HKEY aslong,strpath asstring,strvalue
asstring,strdata As String)
On ERR _ savestring
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(hKey,strpath,keyhand)
r = r数字& "- " & Err。描述[/ Br/]resume next[/Br/]end sub[/Br/]'保存DWORD键值[/Br/]函数保存的word (byval HKEY为long,byval strpathas
string,ByVal strValueName为string,ByVal lData为Long)
Dim lResult为Long
Dim keyhand为Long
Dim r为Long
r = RegCreateKey(hKey,strPath,keyhand)
4)
r = regclosekey(key hand)End Function
' Delete primary key
public Function Delete key(byval HKEY为long,byval strKey
为String)
Dim r为Long
r = RegDeleteKey(hKey,StrKey) End Function
'保存默认键值
function set默认值(ByVal HKEY为Long,ByVal子键
为String,ByVal REG_SZ,Value,Len b
(strConv (value,vbfromnicode))+1)
set default Value =(ret = 0)end function
然后编写表单部分的代码:
Dim lcont为整数。

private command 1 _ click()
dimret as boolean
'在列表框中添加项目
lcont = listview 1 . listitems . count+1
listview 1。添加lcont,,Txname
listview 1 . ListItems(lcont)。sub items(1)= txt cont
'生成一个HTML文件,以项目名称作为文件名
Open App。路径& "\ " & txtname & "htm " For Output As
# 1
Print # 1," " JavaScript " & " " " & " defer > " & vbCrLf _
& " var parent win = external . menu arguments;" & _
vbCrLf & " var doc = parent win . document;" & _
vbCrLf & " var sel = doc . selection;" & vbCrLf & _
" var RNG = sel . create range();" & vbCrLf & _
" if(doc . active element . type = = " & " " " & _
" text " & " " " & " | | doc . active element . type = = " & _
" " " & " " & _
" | | doc . active element . type = = " & " " " & " " " & _
" password " & " " " " " & " " " & vbCrLf & _
" RNG . text = " & " " " & txttext & _
" " " " & ";" & vbCrLf & ""
关闭#1
'添加相应的项目
保存键HKEY _当前_用户,
"软件\ Microsoft \ Internet Explorer \ menuext \ " & txt name。text
ret = set default value(HKEY _当前_用户,
" software \ Microsoft \ internet explorer \ menuext " & " \ " & txt name。Text," file://" & App。路径& "\" & txtname & "htm ")
saved word HKEY _当前_用户,
"软件\微软\ internet explorer \ menuext " & " \ " & txt name,
"上下文",4
savestring HKEY _当前_用户,
"软件\微软\ internet explorer \ menuext " & " \ " & txt name,
"iform ",txtcont
End Sub

Delete private子命令2 _ click ()
Delete键HKEY _当前用户,
"软件\ Microsoft \ Internet Explorer \ Menuext " & " \ " & listview 1。选择编辑项目
列表视图1。移除ListView1。SelectedItem.Index
End Sub

private Sub Form _ Load()
savekey HKEY _当前用户,
" software \ Microsoft \ internet explorer \ menuext " End Sub

三。程序操作

输入代码后,按F5运行它。添加必要的信息后,就可以使用了。图2是演示结果。打开你的IE试试吧!

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 用VB实现“一点即填”

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情