C#在IE右键菜单中添加自定义项的实现代码
本文导语: 首先,增加注册表项 HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExtMyApp MyApp为要显示在右键菜单中的名称 VBScript处理脚本,新增的注册表项的默认值是包含这个VBScript脚本的Html页面地址。 1、添加注册表项: /// /// 在IE中...
首先,增加注册表项 HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExtMyApp
MyApp为要显示在右键菜单中的名称
VBScript处理脚本,新增的注册表项的默认值是包含这个VBScript脚本的Html页面地址。
1、添加注册表项:
/// /// 在IE中增加右键菜单 /// static void RegistryIeContextMenu() { try { string regkey = @"SoftwareMicrosoftInternet ExplorerMenuExtMyApp"; string scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "geturl.htm"); RegistryKey root = Registry.CurrentUser.OpenSubKey(regkey); if (null == root) { root = Registry.CurrentUser.CreateSubKey(regkey); root.SetValue("", scriptPath, RegistryValueKind.String); root.SetValue("Contexts", 0x00000022, RegistryValueKind.DWord); } } catch (Exception ex) { DFApp.LogDebug(ex.ToString()); } }
2、脚本geturl.htm
Sub AddLink(Url,Info,Location)
On Error Resume Next
if Url "" then
if Info = "" then
Info = "unknown"
end if
if Len(Info) > 1000 then
Info = Left(Info, 1000)
end if
DownloadInfo = Url "^" Info
set shell = CreateObject("Wscript.Shell")
shell.Run "C:MyApp.EXE " DownloadInfo
end if
end sub
Sub OnContextMenu()
set srcEvent = external.menuArguments.event
set srcLocation = external.menuArguments.location
set EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY )
if srcEvent.type = "MenuExtAnchor" then
set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
Loop
Call AddLink(srcAnchor.href,srcAnchor.innerText,srcLocation)
elseif srcEvent.type="MenuExtImage" then
if TypeName(EventElement)="HTMLAreaElement" then
Call AddLink(EventElement.href,EventElement.Alt,srcLocation)
else
set srcImage = EventElement
set srcAnchor = srcImage.parentElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
call AddLink(srcImage.href,srcImage.Alt,srcLocation)
exit sub
end if
Loop
Call AddLink(srcAnchor.href,srcImage.Alt,srcLocation)
end if
elseif srcEvent.type="MenuExtUnknown" then
set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
Call AddLink(EventElement.href,EventElement.innerText,srcLocation)
exit sub
end if
Loop
Call AddLink(srcAnchor.href,srcAnchor.innerText,srcLocation)
elseif 1=1 then
MsgBox("Unknown Event Source """ srcEvent.type """" vbCrLf "Please send description of error to test@")
end if
end sub
call OnContextMenu()
您可能感兴趣的文章:
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。