The information in this article applies to:
SUMMARYThis article contains information that supplements the "Controlling the Context Menus" section in the "Reusing the Web Browser Control & MSHTML" overview in the Internet Client SDK. Specifically, this article describes optional registry keys to control the context in which added items are shown as well as a description of the context menu event object. MORE INFORMATIONHere is the full complete text of the section "Adding to the Standard Context Menus": Adding to the Standard Context MenusItems can be added to the existing context menus of the WebBrowser control by placing entries in the registry and linking these to URLs that execute script. To add additional items to the standard WebBrowser context menus, create or open the following key:
Under this key, you create a key (not a value) whose name contains the text
you want displayed in the menu. The default value for this key contains the
URL that will be executed. The key name can include the "&" character,
which will cause the character immediately following the "&" to be
underlined. The URL will be loaded inside of a hidden HTML dialog box, all
of the inline script will be executed, and the dialog box will be closed.
The hidden HTML dialog box's external.menuArguments property contains the
window object of the window on which the context menu item was executed.
The following registry entry will add an item with the title "My Menu Item" to the WebBrowser context menu and will execute the inline script contained in the file "c:\myscript.htm."
The following are the contents of "c:\myscript.htm."
This script obtains the parent window object from external.menuArguments.
The parent window object is the WebBrowser control in which the context
menu item was executed. The script then obtains the current selection and,
if no selection is present, inserts the text "MY INSERTED TEXT" at the
point where the context menu was executed. If there is a selection present,
the selected text is changed to uppercase.
Optional KeysUnder the item registry key created earlier, there are a couple of optional values. One of these specifies on which context menus this item will appear. The other specifies that the script should be run as a dialog box.The "Contexts" DWORD value specifies the context menus in which an item will appear. It is a bit mask consisting of the logical OR of the following values (defined in mshtmhst.h). These values correspond to the constant passed in a IDocHostUIHandler::ShowContextMenu call.
So for example, if you wanted your simple extension to appear only in the
default menu and the text selection menu, you could create a DWORD value in
the registry under the "My Menu Item" key called "Contexts" and set it to
0x11. From C/C++ code, this can be expressed as follows:
The other optional registry DWORD value is "Flags." There is only one bit
(0x1) valid for this registry value, and it is defined as
MENUEXT_SHOWDIALOG in Mshtmhst.h. When this bit is set, the script is run
just as if it had been called through the ShowModalDialog method. The
window that runs the script is not hidden and the dialog boxis not
automatically closed after inline and onload script finishes. The
external.menuArugments value still contains the window object where the
user selected the menu item.
The Context Menu EventWhenever a context menu extension is triggered, the event object off of the main window (external.menuArguments.event) contains information about where the user clicked and which context menu was shown. The mouse coordinates are valid along with event.srcElement. The event.type value contains one of the following strings, indicating which context menu was shown to the user:
Another ExampleThis example will create a new context menu item on just the default menu. This item, called "Show in New Window" will start whatever is clicked on in a new window. So, If something is deeply nested in a frameset, you can easily launch a specific frame in its own window. Here are the contents of a .reg file that can be run to insert the correct registry settings. Call this Example2.reg. Double-clicking on this file in the Explorer will insert the settings in your registry. REGEDIT4
Here are the contents of "C:\Example2.htm."
REFERENCES
Internet Client SDK: Internet Tools & Technologies; Reusing the Web Browser
Control and MSHTML; Overview
© Microsoft Corporation 1999, All Rights Reserved. Additional query words:
Keywords : kbIE400 kbIE401 kbIE500 AXSDKWebBrowser |
Last Reviewed: December 3, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |