Right-click IE and choose add from the shortcut menu.

Source: Internet
Author: User
Tags ultraedit

1. How to add menu items in the IE right-click menu

If you have ever used NetAnts, you may know that NetAnts has added the right-click menu function to IE. You only need to right-click a link or image on the page and select
Down by NetAnts, you can call NetAnts to download the file pointed to by this link. In this article, 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. In the registry, HKEY_CURRENT_USER/software/Microsoft/Internet
Explorer/menuext
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 script on the page pointed to by the URL, in the script on the target page, access
The menuarguments attribute of the external object can access various objects on the page of IE, such as links, images, form fields, and selected text. Detailed Help
For help, refer to the help on internetexplore object in msdn, and familiarize yourself with the window object to better understand the following script.

We can follow NetAnts's practice to create an 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 create an object through VB:

Open VB, click File | new, select ActiveX DLL in the new project window, and press OK to create an ActiveX dll project. In the project list window, change the name attribute of class1 to netapi, and add the following code in the code window of netapi:
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. Select File | make from the menu.
Netsamp. dll creates an object dynamic Connection Library.

Access the registration database. Find regsvr32.exe in the Windows directory, copy it to the directory where netsamp. dll is located, and copy netsamp. dll
To the regsvr32.exe. then, 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:
<Script
Language = "VBScript"> ..

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
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
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 to C:/program files. The file name is
Geturl.htm

As you can see from the script above, first access the External. menuarguments attribute, get the object with the right-click position, and then obtain it based on the object
Then 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, open IE, right-click a connection
Or an image, a get URL item appears in the pop-up menu. Click this item to display a message box showing the URL of the clicked connection or image.

Next, we will introduce the role of the contexts item in the above registration items. This item can be used to determine what objects the menu item appears when right-clicking on IE. It can be a "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, that is, when you click an image or
The menu appears at the anchor point. An anchor is an object that describes a hyperlink on a page. If the contexts item is not set, the menu item appears in the context 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 to call NetAnts by creating an object in the script. If NetAnts is installed, you can call NetAnts by calling the NetAnts object in the program.

Create a new project, click projects | references, and select antapi 1.0 Type Library
If the browser button is not clicked, select netapi. dll under the Network ant directory in the file list box and press the open key. In
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.knowsky.com/z.zip ","",
"Http://www.knowsky.com /"

Click command1 and then NetAnts will run and send http://www.knowsky.com/z.zip to the task.

2. How to add the taskbar button

Basically, you only need to modify the Registry to add the taskbar button. To add a button, follow these steps :.

1. Create a guid.
2. Open Registry Editor and go to HKEY_LOCAL_MACHINE/software/Microsoft
/Internet Explorer/extensions section,
Add a new item under it, named <your guid>
, Your GUID is the guid you just created.
3.
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value named hoticon.
Defines the icon when a button has a hotspot. Its general type is:
The full path name and Icon index of the file containing the icon, for example:
C:/progra ~ 1/Kingsoft/xdict/ieplugin. dll, 208
4,
In the Registry's HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value named icon. The value is defined
The icon of the button, which is generally of the following type:
Full path name and Icon index of the icon file
5. In the Registry
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value named
Buttontext, which defines the tooltip Text of the button.
6. In the Registry
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value named default
Visible, which defines whether the button is visible. If yes, this value is set ..

Yes ",
Otherwise, set it to "no ".
7. HKEY_LOCAL_MACHINE/software/Microsoft/Internet in the Registry
Explorer/extensions/<your guid>
Create a new string type value named clsid.
Set to {1fba04ee-3024-11d2-8f1f-440f87abd16}
8.
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value named exec. This value defines the point
The full path name of the file to run after clicking the button, for example:
C:/program files/samples/net.exe.

For example, the content of the NetAnts button registry key is as follows :.

Windows Registry Editor Version 5.00.

[HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/{57e91b47-f40a-11d1-b792-444553540000}]
"CLSID" = "{1fba04ee-3024-11d2-8f1f-440f87abd16 }"
"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 ".

When you click the NetAnts button, NetAnts runs. In the preceding registry, add a menu item to the tool bar of the menutext item, the menustatusbar item defines the text displayed in the status bar when the cursor moves to the added menu bar. In addition
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
String type of menucustomize
Value. setting this value to "help" will make the menu item appear in the "help" menu bar. Otherwise, it will appear in the "Tools" column.

Of course, we do not want to add a button to execute a program. We hope that the user can control the current page when clicking the button.
HKEY_LOCAL_MACHINE/software/Microsoft/Internet
Explorer/extensions/<your guid>
Create a new string type value. The name is set to
The full path name is the same as adding a right-click menu in the previous section. After you click the button, ie calls this file and sets VBScript to access the External Object
The menuarguments attribute can be used to obtain pages in the browser. For example, we set HKEY_LOCAL_MACHINE/software
/Microsoft/Internet Explorer/extensions/<your guid>/VBScript value is set to C:/program files/samp.htm, and then in C:/Program
Create a file named samp.htm under 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 IE browser and click "new". A dialog box is displayed, showing the URL of the current page. Note that this item cannot be used together with the previously set exec item.

Finally, for Button icons, ie requires two types of icons: 20x20 and 16x16. The former is used for normal display, and the latter is used for display on the full screen.
Hoticon and Icon should point to 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)

In the design drawing, the 256 color icon should use the windows half color palette, and the 16 color icon uses the Windows 16 color palette.

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.