您现在的位置: 天下网吧 >> 网吧天地 >> 天下码农 >> 编程界 >> 正文

用 VB 实现“一点即填”

2008-11-6巧巧读书佚名

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

  本程序首先要在IE的右键菜单上添加项目,这可通过操作注册表来实现,然后利用一个JavaScript程序判断所选 的是不是可输入框,如果是,将我们事先保存的数据填上。 下面介绍具体的实现过程。

  一、设计界面
  进入 VB,选择“标准 EXE”新建一工程,选择“工 程”菜单下的“部件”,在弹出的对话框中选择“Microsoft Windows Common Controls 6.0”,然后按照下表在窗体 上添加控件,设置完成的界面如图 1 所示: 控件类型    Name    属性 标签    label1    Caption:名称 标签    label2    Caption:内容 文本框    txtname 文本框    txtcont 命令按钮    command1    Caption:添加 命令按钮    command2    Caption:删除 列表框    listview1 为它加入两个列,列标题分别为“名称”和“内容”,并 且把 View 属性修改成 3-lvwReport,把 GridLines 改成 True。

  二、程序源代码

  首先在工程中添加一个标准模块并输入如下代码,这 些代码用于注册表操作:
’声明必要的API函数及常量
  Declare Function RegSaveKey Lib "advapi32.dll" Alias
  "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal lpSecurityAttributes   As Long) As Long
  Declare Function RegSetValue Lib "advapi32.dll" Alias
  "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long,   ByVal lpData As String, ByVal cbData As Long) As Long
  Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey
  As Long) As Long
  Declare Function RegCreateKey Lib "advapi32.dll" Alias
  "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As
  String, phkResult As Long) As Long
  Declare Function RegDeleteKey Lib "advapi32.dll" Alias
  "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As
  String) As Long
  Declare Function RegDeleteValue Lib "advapi32.dll" Alias
  "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName
  As String) As Long
  Declare Function RegOpenKey Lib "advapi32.dll" Alias
  "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As
  String, phkResult As Long) As Long
  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
  Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
  "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As   Long, ByVal samDesired As Long, phkResult As Long) As Long
  Public Const HKEY_CLASSES_ROOT = &H80000000
  Public Const HKEY_CURRENT_USER = &H80000001
  Public Const HKEY_LOCAL_MACHINE = &H80000002
  Public Const HKEY_USERS = &H80000003
  Public Const ERROR_NO_MORE_ITEMS = 259&
  Public Const HKEY_CURRENT_CONFIG = &H80000005
  Enum ValueType
  REG_NONE = 0
  REG_SZ = 1
  REG_EXPAND_SZ = 2
  REG_BINARY = 3
  REG_DWORD = 4
  REG_DWORD_BIG_ENDIAN = 5
  REG_MULTI_SZ = 7
  End Enum
  Global Const KEY_ALL_ACCESS = &H3F Dim lngtype As Long
  Dim rtn As Long, lBuffer As Long, sbuffer As String
  Dim lBufferSize As Long
  ’新建主键的过程进入讨论组讨论。
    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

欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛 https://bbs.txwb.com

关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩

本文来源:巧巧读书 作者:佚名

声明
声明:本站所发表的文章、评论及图片仅代表作者本人观点,与本站立场无关。若文章侵犯了您的相关权益,请及时与我们联系,我们会及时处理,感谢您对本站的支持!联系邮箱:support@txwb.com,系统开号,技术支持,服务联系QQ:1175525021本站所有有注明来源为天下网吧或天下网吧论坛的原创作品,各位转载时请注明来源链接!
天下网吧 网吧天下