How to add menu items in IE right-click menu

Source: Internet
Author: User
Tags ultraedit

If you have used NetAnts, you may know that NetAnts has added the right-click menu function in IE, as long as a link to the page
Or right-click the image and select down by NetAnts from the menu to call NetAnts to download the file pointed to by this link. In
The author will introduce how to use VB to implement such a function.
To implement the function of adding menu items in the right-click menu of IE, perform the following steps in sequence:
1. Create
New item. The item name appears in the menu title. For example, if you want to create a menu item with the title of add URL, the name of the new item is
HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ menuext \ add URL
2. Set the default value of the new item to a URL address. After you click the menu item, ie will call the foot in the page pointed to by the URL.
In the script on the target page, you can access the page in IE by accessing the menuarguments attribute of the external object provided by IE.
Various objects, such as links, images, form fields, and selected text. For more information, see internetexplore object in msdn.
With the help of window object, you can better understand the following script.
How to implement your own Program To access menuarguments, we can follow NetAnts's practice and first establish
OLE Automation Object, then call the object in the script, and pass the page information to the object for processing. Next we need to first establish
One object:
Open VB and click File | new. In the new project window, select ActiveX DLL and press OK to create an ActiveX DLL.
Project. In the project list window, change the name attribute of class1 to netapi. Code Add the following code in the 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 object Dynamics
Connection Library.
Access the registration database. Find regsvr32.exe in the Windows directory and copy it to the directory where netsamp. dll is located.
The graph of netsamp.dllis dragged to regsvr32.exe. the regsvr32.exe dialog box prompts that the object is successfully registered.
Open ultraedit (or another text editor) and input the following script code to the Editor:

<S required language = "vbs succeeded">

Sub oncontextmenu ()
On Error resume next
Set srcevent = External. menuarguments. Event
Set eventelement = external.menuarguments.doc ument. 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 ()

</S response>

Save the file to c: \ Program Files. The file name is geturl.htm.
As shown in the preceding script, first access the External. menuarguments attribute to get the object at the right-click position of the user.
Then obtain the URL of the object based on the object, create the iecontextmenu. iemenu1 object, and call the addurl method of the object.
Next, create a registration item for the right-click menu, open ultraedit (or another text editor), and enter the following registration data in the 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 with the suffix Reg, double-click the file in Windows Resource Manager to add the registration entry to the Registry, and then open
IE, right-click a connection or image, a get URL item will appear in the pop-up menu, click this item, a message box will appear
URL of the clicked connection or image
Next, we will introduce the role of the contexts item in the above registration items. With this item, we can use it to determine what object the menu item is when right-clicking on IE
It can be an "or" combination of the following values:
Object Value
0x1 by default
Image 0x2
Control 0x4
Form field 0x8
Select text 0x10
0x20 anchor point
For example, if you want the menu item to appear when you click an image or hyperlink, set the value to DWORD: 00000022
Click the image or anchor to display the menu. An anchor is an object that describes a hyperlink on a page. If the contexts item is not set, the menu item
It will appear in the right-click menu when you click any object.
Through the above program, we can see the IE right-click menu working process. As mentioned above, NetAnts uses this method
Create an object in the script to call NetAnts. If NetAnts is installed, you can call the NetAnts object in the program.
Call NetAnts.
Create a new project, click projects | references, and select the antapi 1.0 Type Library item.
Click the browser button, select netapi. dll under the Network ant directory in the file list box, and press the open key. Add a commandbutton in form1
Button to add the following code to the commandmediaclick 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 at 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.