Article ID: 177241
Article Last Modified on 3/21/2006
HKEY_CURRENT_USER
Software
Microsoft
Internet Explorer
MenuExt
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.
HKEY_CURRENT_USER
Software
Microsoft
Internet Explorer
MenuExt
My Menu Item = "file://c:\myscript.htm"
The following are the contents of "c:\myscript.htm."
<SCRIPT LANGUAGE="JavaScript" defer>
var parentwin = external.menuArguments;
var doc = parentwin.document;
var sel = doc.selection;
var rng = sel.createRange();
var str = new String(rng.text);
if(str.length == 0)
rng.text = "MY INSERTED TEXT";
else
rng.text = str.toUpperCase();
</SCRIPT>
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.
(0x1 << CONTEXT_MENU_DEFAULT) (evaluates to 0x1) (0x1 << CONTEXT_MENU_IMAGE) (evaluates to 0x2) (0x1 << CONTEXT_MENU_CONTROL) (evaluates to 0x4) (0x1 << CONTEXT_MENU_TABLE) (evaluates to 0x8) (0x1 << CONTEXT_MENU_TEXTSELECT) (evaluates to 0x10) (0x1 << CONTEXT_MENU_ANCHOR) (evaluates to 0x20) (0x1 << CONTEXT_MENU_UNKNOWN) (evaluates to 0x40)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:
(0x1 << CONTEXT_MENU_DEFAULT) | (0x1 << CONTEXT_MENU_TEXTSELECT)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.
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Show in &New Window] @="file://c:\\example2.htm" "Contexts"=dword:00000001Here are the contents of "C:\Example2.htm."
<SCRIPT LANGUAGE="JavaScript" defer>
open(external.menuArguments.location.href);
</script>
Keywords: kbhowto KB177241