1. How to add menu items to the IE right-click menu
Friends who have used Netants may know that NetAnts has added a right-click menu function in IE. As long as you right-click on a link or picture on the page and select Down By Netants in the menu, you can call Netants to download the file pointed to by the link. In this article, the author will introduce how to implement such a function through VB.
To implement the function of adding menu items to the IE right-click menu, the following steps must be implemented in sequence:
1. Create a new item under the HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExt item in the registry. The name of the item appears as the title in the menu. For example, the title of the menu item you want to create is Add URL, then the name of the new item is
HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExtAdd URL
2. Set the default value of the new item to a URL address. When the user clicks on the menu item, IE will call the script in the page pointed to by the URL. In the script of the target page, access the menuArguments attribute of the external object provided by IE. You can access various objects in the page in IE, such as links, pictures, form fields, selected text, etc. For detailed help, please refer to MSDN about InternetExplore object
With help, you can better understand the following script if you are familiar with the Window object.
For the problem of how to implement our own program to access menuArguments, we can follow Netants' approach and first create a
OLE Automation object, and then call the object in the script and pass the page information to the object for processing. Next we need to first create an object through VB:
Open VB, click the menu: File | New, select ActiveX Dll in the new project window and press the OK key to create an ActiveX DLL
project. Then change the Name property of Class1 to NetAPI in the project list window, and then add the following code in the NetAPI code window:
Public Sub AddURL(URL As String, Info As String)
MsgBox Info, vbOKOnly, URL
End Sub
Save the file and save the project file as NetSamp.vbp. Then select File | Make NetSamp.dll in the menu to create the object dynamic link library.
Next is the registration library. Find Regsvr32.exe in the Windows directory, and then copy it to the directory where netsamp.dll is located.
Drag the icon of netsamp.dll onto Regsvr32.exe and release it. At this time, Regsvr32.exe will pop up a dialog box prompting that the object registration is successful.
Open UltraEdit (or other text editor) and enter the following script code into the editor:
<script language="VBScript">
Sub OnContextMenu()
On Error Resume Next
set srcEvent = external.menuArguments.event
set EventElement = external.menuArguments.document.elementFromPoint(srcEvent.clientX, srcEvent.clientY)
set objNetSamp=CreateObject("NetSamp.NetAPI")
if srcEvent.type = "MenuExtAnchor" then
set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
Loop
Call objNetSamp.AddUrl(srcAnchor.href,srcAnchor.innerText)
elseif srcEvent.type="MenuExtImage" then
if TypeName(EventElement)="HTMLAreaElement" then
Call objNetSamp.AddUrl(EventElement.href,EventElement.Alt)
else
set srcImage = EventElement
set srcAnchor = srcImage.parentElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
call objNetSamp.AddUrl(srcImage.href,srcImage.Alt)
exit sub
end if
Loop
Call objNetSamp.AddUrl(srcAnchor.href, srcImage.Alt)
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 objNetSamp.AddUrl(EventElement.href,EventElement.innerText)
exit sub
end if
Loop
Call objNetSamp.AddUrl(srcAnchor.href,srcAnchor.innerText)
end if
end Sub
callOnContextMenu()
</script>
Save the file to c:program files with the file name geturl.htm
As you can see from the above script, first access the external.menuArguments property to obtain the object where the user clicks the right mouse button, then obtain its URL based on the object, then create the IEContextMenu.IEMenu1 object and call the object's AddURL method.
The next step is to create a registration item for the right-click menu, open UltraEdit (or other text editor) and enter the following registration data into the editor.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExt&Get URL]
@="c:\program files\geturl.htm"
"Contexts"=dword:00000022
Save the file with reg as the suffix, then double-click the file in Windows Explorer to add the registration key to the registry, and then open it
IE, right-click a link or image, and a Get URL item will appear in the pop-up menu. Click this item, and a message box will appear showing the URL address of the clicked link or image.
Let’s introduce the role of the Contexts item in the above registration item. Through this item, you can specify what menu item appears when you right-click on an object in IE. It can be an "OR" combination of the following values:
object value
Default 0x1
Image 0x2
Control 0x4
Form field 0x8
Select text 0x10
Anchor point 0x20
For example, above we want the menu item to appear when the user clicks on the image or hyperlink, then we set the value to dword:00000022, which means the menu will appear when the user clicks on the image or anchor. An anchor is an object on the page that describes a hyperlink. If the Contexts item is not set, the menu items will appear in the right-click menu when clicking on any object.
Through the above program introduction, we can see the working process of the IE mouse right-click menu. As mentioned earlier, Netants uses this method to call NetAnts by creating objects in scripts. If we install NetAnts, we can call NetAnts in the program by calling the NetAnts object.
Create a new project, click the Projects | References item in the menu, and select the AntAPI 1.0 Type Library item. If the Browser button is not clicked, select NetAPI.dll in the Network Ant directory in the file list box and press the Open key. Add a CommandButton in Form1
button, add the following code in the Command1_Click event:
Dim ant As New ANTAPILib.AntAPIObj
ant.AddUrl " http://www.downcodes.com/ "
Click command1, then NetAnts will run and 7. HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerExtensions<Your GUID> in the registry
Create a new String type value named Clsid, and set the value to {1FBA04EE-3024-11D2-8F1F-0000F87ABD16}
8. In the registry HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerExtensions<Your GUID>
Create a new String type value named Exec. This value defines the full path name of the file to be run after clicking the button, for example:
c:program filessamplesnet.exe
For example, the content of the NetAnts button registry key is as follows:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerExtensions{57E91B47-F40A-11D1-B792 -444553540000}]
"CLSID"="{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}"
"Default Visible"="Yes"
"HotIcon"="C:\PROGRA~1\NETANTS\NetAnts.exe,1001"
"Icon"="C:\PROGRA~1\NETANTS\NetAnts.exe,1000"
"Exec"="C:\PROGRA~1\NETANTS\NetAnts.exe"
"ButtonText"="NetAnts"
"MenuText"="&NetAnts"
"MenuStatusBar"="Launch NetAnts"
Netants will be launched when the NetAnts button is clicked. The following two items in the above registry key: the MenuText key adds a menu item to the "Tools" bar of the menu, and the MenuStatusBar key defines the prompt text that is displayed in the status bar when the cursor moves to the added menu bar. In addition, in the registry
You can also add a file named
String type value of MenuCustomize. Setting this value to "Help" will cause the menu item to appear in the "Help" menu bar, otherwise it will appear in the "Tools" bar.
Of course, we will not be satisfied with just adding a button and executing a program. We hope to be able to control the current page when the user clicks the button, which is in the registry's HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerExtensions<Your GUID>
Create a new String type value, and set the name to the full path name of an html file. Same as adding a right-click menu introduced earlier, IE will call the file after clicking the button, and access it by setting VBScript in the file. The menuArguments property of the external object can obtain the page in the browser. For example, we will HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerExtensions<Your GUID>VBScript
Set the value to c:program filessamp.htm, then create a file named Samp.htm under c:program files, and enter the following script content in the file:
<script language="VBScript">
Set objNetSamp=CreateObject("IEContextMenu.IEMenu1")
userURL=external.menuArguments.location.href
Call objNetSamp.AddUrl(userURL,"")
</script>
Open the IE browser, click the New button, and a dialog box will pop up to display the URL of the current page. Note that this item cannot be used at the same time as the Exec item set previously.
Finally, for button icons, IE requires two sizes of icons: 20x20 and 16x16. The former is used for display in normal state, and the latter is used for display in full screen, so the icon resources pointed to by HotIcon and Icon above should be A combination of three icons. The specifications of these three icons are as follows:
16x16 16-color icon (required)
20x20 16-color icon (optional)
20x20 256-color icon (required)
When designing icons, 256-color icons should use the Windows halftone palette, while 16-color icons should use the Windows 16-color palette.
http://www.cnblogs.com/goody9807/archive/2006/12/04/581359.html