分享
 
 
 

定制IE 5.0

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

定制IE 5.0

Download the code (13KB)

定制IE 5.0

Dino Esposito 

张中华 翻译讲解

==============

张某前言:金山词霸、网络蚂蚁这些软件是怎么在IE5.0里添加工具条按钮和右键菜单呢?读了Dino Esposito的这篇文章,你就一清二楚了。你可以只看中文翻译讲解部分,如不能充分理解明白,请看对照的原文。

本文原文在MSDN网站上有:

Dino Esposito, "Customizing Microsoft Internet Explorer 5.0", MIND, 1999年11月期

在MSDN中的路径为:

Periodicals ¦ Periodicals 1999 ¦ Microsoft Internet Developer ¦ November

MSDN中,关于IE应用开发的更多信息位于:

Platform SDK ¦ Web Services ¦ Workshop ¦ Reusing Browser Technology

由于这里不能放图片,建议看译者网站上的:

http://zzh-cn.com

==============

Nowadays, writing a completely custom browser is not a difficult task—provided you can rely on the WebBrowser control that's available starting with Microsoft?Internet Explorer 3.0. The browser helper objects (BHO) introduced with Internet Explorer 4.0 gave you an opportunity to add even complex new functionality to the original browser. A couple of working examples of BHOs can be found in Scott Roberts' article in the May 1998 issue of MIND and in the January/February 1999 issue of MSDN?News.

==============

翻译讲解:有哪些技术、工具可用来定制IE浏览器呢?从IE3.0开始提供的WebBrowser control,从IE4.0开始提供的Browser Helper Objects(BHOs),就是让开发人员用来定制IE的。Scott Roberts和Dino Esposito写有BHOs相关的介绍文章:

Scott Roberts, "Controlling Internet Explorer 4.0 with Browser Helper Objects", MIND, 1998年5月期

Dino Esposito, "Browser Helper Objects: The Browser the Way You Want It", MSDN News, 1999年1/2月期

==============

There is just one aspect missing from all these pre-Internet Explorer 5.0 programming goodies: you couldn't associate new functionality with the browser's user interface. You had no way to add new toolbar buttons or to customize any of the menus. Thankfully, this problem has been solved with Internet Explorer 5.0.

==============

翻译讲解:但是这些IE5.0之前的技术有个缺点:就是你不能把功能和用户界面联系起来,即你不能往工具条上增加按钮,也不能往菜单里增加菜单项。谢天谢地,IE5.0解决了这些问题。

==============

Let's look at the new ways you can interface with the Internet Explorer UI, the points at which you're allowed to intervene, and what you can actually obtain through code. I'll briefly review the highlights of BHOs, focusing on scripting-related aspects of Internet Explorer 5.0 customization and registry changes. Windows Script Host (WSH) will be my development environment of choice here.

==============

翻译讲解:现在就让我们看看是怎么做的,本文使用的开发环境为Windows Script Host(WSH)。

==============

Customizable Aspects of Internet Explorer 5.0

Figure 1 summarizes the aspects of Internet Explorer 5.0 that can be considered customizable. In particular, you can add new toolbar buttons and menu items. For each, you specify the text and icons to add to the particular object, as well as the code that you should run when the user selects the new entry. The browser has a number of context menus that appear when you right-click an image, a document, a table, an ActiveX?control, selected text, and other items. You can add new items to any of the context menus and have full control over the whole process that displays the menu. In other words, you can detect when the context menu is about to be shown and add your changes on the fly.

==============

翻译讲解:Figure 1概括了IE5.0可定制的方面。最令人关注的就是可增加工具条按钮和菜单项。右键点击弹出的菜单叫context menu,也可以往里面增加菜单项。

==============

Internet Explorer 5.0 comes with a number of related applications that let you work outside the Web, such as email or news readers, HTML editors, and so on. You can modify the list of available applications to fit your needs. The search bar can be enhanced and you can even use your own search panel.

==============

翻译讲解:和IE5.0相关的程序还有电子邮件和新闻阅读器(OutlookExpress),网页编辑器(FrontPage)等。在Internet选项对话框中程序那一栏里,有个列表列出可供选择的程序,你可以把你喜爱的程序(Foxmail, Dreamweaver)加入列表中。

==============

Technologies like Dynamic HTML (DHTML), behaviors, and XML provide excellent tools for customizing and extending browser features. You can create a browser implementing the IDocHostUIHandler interface, and expose a completely custom object model through that interface's External property (see "Take Total Control of Internet Explorer with Advanced Hosting Interfaces," by Scott Roberts in the October 1998 issue of MIND). You can use behaviors to customize the way a certain HTML tag reacts to user and browser solicitations by extending it with new methods, properties, and events.

==============

翻译讲解:用来定制或扩展浏览器的技术有动态HTML(DHTML), behaviors, XML等。例如,通过实现一个IDocHostUIHandler 接口可以创建一个浏览器,参见:

Scott Roberts, "Take Total Control of Internet Explorer with Advanced Hosting Interfaces", MIND, 1998年10月期

==============

Customization Techniques

Customization of the Internet Explorer 5.0 user interface involves four elements: COM components, HTML, script files, and the registry. By writing a special COM component or script file and entering some keys and values to the registry, you can personalize the Internet Explorer interface. As I mentioned earlier, I won't discuss the COM stuff in depth here, but I will give you an overview of the COM component you can write to interact with Internet Explorer 5.0.

==============

翻译讲解:定制IE5.0涉及4种元素:COM组件,HTML,Script文件,注册表。往注册表里添加一些Keys和Values,写一个特定的COM组件或Script文件,就可以定制IE的界面了。

==============

There are basically four types of Internet Explorer-specific COM objects: BHOs, BHOs with custom commands, command-only objects, and the Explorer deskband.

==============

翻译讲解:基本上,与IE相关的COM object有4种类型:BHOs,带定制命令的BHOs,command-only objects,Explorer deskband。

==============

A BHO is a simple COM server that is only required to implement the IObjectWithSite interface. You can create a BHO with ATL by choosing the Internet Explorer object template from the ATL objects gallery. BHOs are also supported by Windows Explorer (if you're running shell version 4.71 or greater) and Internet Explorer 4.0. BHOs don't necessarily link with the UI; they are just actions you take when starting the browser. BHOs are passed a pointer to the browser's IUnknown interface.

==============

翻译讲解:一个BHO是一个简单的COM server,只需实现IObjectWithSite接口即可。可以用ATL创建一个BHO,从ATL objects gallery中选择Internet Explorer object template。Windows Explorer和IE4.0也支持BHOs。BHOs并不和UI相连,它只是在浏览器启动时起作用。BHOs会接收到一个指向浏览器IUnknown接口的指针。

==============

You can add new commands to the browser by writing BHOs, or even simpler COM objects, that implement IOleCommandTarget. With this interface, Internet Explorer 5.0 knows how to ask your component to execute a function. Such a component needs to be associated with a menu item or a toolbar button. The difference between a BHO and a COM server implementing IOleCommandTarget is that a BHO can easily access (via the received IUnknown pointer) any object model exposed by the document being viewed.

==============

翻译讲解:如果要往浏览器里加入命令,那么写BHOs,或更简单的COM object时,要实现IOleCommandTarget接口。IE5.0通过这个接口和你的组件交互并执行某项功能。这种组件需要和一个菜单项或一个工具条按钮联系起来。这种实现IOleCommandTarget接口的COM server和前面介绍的实现IObjectWithSite接口的BHOs的区别是:实现IObjectWithSite接口的BHO可以很容易地访问正被浏览的文档中的object model(这是因为上面说到过的,它会接收到一个指向浏览器IUnknown接口的指针)。

==============

An Explorer deskband is a docking window that you can employ as the left pane of your browser. By default, the deskband is a window within Explorer that shows the shell's namespace. Other predefined deskbands allow you to see the Search, History, and Favorites panels. Usually, the available deskbands are listed under the View ¦ Explorer Bar menu both for Windows Explorer and Internet Explorer (see Figure 2).

==============

翻译讲解:Explorer deskband是一个浮动窗口,你可以用来作为你的浏览器的左窗格。缺省情况下,deskband显示shell的名字空间(目录树)。其它预定义的deskband用来显示搜索,历史记录,收藏夹等。通常地,这些可用的deskband在Windows Explorer和IE的查看 ¦ 浏览栏菜单中罗列出来,见Figure 2。

==============

Figure 2: Available Deskbands

Writing a custom deskband is neither painfully difficult nor particularly easy. A few examples can be found in the latest Platform SDK.

==============

翻译讲解:写一个定制的deskband不难(对高手而言),也不易(对初哥而言),在最新的Platform SDK中可以找到一些例子。

==============

Adding a New Toolbar Button

To add a new button to the Internet Explorer 5.0 toolbar, you just write some new entries to the system registry. You define the icons to be used, the text to be shown, and what happens when someone clicks the button. A toolbar button always has a corresponding menu item, which is automatically added at the bottom of the Tools menu. The Windows Scripting Host (WSH) script shown in Figure 3 demonstrates how to create a new button called Run Script. The final effect is shown in Figure 4.

==============

翻译讲解:要往IE5.0的工具条上加按钮,你只要往注册表里加些条目即可。内容包括使用什么图标,显示什么文字,点击按钮时该做什么等。每个工具条按钮总有相应的菜单项,它会被自动加到工具菜单的底部。Figure 3 的WSH Script举例演示了如何添加一个名为Run Script的新按钮,Figure 4显示了最终结果。

==============

Figure 4: The New Run Script Toolbar Button

There are two categories of information to be added for a new button: configuration and behavior. Figure 5 shows the entries that describe the button. All the entries mentioned here are strings (type REG_SZ). Notice that if Default Visible is set to No, the button won't appear on the toolbar, although it will still be available through the toolbar's Customize dialog. If the user has already customized the toolbar, the button will not appear on the toolbar automatically no matter the value of Default Visible.

==============

翻译讲解:用什么定义一个新按钮呢?有两种信息:configuration和behavior。Figure 5 显示了描述一个按钮所需的条目。这里提到的所有条目都是字符串(REG_SZ类型)。要注意,如果Default Visible设为No,那么该按钮不会出现在工具条上,虽然它在工具条的定制对话框中仍然可以看到。如果用户早就定制过了工具条,那么无论Default Visible的值是什么,按钮都不会自动出现在工具条上。

==============

The Clsid entry can take two possible GUIDs as values: {E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}

and

{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}

Use the first GUID if you're attaching a deskband to the button, otherwise use the second one.

These entries must all be written to the following root key:

HKEY_LOCAL_MACHINE

\Software

\Microsoft

\Internet Explorer

\Extensions

Under this path, however, you have to create a new key with a unique GUID. You can use GuidGen.exe to generate a new one. Incidentally, this is exactly what I did to come up with the GUID in Figure 3. Notice that as long as you use the HKEY_LOCAL_MACHINE root node, the button will be visible to all users on the specified machine. If you want it to apply only to certain users, enter the registry changes under the HKEY_CURRENT_USER node instead.

==============

翻译讲解:Clsid条目的值是一个GUIDs,有两种选择可能:

{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16} 和 {1FBA04EE-3024-11D2-8F1F-0000F87ABD16}如果你想把一个deskband连接到按钮上,使用第一个GUID,否则用第二个(多数情况)。

这些条目放在注册表里的什么地方呢?其根Key为: HKEY_LOCAL_MACHINE

\Software

\Microsoft

\Internet Explorer

\Extensions

在此路径下,创建一个新Key,其名字应为一个唯一的GUID。你可以用GuidGen.exe程序来产生这个GUID,作者就是这样得到Figure 3

中的GUID 的。注意,当你在HKEY_LOCAL_MACHINE 根节点下增加这些条目时,这台机器上的所有用户都能看到这个按钮。如果你只想让某些特定的人看到,改放到HKEY_CURRENT_USER根节点下。

==============

These changes are sufficient to make a new button appear on the Internet Explorer toolbar. The icons must include two formats each: 16X16 (16 colors) and 20X20 (256 colors). You can create these icons with the integrated resource editor of Visual Studio? To give the button an associated behavior, you have three options: running an executable, running a script or an HTML page, or invoking a command defined in some COM component implementing the IOleCommandTarget interface. Let's take a look at what you have to add to the registry in each case.

==============

翻译讲解:为了让新按钮出现在工具条上,注册表做这些改动就可以了。要求图标的格式有两种:16X16 (16色) and 20X20 (256 色)。你可以用Visual Studio内集成的resource editor创建这些图标。给该按钮赋予相关的behavior,你有3种选择:运行一个可执行文件,打开一个script或HTML页面,或者引发一条命令,该命令定义在某些实现了IOleCommandTarget接口的COM组件中。让我们看看在每种情况下,注册表里要添加些什么。

==============

To spawn an external program you need to add a further value, Exec, whose content is the fully qualified name of the executable. My tests indicate that you can't specify a command-line argument. For example, notepad.exe

works fine, while

notepad.exe file.txt

doesn't, even if you surround the whole thing with quotes.

==============

翻译讲解:如果要运行一个可执行文件,你需要增加一个value,其名字为Exec,内容为可执行文件的全路径名(网络蚂蚁就这样做)。作者测试结果表明,不能指定命令行参数,如

notepad.exe

可正常工作,而 notepad.exe file.txt

却不行,即使把全部字符串用双引号括起来也一样。

==============

If your goal is to run a Web page or a script file, then you have to change the entry. Use Exec for a Visual Basic?Scripting Edition (VBScript) or JScript script, and use Script for an HTML page. There are some subtle differences between these two options. Exec means that the specified file is executed through the program registered to manage that type of file. If you use the Exec entry with an HTML file, you force the default browser (in most cases Internet Explorer 5.0 itself) to navigate to that page. If you use Exec with a .vbs file, you simply end up executing that code—provided that you have WSH properly installed. Running a VBScript or a JScript file as a standalone executable doesn't let you access the current instance of the browser and the object model exposed by the currently viewed document. If you want to use these objects, you must resort to using an HTML file that contains only script code and run it through a Script (not Exec) entry. For example, this code<SCRIPT LANGUAGE="JavaScript">

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 = "HELLO, MIND!";

else

rng.text = str.toUpperCase();

</SCRIPT>

adds "HELLO, MIND!" to the current page when you click the button.

==============

翻译讲解:如果要执行一个VBScript或者JScript script,仍是用Exec,如果要打开一个HTML页面,Value的名字要改用Script。两种情况的差别是:Exec意味着指定的文件是由它的关联程序所执行的。如果你在Exec中指定一个HTML文件,会启动缺省浏览器(IE5.0)去浏览该页面文件。如果你在Exec中指定一个.vbs文件,那只是简单地执行其中的代码,当然,WSH必须安装妥当。VBScript或JScript文件作为单独可执行文件运行时,你访问不到当前浏览器的instance 和由当前正被浏览的文档所exposed出来的object model 。如果想使用这些objects,你必须写一个HTML文件,其中仅包含script代码,并用Script (而非Exec)来执行之。例如,当你点击按钮时,下面这些代码:

<SCRIPT LANGUAGE="JavaScript">

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 = "HELLO, MIND!";

else

rng.text = str.toUpperCase();

&nbsp;</SCRIPT>会在当前页面中加一句"HELLO, MIND!" 。

==============

Using the Script entry and a script-only HTML file allows you to use the External object to access the document's object model. If you put any decorative tags in this HTML file, they will be ignored.

==============

翻译讲解:就这样,使用Script条目和一个script-only HTML文件,能让你使用External object去访问文档的object model。如果你往这个HTML文件中加入任何HTML tags,它们都会被忽略。

==============

Finally, you can establish a link between an Internet Explorer 5.0 toolbar button and a COM object via the ClsidExtension entry. Its content is the CLSID of the COM object implementing the IOleCommandTarget interface. If you have a deskband, use the BandClsid entry instead of ClsidExtension.

==============

翻译讲解:最后一种情况,把IE5.0的工具条按钮连接到一个COM object上,添加的Value名字为ClsidExtension,其内容是那个实现了IOleCommandTarget接口的COM object的CLSID(金山词霸就这样做)。如果是一个deskband,用BandClsid而非ClsidExtension。

==============

Accessing the Document Object Model

I mentioned earlier that if you want to access the document object model (DOM), you have to resort to the Script entry and a script-only HTML file. Well, that's not completely true. Or rather, it's true if you want to rely on the standard capabilities of Internet Explorer. However, if you have a brave heart and know how to build a simple Visual Basic-based COM object, you can have both your WSH scripts and a standalone executable that accesses the object model of the document being viewed through Internet Explorer.

==============

翻译讲解:早先曾提到,如果你想要访问document object model (DOM),你必须借助于Script条目和一个script-only HTML文件。Well,那并不完全正确。或者说,如果你只是依赖IE的普通做法,那只能如此。然而,如果你有一颗勇敢的心,并且知道如何创建一个简单的VB-based COM object,那么无论用WSH scripts还是用单独的可执行文件,你都可以访问正被IE浏览的文档的object model。

==============

You need two pieces of information: the instance of Internet Explorer that's running your script, and the way to connect to a running instance of Internet Explorer. Every running instance of Internet Explorer has its own window, and every window has its own unique handle (HWND). Internet Explorer 5.0 makes available a COM object that returns the collection of all the running instances of both Explorer and Internet Explorer. Such an object is of type ShDocVw.ShellWindows. It was also available for Internet Explorer 4.0, albeit with a slightly different name. Once you've created an instance of this object, you have a reference to all the running instances of Internet Explorer. You just have to distinguish between Windows Explorer and Internet Explorer and realize which instance of Internet Explorer is actually running your script.

==============

翻译讲解:有两点关键:哪一个IE的Instance执行着你的script,如何connect到一个运行中的IE的Instance上。每个运行中的IE的Instance都有它自己的窗口,每个窗口都有它自己唯一的handle (HWND)。IE5.0中有个COM object,其类型为ShDocVw.ShellWindows,它可以返回所有运行中的Windows Explorer和IE的Instance的一个集合。一旦你创建了这个object的一个instance ,你就获得了一个所有Windows Explorer和IE的运行中的Instance的reference。你要做的只是区分出哪些是Windows Explorer的,哪些是IE的,并且找出实际执行你的script的IE的Instance。

==============

A user who wants to run a script would click on a toolbar button, which automatically means that the foreground window is Internet Explorer. The handle of the foreground window is returned by the GetForegroundWindow API function. Hence, the algorithm is:Get the collection of the active instances of Internet Explorer.

Walk the collection.

For each instance of Internet Explorer, compare the handle of the main window with the foreground window.

There's just one possible match. When you've found that, you've found the instance of Internet Explorer that ran your script.

==============

翻译讲解:当用户点击工具条按钮时,系统的foreground窗口正是IE,用GetForegroundWindow API函数可返回foreground窗口的handle。因此,算法过程是:取得运行中的IE的instances的一个集合。遍历该集合。

对每个运行中的IE的instance,把它的主窗口的handle和foreground窗口的handle比较。只可能有一个是match的。当你找到时,它就是执行你的script的IE的instance。==============To execute all of this from within a WSH script, I wrote a very simple Visual Basic-based object whose source code is shown in Figure 6. This object (the progID is IE5Script.Instance) exposes four properties: HWND, Title, IEDocument, and IEObject. HWND returns the handle of the foreground window. Title returns the caption of the foreground window. IEDocument matches the foreground window with the various copies of Internet Explorer and returns the Document object of the right instance. (If you expect to execute this from a script associated with an Internet Explorer toolbar button, you must have at least one copy of Internet Explorer running!) Finally, IEObject returns a reference to the application object of Internet Explorer. Through the value retrieved by this property, you can drive the whole Internet Explorer object model.

==============

翻译讲解:为了在一个WSH script内执行所有这4个步骤,作者写了个非常简单的VB-based object,其源码列在Figure 6中。这个object(其progID是IE5Script.Instance)exposes4个属性:HWND, Title, IEDocument, 和IEObject。 HWND返回foreground窗口的handle,Title返回foreground窗口的标题,IEDocument返回显示在屏幕最前面的IE的instance中的Document object。(当你点击IE的工具条按钮时,这个IE的instance就显示在屏幕最前面,其窗口就是foreground窗口!)最后,IEObject返回一个IE的application object 的reference。通过这些属性值,你就可以drive整个IE的object model了。

==============

A script that wants to access the DOM can do something like this: Set obj = CreateObject("IE5Script.Instance")

Set myPageObj = obj.IEDocument

From now on, myPageObj can be used to access the various items that form the DHTML object model. For example, you could enumerate all the links in a page:

Set obj = CreateObject("IE5Script.Instance")

Set myPageObj = obj.IEDocument

For Each lnk In myPageObj.links

txt = txt & lnk.href & vbCrLf

Next

MsgBox txt

Figure 7 shows the final result.

==============

翻译讲解:想要访问DOM,script可以写成这样: Set obj = CreateObject("IE5Script.Instance")

Set myPageObj = obj.IEDocument

从现在开始, myPageObj就可以用来访问DHTML object model中各种各样的items 了。例如,你可以把页面中的连接一一列举出来: Set obj = CreateObject("IE5Script.Instance")

Set myPageObj = obj.IEDocument

For Each lnk In myPageObj.links

txt = txt & lnk.href & vbCrLf

Next

MsgBox txtFigure 7显示了最终结果。

==============

Figure 7: Enumerating Links in a Page

Modifying the Menus

You can also modify the Internet Explorer 5.0 menu without affecting the toolbar. As mentioned earlier, each toolbar button has a corresponding command in the Tools menu. However, this is only true in the default case. In other words, a new command goes under the Tools menu unless you specify otherwise. Unfortunately, you can't add the menu item wherever you want. You have just two choices: you can add it under the Help menu or the Tools menu. By default, it goes under Tools unless you create another string value called MenuCustomize when you're setting up the registry entries. Set MenuCustomize to "Help" and the menu item will appear under the Help menu. Set it to any other string (say, "File") and the menu item will appear under the Tools menu.

==============

翻译讲解:你可以修改IE5.0的菜单而不影响工具条。早先时候提到过,每个工具条按钮都有相应的命令在工具菜单下。然而,实际上你可以把命令放在别处而不必再工具菜单下。不幸的是,你不能把菜单项添加到任意你想放的地方。只有两处可以:帮助菜单下或工具菜单下。缺省情况下,是放到工具菜单下。只有一种情况会放到帮助菜单下:你在注册表里和MenuText, Icon并列的地方,创建一个字符串Value,名字为MenuCustomize,内容为Help。

==============

When you specify the text for the item (its value is MenuText), you can't specify your choice of underlined character to denote a keyboard shortcut. This is done as a precaution so that you don't introduce a conflict.

The Context Menus

When it comes to customizing the browser, the context menus are frequently one of the aspects you want to control. One of the typical problems you might have is needing to hide the source code of the page from curious users. Until the release of Internet Explorer 5.0, this was possible only by implementing IDocHostUIHandler in your WebBrowser's container. With Internet Explorer 5.0, a slightly enhanced DHTML object model lets you get the same result with script code. The latest Platform SDK contains a made-to-measure example under the path \samples\internet\ie\ie50\OnContextMenu.

==============

翻译讲解:当context menus可用来定制浏览器后,它就成为人们最频繁想控制的一个方面。你可能遇到的一个典型的问题就是需要隐藏页面的源码,以免好奇的访客查看到。IE5.0发布之前,这只能通过在你的WebBrowser's container中实现IDocHostUIHandler接口而做到。在IE5.0里,增强的DHTML object model让你用script代码就能得到相同的结果。在最新的Platform SDK中,\samples\internet\ie\ie50\OnContextMenu路径下,有个made-to-measure例子。

==============

To hide the standard context menu, just use the following piece of script code: <body oncontextmenu="return false">

However, if you assign a procedure to the oncontextmenu property, you can decide at runtime whether to display a menu and, if you do, which one should appear. You can also build your own menu on the fly, as demonstrated in the Platform SDK example.

==============

翻译讲解:欲隐藏标准的context menu,只要下面的script代码片断即可:&nbsp;<body oncontextmenu="return false">然而,如果你给oncontextmenu属性指定了一个procedure ,那么你可以在运行时刻才决定是否显示一个菜单,并且,如果你愿意,还可以决定显示哪一个。你也可以象Platform SDK中的例子所演示的那样,动态地创建你自己的菜单。

==============

If you don't mind all the standard context menu items, but simply want new and more specific items, describe them in a registry subtree located under: HKEY_CURRENT_USER

\Software

\Microsoft

\Internet Explorer

\MenuExt

Each subkey of this node will be considered a new item for any context menu. Notice that now you must work under HKEY_CURRENT_USER. For example, you could create a key called "Do Something?quot; and set its default value to the following HTML page:

<SCRIPT LANGUAGE="JavaScript">

var parentwin = external.menuArguments;

var doc = parentwin.document;

alert("My parent window is: " + doc.title);

</SCRIPT>

From now on, any context menu of Internet Explorer 5.0 includes a "Do Something?quot; item, which prompts you with the title of the current page. In Figure 8, you can see how the context menu for both images and selected text show off a brand new item.

==============

翻译讲解:如果你并不关心所有标准的context menu的items,而仅仅只是想要新的更特定的items,在下面的注册表子树中描述他们: HKEY_CURRENT_USER

\Software

\Microsoft

\Internet Explorer

\MenuExt

该节点下的每个subkey都会被认为是任意context menu的一个新项(网络蚂蚁就是这样做的)。注意此时必须在HKEY_CURRENT_USER下。举个例子,你可以创建一个名为"Do Something..."的Key,并在下面的HTML页面中设置其缺省值: <SCRIPT LANGUAGE="JavaScript">

var parentwin = external.menuArguments;

var doc = parentwin.document;

alert("My parent window is: " + doc.title);

</SCRIPT>

从现在起,IE5.0的任意context menu都包含一个"Do Something..."项,选中它后,会向你提示当前页面的标题是什么。从 Figure 8中,你可以看到在图片上和在选中文本上显示的context menu的新项。

==============

Figure 8: A New Context Menu Item

As for toolbar buttons, the HTML code associated with the command will be run in a hidden dialog box that is passed the parent window object through the external.menuArguments property.

==============

翻译讲解:和前面定制工具条按钮的例子一样,和命令相连的HTML代码是在一个隐藏的对话框中运行的,该对话框通过external.menuArguments属性接收到父窗口的object。

==============

You can also limit the number of context menus where a given command appears. To do so, add another value and name it Contexts. Note that it must be a DWORD value. Assign it any combination of the hex values listed in Figure 9. For example, a value of 0x12 will cause the new item to appear only on the Image and Text context menu, as shown in Figure 8.

==============

翻译讲解:你也可以限定一个新命令项只能出现在某些context menus上。为此,增加一个DWORD类型的value,名为Contexts,用Figure 9中列出的十六进制值的任意组合给它赋值。比如,象Figure 8所显示的那样,赋值0x12将使新命令项只能在图片和文本的context menu上出现。

==============Related Applications

Internet Explorer 5.0 works in conjunction with a number of other applications: HTML editors, mail and news clients, calendars, contact managers, and conferencing. Usually, it detects and lets you choose only a few of the applications you may have on your machine. Once Internet Explorer 5.0 detects such programs, it lists them through the Internet Options dialog box (see Figure 10).

==============

翻译讲解:和IE5.0一起的还有若干其它程序:HTML编辑器,邮件和新闻客户端,日历,联络管理簿等。通常,它只能检测到你机器上的少量程序并让你选择使用。一旦IE5.0检测到这些程序,就会在Internet选项对话框中罗列出来(见Figure 10)。

==============

Figure 10: Internet Explorer-related Programs

Let's see how to make other applications available. Five out of six categories can be managed through this registry node: HKEY_LOCAL_MACHINE

\Software

\Clients

These categories include: Mail, News, Internet Call (conferencing), Calendar, and Contacts. To define a new mail reader (even a dummy entry), create a new node under the Mail key and duplicate the settings you can see for the other entries. Figure 11 shows the result.

==============

翻译讲解:让我们看看如何使其它程序也可被选用。6种程序中有5种可通过下面的注册表节点进行管理: HKEY_LOCAL_MACHINE

\Software

\Clients

这几种程序包括: Mail, News, Internet Call (conferencing), Calendar, 和Contacts。欲定义一个新的邮件阅读器(即使只是个虚假的条目),在Mail key下创建一个新节点,并从其它已有的条目中拷入设置内容(Foxmail就是这样做的)。Figure 11 显示了结果。

==============

Figure 11: Registry Settings for a New Mail Reader

The remaining category of Internet Explorer 5.0 applications is HTML editors. If an HTML editor is made available, it must first be configured elsewhere in the registry. The key to look for is: HKEY_CLASSES_ROOT

\.htm

\OpenWithList

Under this node, you can create a new key for any new program that processes HTML file names on the command line. Take note of the OpenWithList key—it's a sneak preview of a shell feature that's scheduled to ship with Windows 2000. If you're already running a prerelease version of Windows 2000, chances are you already noticed that some file types have dropdown menus in their context menus under the Open With item, allowing you to select from multiple programs to open the file type. All the items shown in this list are taken from the OpenWithList registry key.

==============

翻译讲解:剩下的1种IE5.0程序是HTML编辑器。如果想要使一个HTML编辑器可用,首先必须在注册表的其它地方进行配置。要找的key是: HKEY_CLASSES_ROOT

\.htm

\OpenWithList

在此节点下,你可以为任意程序创建一个新key,只要该程序可在命令行下处理HTML文件名即可。注意OpenWithList key,它是shell的一个新feature,准备在Windows 2000中正式提供。如果你已在使用一个Windows 2000的预览版,那你早就有机会注意到,对某些类型的文件,在它的context menus中Open With项里,有个下拉菜单用来从多个程序中选择。所有在此下拉菜单中列出的项,都是从这个OpenWithList key中取得的。&nbsp;

==============

Deploying the Customization

So far I've discussed a number of techniques you can employ to make Internet Explorer better suit your needs. As you can see, almost all the changes that are required to customize Internet Explorer end up being registry tweaks that must take place on the local client machine.

To wrap things up, let me address some strategies you can follow in order to deploy any change in a fairly automatic way.

==============

翻译讲解:至此,作者讨论了若干种技术,你可以用它们来使IE更适合你的需要。正如你所见,几乎所有的改变,都需要在客户端本机上的注册表里作修改。

对此,让我们想些办法使得这个deploy过程可以自动进行。

==============

You have three options: remote administration of the registry, running WSH scripts locally, or using a self-installing ActiveX module that users download from a fixed URL. In the first case, the system administrator is free to access and manipulate the registry of the connected machines from a remote workstation and can enter any needed change. In the second case, users are required to run a script-based setup procedure locally. From the developer's point of view, these two approaches look much the same.

==============

翻译讲解:你有3种选择:远程管理注册表,在本机运行WSH scripts,或使用一个可让用户从一个固定URL下载的self-installing ActiveX module。在第一种情况下,系统管理员可以从远程工作站连上来,自由地访问和操作注册表,并可以加入任意需要的改变。在第二种情况下,用户需要在本机运行一个script-based安装过程。从开发者观点看,这两种做法看起来是一样的。

==============

The third option is the one I prefer and which I've often employed, although in a slightly different context. When a user wants to update his browser, he just connects to a fixed URL on the intranet. That page contains an ActiveX control, CAB file, or Java-language applet—the choice is yours—which gets downloaded locally and works in the background.

==============

翻译讲解:第三种选择是作者最喜欢并且经常使用的。当用户想更新他们的浏览器时,他只需连接到intranet中一个固定的URL上。这个页面包含有一个ActiveX control, CAB文件, 或Java applet(用什么,随你便),它将被下载到本机并在后台运行,从而修改了注册表。

==============

Summary

I've shown you the major customization features of Internet Explorer 5.0, focusing on the configuration aspects of the browser as opposed to more development-oriented topics such as behaviors and object model extensions. (For more information on behaviors and object model extensions, please see past issues of MIND and MSDN?News.) For more information about the administrative concepts covered in this column, you can refer to the latest MSDN CDs; look under the Platform SDK area for the Web Services ¦ Workshop node.

==============

翻译讲解:作者向你展示了IE5.0的主要定制features,主要集中在浏览器的configuration方面,而不是更加面向开发者的主题,如behaviors和object model extensions。(关于behaviors和object model extensions的更多信息,请看MIND和MSDN?News的以往各期。)关于本专栏所覆盖的各相关概念的更多信息,可参考最新的MSDN光盘,找Platform SDK下的Web Services ¦ Workshop节点。

==============

From the November 1999 issue of Microsoft Internet Developer.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有