How to add a menu item to the IE right-click menu

Source: Internet
Author: User
Tags exit implement key string window zip access ultraedit
Menu | Right button

If you have used netants friends may know, netants in IE, add the right menu function, as long as a link in the page or the picture on the right click on the menu after the select down by netants can call netants download the link point to the file. In this article, the author will describe how to implement this function through VB.

To implement the ability to add menu items to the IE right-click menu, follow these steps in turn:
1, in the registry HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\menuext to create a new item, the name of the item appears in the menu of the title, such as the menu you want to create the title of the Add URL , the name of the new item is the HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\menuext\add URL
2, the default value of the new item is set to a URL address, when the user clicks on the menu item, IE will call the URL to point to the script in the page, In the script of the target page, you can access the various objects on the page in IE, such as links, pictures, form fields, selected text, and so on, by accessing the menuarguments properties of the external object that IE provides. For more help, refer to the MSDN Help on Internetexplore object, and familiarize yourself with the window object to get a better understanding of the following script.
For the question of how to implement your own program Access menuarguments, we can emulate the netants approach by first building an OLE Automation object, then calling the object in the script, and passing the page information to the object. Below we need to first create an object through VB:
Open VB, click menu: File | New, select the ActiveX DLL in the New Project window and press the OK key to establish an ActiveX DLL project. Then change the Class1 Name property to Netapi in the Project List window, and then add the following code to 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 a netsamp.vbp. Then select File | In the menu Make NetSamp.dll establishes an object dynamic connection 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, and drag Netsamp.dll's icon to the Regsvr32.exe to release it, and Regsvr32.exe will pop up a dialog box to prompt the object to register successfully.
Open UltraEdit (or another text editor) to the following scripting code input 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

Call OnContextMenu ()

</script>

Save the file under C:\Program Files with the file name geturl.htm
As you can see from the script above, You first access the External.menuarguments property, get the object where the user clicks the right mouse button, then get its URL based on the object's difference, and then establish the Iecontextmenu.iemenu1 object and invoke the Addurl method of the object.
The next step is to create a registration entry for the right-click menu and open the UltraEdit (or other text editor) to the following registration data entry editor

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\menuext\&get URL]
@= "C:\\Program Files\\geturl.htm"
"Contexts" =dword:00000022

Save the file as a reg suffix, and then double-click the file in Windows Explorer to add the registration entry to the registry, then open IE, right-click a connection or picture, and a Get URL entry appears in the pop-up menu, click on the item, A message box appears showing the clicked connection or the URL of the image.

The following is an introduction to the role of the contexts item in the above registry, which can be used to create a menu item that appears when you right-click on the object in IE, which can be a combination of the following values:

Object value
Default 0x1
Picture 0x2
Control 0x4
form Field 0x8
Select text 0x10
Anchor Point 0x20

For example, we want the menu item to appear when the user clicks on a picture or hyperlink, and then we set the value to dword:00000022, and the menu appears when you click on the image or anchor point. An anchor point is an object in the page that describes a hyperlink. If you do not set the contexts item, the menu item appears in the right-click menu when you click on any object.
Through the above procedures, we can see the IE mouse right-click menu work process. As I said earlier, netants is using this method to invoke netants by creating objects in the script, so if we install netants, we can invoke Netants in the program by calling the Netants object.
To create a new project, click on the menu Projects | References, select the ANTAPI 1.0 Type Library Item, and if you do not click the browser button, select the NetAPI.dll in the network ant directory in the File list box and press the open key. Add a CommandButton button to the Form1 and add the following code to the Command1_Click event:

Dim Ant as New antapilib.antapiobj

Ant. Addurl "Http://www.applevb.com/z.zip", "" "," http://www.applevb.com/"

Click Command1, and then Netants will run and add Http://www.applevb.com/z.zip to the task.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.