How to add a menu item to the IE right-click menu and how to add the IE taskbar button

Source: Internet
Author: User
Tags exit implement zip ultraedit
Buttons | menu | Right button

How to add a menu item to the IE right button
If you have used netants friends may know, netants in IE added a right-click menu function, as long as a link in the page
Or click on the right button in the picture and choose down by netants in the menu to invoke netants to download the file that the link points to. In this
In this paper, the author will introduce how to achieve this function through VB.
To implement the ability to add menu items to the IE right-click menu, follow these steps in turn:
1, under the registry HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\menuext to establish a
New item, the name of the item appears in the menu title, for example, if you want to create a menu item with the Add URL, the name of the new item is called
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 point to the page in the foot
In the script of the target page, you can access the menuarguments properties of the external object provided by IE in the page in IE.
Various objects, such as links, pictures, form fields, selected text, and so on. For more help please refer to the MSDN about Internetexplore object
Help, familiarize yourself with the window object to get a better understanding of the script below.
For the question of how to implement your own program Access menuarguments, we can emulate Netants's approach by first building a
OLE Automation The object, and then calls the object in the script and passes the page information to the object for processing. Below we need to first set up through VB
An object:
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
Engineering. 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 Build Object dynamics
Connection library.
Next is the registration library, locate the Regsvr32.exe in the Windows directory, and then copy it to the Netsamp.dll directory and
Netsamp.dll's icon is dragged onto the Regsvr32.exe, 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 and get the object where the user clicks the right mouse button.
It then obtains its URL based on the object's differences, then establishes the Iecontextmenu.iemenu1 object and invokes the object's Addurl method.
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 registry entry to the registry, and then open
IE, right click on a connection or picture, in the pop-up menu will appear a Get URL entry, click on the item, there will be a message box display
Click on the connection or the URL address of the picture
The following is an introduction to the role of the contexts item in the above registry, which allows you to make a menu item when you right-click on IE.
appears, it 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 the image or hyperlink, so we set the value to dword:00000022, both in the
The menu appears when you click on a picture 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 before, Netants is using this method
To create an object in the script to implement the call netants, then if we install netants, we can call Netants object in the program
Call Netants.
To create a new project, click on the menu Projects | References entry, select the ANTAPI 1.0 Type Library Item, if no
Click on the Browser button, in the File list box, select the NetAPI.dll in the network ant directory and press the open key. Add a CommandButton to the Form1
button, add the following code to the Command1_Click 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 add Http://www.knowsky.com/z.zip to the task.


Ii. How to add a taskbar button
Basically, adding a taskbar button only needs to be done by modifying the registry. To implement the Add button by modifying the registry, follow these steps:

1, establish a GUID.
2, open Registry Editor, go to hkey_local_machine\software\microsoft\internet explorer\extensions section,
Add a new item under it, named <your guid>, Your GUID for the GUID you just created.
3, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value, named Hoticon, that defines the icon when the button has a hotspot, and its general type is:
Contains the file full path name of the icon, the icon index, for example:
C:\progra~1\kingsoft\xdict\ieplugin. dll,208
4, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value, named icon, that defines the icon for the button, and its general type is:
Icon file full path name, icon index
5, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value, named ButtonText, that defines the ToolTip text for the button.
6, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value, named Default Visible, that defines whether the button is visible, and if so, the value is set
Is "Yes", otherwise set to "No".
7, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value, named CLSID, that sets the value to {1FBA04EE-3024-11D2-8F1F-0000F87ABD16}
8, in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Creates a new string value named EXEC that defines the full path name of the file that runs after the click of the button, for example:
C:\Program Files\samples\net.exe

For example, the contents of the Netants button registry key are 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-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"

When the Netants button is clicked, the netants is run. The following two items in the registry key above: MenuText Item Add a menu item to the menus
Tool bar, the Menustatusbar item definition displays the prompt text in the status bar when the cursor is moved to the added menu bar. Also in the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid> can also add a name called
Menucustomize String type value, setting this value to "help" will cause the menu item to appear in the Assistance menu bar, otherwise it appears in the Tools bar.

Of course, we will not be satisfied with just adding a button to execute a program that we want to be able to get when the user clicks on the button to manipulate the current
Page, in the registry of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\extensions\<your guid>
Create a new string value with the name set to the full path name of an HTM file, as described in the previous add-right menu, in the click
After the button, IE will call the file, in the file by setting VBScript access to the external object's Menuarguments property can be obtained in the browser
Page. For example, we will hkey_local_machine\software\microsoft\internet Explorer\extensions\<your Guid>\vbscript
The value is set to C:\Program Files\samp.htm, then create a file named samp.htm under C:\Program Files, and enter the following
Script content:
<script language= "VBScript" >

Set objnetsamp=createobject ("iecontextmenu.iemenu1")
Userurl=external.menuarguments.location.href
Call Objnetsamp.addurl (Userurl, "")

</script>
Open IE Browser, click the New button, pop-up dialog box will display the current page URL. Note that this item cannot be used concurrently with the exec item previously set.
Finally, for the button icon, IE needs two dimensions of the icon: 20x20 and 16x16, the former for the normal state of the display, the latter for the full screen
Under the display, so the above Hoticon and icon pointing to the icons resource should be a combination of three icons, these three icons are the following specifications:
16x16 16-color icon (must)
20x20 16-color icon (optional)
20x20 256-color icon (must)
When you design an icon, the 256-color icon should use the Windows Halftone palette, while 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.