BHO开发浏览器插件-Adding Menu Items

以下内容来自MSDN:

Adding Menu Items


This tutorial explains how to add a menu item that runs a Microsoft Windows application or that runs a script to the Tools menu or Help menu in Microsoft 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 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) World Wide Web link.

  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

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.

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

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


开发参考文章:http://www.iteye.com/blogs/subjects/ray_linn2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值