---------------------------------------------------------------------------
无意中在网上发现的,我也不会用,你可以试试的,若好用,说一声,呵呵~~~~~~
---------------------------------------------------------------------------
相关内容请点击这里讨论
--------------------------------------------------------------------------------
现在,有许多软件安装后会在 IE 浏览器的工具条上添加一个自定义按钮,为用户运行程序提供了方便,如“网络蚂蚁”、“金山词霸2000”等等。实际上添加这个自定义按钮并不难,只要找到了它在注册表中的位置和有关参数,通过手工或程序都可以轻易完成。而最方便的办法就是调用现成的 ActiveX 控件来完成这个功能,但 Windows 似乎没有提供这种控件。下面介绍如何开发和使用这种自定义控件。
实现方法
要添加这种自定义按钮,需要在 Windows 注册表的 HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions 子键下建立一个 GUID 项,然后在注册表的右栏建立相应的参数并赋值。这些参数及其含义如下:
●ButtonText:自定义按钮上显示的文本字符串;
●Clsid:IE 工具条的类标识码,为“{1FBA04EE-3024-11D2-8F1F0000F87ABD16}”;
●Default Visible:自定义按钮是否可见,一般为 “Yes";
●Exec:自定义按钮执行的目标,为可执行文件或超文本链接等;
●HotIcon:鼠标移上按钮时显示的图标,一般取自 EXE 文件或 DLL 文件;
●Icon:按钮正常显示的图标,一般取自 EXE 文件或 DLL 文件;
●MenuText:在 IE 的“工具”菜单中显示的菜单项;
●MenuStatusBar:IE的“工具”菜单项的注释,在状态条上显示。
制作过程
在 VB 5.0/6.0 下建立新的“ActiveX 控件”工程。
首先,给控件 AddButton 的 Picture 属性添加一个微型 Icon 图片,这样当使用该控件时,会在控件工具箱上显示这个小图标。然后,再在设计窗口上放置一个 image 控件,给它也设置一个小图片,使用该控件时,会在其 Form 上显示该控件的外观。最后,调出代码编辑窗口,在该窗口中键入以下代码,其中 API 函数调用的代码可以直接从“API 文本浏览器”中获得。
Option Explicit
……'Default Property Values
……'Property Variables
'定义常量
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
'声明存取注册表的 API 函数
Private Declare Function RegCloseKey Lib “advapi32.dll" (ByVal hKey As Long) As Long
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 RegDeleteValue Lib “advapi32.dll" Alias “RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib “advapi32.dll" Alias “RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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 hKey = HKEY_LOCAL_MACHINE
Const subKey0=“Software\Microsoft\Internet Explorer\Extensions($%$43%^#ASD#2@$#f$%^)
’把字符串值存入注册表
Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
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)
End Sub
’从注册表中删除字符串值
Private Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
Dim r, keyhand As Long
r = RegOpenKey(hKey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function
'把设置写入注册表,定义按钮
Public Sub AddBtn2IEtoolbar()
Dim subKey As String
subKey = subKey0 & Trim(GUID) & “($%$43%^#ASD#2@$#f$%^)
Call SaveString(hKey, subKey, “ButtonText", ButtonText)
Call SaveString(hKey, subKey,“Clsid",
“{1FBA04EE-3024-11D2-8F1F0000F87ABD16}")
Call SaveString(hKey, subKey, “Default Visible", “Yes")
Call SaveString(hKey, subKey, “Exec", Exec)
Call SaveString(hKey, subKey, “HotIcon", HotIcon)
Call SaveString(hKey, subKey, “Icon", Icon)
Call SaveString(hKey, subKey, “MenuStatusBar",
MenuStatusBar)
Call SaveString(hKey,subKey,“MenuText", MenuText)End Sub
'从注册表中删除自定义按钮
Public Sub DelBtnFromIEtoolbar()
Dim subKey As String
subKey = subKey0 & Trim(GUID) & “($%$43%^#ASD#2@$#f$%^)
Call DeleteValue(hKey, subKey, “ButtonText")
Call DeleteValue(hKey, subKey, “Clsid")
Call DeleteValue(hKey, subKey, “Default Visible")
Call DeleteValue(hKey, subKey, “Exec")
Call DeleteValue(hKey, subKey, “HotIcon")
Call DeleteValue(hKey, subKey, “Icon")
Call DeleteValue(hKey, subKey, “MenuStatusBar")
Call DeleteValue(hKey, subKey, “MenuText")
End Sub
'初始化控件属性
Private Sub UserControl_InitProperties()
m_ButtonText = m_def_ButtonText
m_Exec = m_def_Exec
m_HotIcon = m_def_HotIcon
m_Icon = m_def_Icon
m_MenuText = m_def_MenuText
m_MenuStatusBar = m_def_MenuStatusBar
m_GUID = m_def_GUID
End Sub
'从存储器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_ButtonText = PropBag.ReadProperty
(“ButtonText", m_def_ButtonText)
m_Exec = PropBag.ReadProperty(“Exec",
m_def_Exec)
m_HotIcon = PropBag.ReadProperty(“HotIcon",
m_def_HotIcon)
m_Icon = PropBag.ReadProperty(“Icon",
m_def_Icon)
m_MenuText = PropBag.ReadProperty
(“MenuText",m_def_MenuText)
m_MenuStatusBar =PropBag.ReadProperty
(“MenuStatusBar", m_def_MenuStatusBar)
m_GUID =PropBag.ReadProperty(“GUID",
m_def_GUID)
End Sub
无意中在网上发现的,我也不会用,你可以试试的,若好用,说一声,呵呵~~~~~~
---------------------------------------------------------------------------
相关内容请点击这里讨论
--------------------------------------------------------------------------------
现在,有许多软件安装后会在 IE 浏览器的工具条上添加一个自定义按钮,为用户运行程序提供了方便,如“网络蚂蚁”、“金山词霸2000”等等。实际上添加这个自定义按钮并不难,只要找到了它在注册表中的位置和有关参数,通过手工或程序都可以轻易完成。而最方便的办法就是调用现成的 ActiveX 控件来完成这个功能,但 Windows 似乎没有提供这种控件。下面介绍如何开发和使用这种自定义控件。
实现方法
要添加这种自定义按钮,需要在 Windows 注册表的 HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions 子键下建立一个 GUID 项,然后在注册表的右栏建立相应的参数并赋值。这些参数及其含义如下:
●ButtonText:自定义按钮上显示的文本字符串;
●Clsid:IE 工具条的类标识码,为“{1FBA04EE-3024-11D2-8F1F0000F87ABD16}”;
●Default Visible:自定义按钮是否可见,一般为 “Yes";
●Exec:自定义按钮执行的目标,为可执行文件或超文本链接等;
●HotIcon:鼠标移上按钮时显示的图标,一般取自 EXE 文件或 DLL 文件;
●Icon:按钮正常显示的图标,一般取自 EXE 文件或 DLL 文件;
●MenuText:在 IE 的“工具”菜单中显示的菜单项;
●MenuStatusBar:IE的“工具”菜单项的注释,在状态条上显示。
制作过程
在 VB 5.0/6.0 下建立新的“ActiveX 控件”工程。
首先,给控件 AddButton 的 Picture 属性添加一个微型 Icon 图片,这样当使用该控件时,会在控件工具箱上显示这个小图标。然后,再在设计窗口上放置一个 image 控件,给它也设置一个小图片,使用该控件时,会在其 Form 上显示该控件的外观。最后,调出代码编辑窗口,在该窗口中键入以下代码,其中 API 函数调用的代码可以直接从“API 文本浏览器”中获得。
Option Explicit
……'Default Property Values
……'Property Variables
'定义常量
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
'声明存取注册表的 API 函数
Private Declare Function RegCloseKey Lib “advapi32.dll" (ByVal hKey As Long) As Long
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 RegDeleteValue Lib “advapi32.dll" Alias “RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib “advapi32.dll" Alias “RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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 hKey = HKEY_LOCAL_MACHINE
Const subKey0=“Software\Microsoft\Internet Explorer\Extensions($%$43%^#ASD#2@$#f$%^)
’把字符串值存入注册表
Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
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)
End Sub
’从注册表中删除字符串值
Private Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
Dim r, keyhand As Long
r = RegOpenKey(hKey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function
'把设置写入注册表,定义按钮
Public Sub AddBtn2IEtoolbar()
Dim subKey As String
subKey = subKey0 & Trim(GUID) & “($%$43%^#ASD#2@$#f$%^)
Call SaveString(hKey, subKey, “ButtonText", ButtonText)
Call SaveString(hKey, subKey,“Clsid",
“{1FBA04EE-3024-11D2-8F1F0000F87ABD16}")
Call SaveString(hKey, subKey, “Default Visible", “Yes")
Call SaveString(hKey, subKey, “Exec", Exec)
Call SaveString(hKey, subKey, “HotIcon", HotIcon)
Call SaveString(hKey, subKey, “Icon", Icon)
Call SaveString(hKey, subKey, “MenuStatusBar",
MenuStatusBar)
Call SaveString(hKey,subKey,“MenuText", MenuText)End Sub
'从注册表中删除自定义按钮
Public Sub DelBtnFromIEtoolbar()
Dim subKey As String
subKey = subKey0 & Trim(GUID) & “($%$43%^#ASD#2@$#f$%^)
Call DeleteValue(hKey, subKey, “ButtonText")
Call DeleteValue(hKey, subKey, “Clsid")
Call DeleteValue(hKey, subKey, “Default Visible")
Call DeleteValue(hKey, subKey, “Exec")
Call DeleteValue(hKey, subKey, “HotIcon")
Call DeleteValue(hKey, subKey, “Icon")
Call DeleteValue(hKey, subKey, “MenuStatusBar")
Call DeleteValue(hKey, subKey, “MenuText")
End Sub
'初始化控件属性
Private Sub UserControl_InitProperties()
m_ButtonText = m_def_ButtonText
m_Exec = m_def_Exec
m_HotIcon = m_def_HotIcon
m_Icon = m_def_Icon
m_MenuText = m_def_MenuText
m_MenuStatusBar = m_def_MenuStatusBar
m_GUID = m_def_GUID
End Sub
'从存储器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_ButtonText = PropBag.ReadProperty
(“ButtonText", m_def_ButtonText)
m_Exec = PropBag.ReadProperty(“Exec",
m_def_Exec)
m_HotIcon = PropBag.ReadProperty(“HotIcon",
m_def_HotIcon)
m_Icon = PropBag.ReadProperty(“Icon",
m_def_Icon)
m_MenuText = PropBag.ReadProperty
(“MenuText",m_def_MenuText)
m_MenuStatusBar =PropBag.ReadProperty
(“MenuStatusBar", m_def_MenuStatusBar)
m_GUID =PropBag.ReadProperty(“GUID",
m_def_GUID)
End Sub
文章来源:http://bbs.sdnyyz.com:8080/article/list.asp?id=64