Adding Menu Items
This tutorial explains how to add a menu item that runs a Windows application or that runs a script to the Tools menu or Help menu in Windows Internet Explorer. If you also want to create a toolbar button for the Microsoft Win32 application or script, see the Adding Toolbar Buttons tutorial.
Requirements and Dependencies
Developers who want to add items to the Tools menu in Internet Explorer must be familiar with the registry.
This feature is only available in Microsoft Internet Explorer 5 and later.
General Steps
The steps in this section must be followed when adding any items to the Tools menu in Internet Explorer. If any of the required steps are omitted, the item will not be displayed in the Tools menu.
- Create a valid GUID.
You can use Guidgen.exe from Microsoft Visual Studio, or Uuidgen.exe from the Windows Software Development Kit (SDK).
- Create a new key (using the GUID as the name) in the registry under:
HKEY_LOCAL_MACHINE
Software
Microsoft
Internet Explorer
Extensions
{GUID}{GUID} is the valid GUID that you created in step 1.
- Required. Create the following string values in the registry under the new key:
- CLSID - set the value equal to
{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}. This value indicates that the extension is of the CLSID_Shell_ToolbarExtExec class.HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\CLSID - MenuText - This is the text you want to be displayed in the menu. This text does not support any underlining of characters for shortcut keys, because there is no way to prevent conflicts.
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\MenuText
- CLSID - set the value equal to
- Optional. The following string values customize the location and tooltip of the new menu command.
- MenuCustomize - Set the value to "help" to have the menu item appear in the Help menu. If this string value doesn't exist or is set to something other than "help", the menu item will appear in the Tools menu.
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\MenuCustomize - MenuStatusBar - This is the text you want displayed in the status bar when the menu item is highlighted. This text should describe what the script associated with this menu item will do.
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\MenuStatusBar
- MenuCustomize - Set the value to "help" to have the menu item appear in the Help menu. If this string value doesn't exist or is set to something other than "help", the menu item will appear in the Tools menu.
Adding the Details
To complete the setup of the custom command, you must provide details of the action that takes place when the menu item is selected. The values that you need depend on how the menu item is implemented. The following list contains links to the sections with the steps required to complete the addition of a menu item.
COM Objects
In order to invoke a Component Object Model (COM) object from Internet Explorer, it must implement IOleCommandTarget. Only one command is supported per object; the COM object's IOleCommandTarget::Exec is always called with nCmdID=0 and with VARIANT arguments set to NULL. Additionally, the implementation of IOleCommandTarget::QueryStatus is always called with cCmds=1.
If the COM object needs to access the browser or Dynamic HTML (DHTML) Object Model of the active page, it must implement IObjectWithSite. Internet Explorer calls IObjectWithSite::SetSite with a pointer to IShellBrowser.
The following steps are required to complete the creation of an item in the Tools menu that implements a COM object.
- Register the COM object.
- Create a new string value, ClsidExtension, in the registry as follows:
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\ClsidExtensionSet the value of ClsidExtension equal to the GUID of the COM object.
Scripts
The following step is required to complete the creation of an item in the Tools menu that runs a script.
- Create a new string value, Script, in the registry as follows:
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\ScriptSet the value of Script to the full path of the script to be run.
To add a toolbar button with the same functionality, see the Adding Toolbar Buttons tutorial.
Executable Files
The following step is required to complete the creation of an item in the Tools menu that runs an executable file.
- Create a new string value, Exec, in the registry as follows:
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\ExecSet the value of Exec to the full path of the .exe file to be run.
To add a toolbar button with the same functionality, see the Adding Toolbar Buttons tutorial.
Related Topics
Couple of things that this article does not mention:
-
The location of the Script can actually be an URL. Beware UTF-8 escape sequences there!
-
If you are interested in running a JavaScript block, ensure that the block is in a .HTA file between these tags:
-
<script type="text/javascript"><!-- put your js code here
//--></script> -
The other thing is that if you try to use the standard document, window or any other DOM objects to get at the HTML loaded in the browser, they will not work. The reason is that the document object will be pointing right back to the context of the running script. So, if you want to get at the document loaded in the IE window that lauched this script, use the following section of code:
-
var parentwin = external.menuArguments;
var doc = parentwin.document; -
Use doc instead of document for accessing the document in the target browser window.
- 2/6/2008
- Mekkanik Mike
- 3/17/2010
- yecril