次の方法で共有


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
  • General Steps
  • Adding the Details
    • COM Objects
    • Scripts
    • Executable Files
  • Related topics

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.

Note  This tutorial describes how to add a menu item for all users. You can substitute HKEY_CURRENT_USER for HKEY_LOCAL_MACHINE in the steps below for settings that you want to make per user. Duplicate items found in HKEY_CURRENT_USER override those in HKEY_LOCAL_MACHINE.

 

  1. Create a valid GUID.

    You can use Guidgen.exe from Microsoft Visual Studio, or Uuidgen.exe from the Windows Software Development Kit (SDK).

  2. 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.

  3. 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
      
  4. 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
      

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
  • Scripts
  • Executable Files

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.

  1. Register the COM object.

  2. Create a new string value, ClsidExtension, in the registry as follows:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\{GUID}\ClsidExtension
    

    Set 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}\Script
    

    Set 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}\Exec
    

    Set 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.

Conceptual

About Browser Extensions

Web Accessories

Adding Toolbar Buttons