⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_定制ie 5_0.htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 4 页
字号:
            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 <BR><BR>works fine, while<BR>notepad.exe 
            file.txt<BR><BR>doesn't, even if you surround the whole thing with 
            quotes.<BR>==============<BR>翻译讲解:如果要运行一个可执行文件,你需要增加一个value,其名字为Exec,内容为可执行文件的全路径名(网络蚂蚁就这样做)。作者测试结果表明,不能指定命令行参数,如<BR>notepad.exe 
            <BR>可正常工作,而 notepad.exe 
            file.txt<BR>却不行,即使把全部字符串用双引号括起来也一样。<BR>==============<BR>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&lt;SCRIPT 
            LANGUAGE="JavaScript"&gt;<BR>&nbsp; &nbsp; var parentwin = 
            external.menuArguments;<BR>&nbsp; &nbsp; var doc = 
            parentwin.document;<BR>&nbsp; &nbsp; var sel = 
            doc.selection;<BR>&nbsp; &nbsp; var rng = 
            sel.createRange();<BR>&nbsp; &nbsp; var str = new 
            String(rng.text);<BR>&nbsp; &nbsp; if(str.length == 0)<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; rng.text = "HELLO, MIND!";<BR>&nbsp; &nbsp; 
            else<BR>&nbsp; &nbsp; &nbsp; &nbsp; rng.text =&nbsp; 
            str.toUpperCase();<BR>&lt;/SCRIPT&gt;<BR><BR>adds "HELLO, MIND!" to 
            the current page when you click the 
            button.<BR>==============<BR>翻译讲解:如果要执行一个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)来执行之。例如,当你点击按钮时,下面这些代码:<BR><BR>&lt;SCRIPT 
            LANGUAGE="JavaScript"&gt;<BR>&nbsp; &nbsp; var parentwin = 
            external.menuArguments;<BR>&nbsp; &nbsp; var doc = 
            parentwin.document;<BR>&nbsp; &nbsp; var sel = 
            doc.selection;<BR>&nbsp; &nbsp; var rng = 
            sel.createRange();<BR>&nbsp; &nbsp; var str = new 
            String(rng.text);<BR>&nbsp; &nbsp; if(str.length == 0)<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; rng.text = "HELLO, MIND!";<BR>&nbsp; &nbsp; 
            else<BR>&nbsp; &nbsp; &nbsp; &nbsp; rng.text =&nbsp; 
            str.toUpperCase();<BR>&amp;nbsp;&lt;/SCRIPT&gt;会在当前页面中加一句"HELLO, 
            MIND!" 。<BR>==============<BR>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.<BR>==============<BR>翻译讲解:就这样,使用Script条目和一个script-only 
            HTML文件,能让你使用External object去访问文档的object model。如果你往这个HTML文件中加入任何HTML 
            tags,它们都会被忽略。<BR>==============<BR>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.<BR>==============<BR>翻译讲解:最后一种情况,把IE5.0的工具条按钮连接到一个COM 
            object上,添加的Value名字为ClsidExtension,其内容是那个实现了IOleCommandTarget接口的COM 
            object的CLSID(金山词霸就这样做)。如果是一个deskband,用BandClsid而非ClsidExtension。<BR>==============<BR>Accessing 
            the Document Object Model<BR>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.<BR>==============<BR>翻译讲解:早先曾提到,如果你想要访问document object 
            model (DOM),你必须借助于Script条目和一个script-only 
            HTML文件。Well,那并不完全正确。或者说,如果你只是依赖IE的普通做法,那只能如此。然而,如果你有一颗勇敢的心,并且知道如何创建一个简单的VB-based 
            COM object,那么无论用WSH scripts还是用单独的可执行文件,你都可以访问正被IE浏览的文档的object 
            model。<BR>==============<BR>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.<BR>==============<BR>翻译讲解:有两点关键:哪一个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。<BR>==============<BR>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.<BR>Walk the 
            collection.<BR>For each instance of Internet Explorer, compare the 
            handle of the main window with the foreground window.<BR>There's 
            just one possible match. When you've found that, you've found the 
            instance of Internet Explorer that ran your 
            script.<BR>==============<BR>翻译讲解:当用户点击工具条按钮时,系统的foreground窗口正是IE,用GetForegroundWindow 
            API函数可返回foreground窗口的handle。因此,算法过程是:取得运行中的IE的instances的一个集合。遍历该集合。<BR>对每个运行中的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.<BR>==============<BR>翻译讲解:为了在一个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了。<BR>==============<BR>A script that wants to access the DOM 
            can do something like this: Set obj = 
            CreateObject("IE5Script.Instance")<BR>Set myPageObj = 
            obj.IEDocument<BR><BR>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:<BR>Set obj = 
            CreateObject("IE5Script.Instance")<BR>Set myPageObj = 
            obj.IEDocument<BR><BR>For Each lnk In myPageObj.links<BR>&nbsp; 
            &nbsp; txt = txt &amp; lnk.href &amp; vbCrLf<BR>Next<BR>MsgBox 
            txt<BR><BR>Figure 7 shows the final 
            result.<BR>==============<BR>翻译讲解:想要访问DOM,script可以写成这样: Set obj = 
            CreateObject("IE5Script.Instance")<BR>Set myPageObj = 
            obj.IEDocument<BR>从现在开始, myPageObj就可以用来访问DHTML object 
            model中各种各样的items 了。例如,你可以把页面中的连接一一列举出来: Set obj = 
            CreateObject("IE5Script.Instance")<BR>Set myPageObj = 
            obj.IEDocument<BR><BR>For Each lnk In myPageObj.links<BR>&nbsp; 
            &nbsp; txt = txt &amp; lnk.href &amp; vbCrLf<BR>Next<BR>MsgBox 
            txtFigure 7显示了最终结果。<BR>==============<BR><BR>Figure 7: Enumerating 
            Links in a Page<BR>Modifying the Menus<BR>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.<BR>==============<BR>翻译讲解:你可以修改IE5.0的菜单而不影响工具条。早先时候提到过,每个工具条按钮都有相应的命令在工具菜单下。然而,实际上你可以把命令放在别处而不必再工具菜单下。不幸的是,你不能把菜单项添加到任意你想放的地方。只有两处可以:帮助菜单下或工具菜单下。缺省情况下,是放到工具菜单下。只有一种情况会放到帮助菜单下:你在注册表里和MenuText, 
            Icon并列的地方,创建一个字符串Value,名字为MenuCustomize,内容为Help。<BR>==============<BR>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.<BR>The Context Menus<BR>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.<BR>==============<BR>翻译讲解:当context 
            menus可用来定制浏览器后,它就成为人们最频繁想控制的一个方面。你可能遇到的一个典型的问题就是需要隐藏页面的源码,以免好奇的访客查看到。IE5.0发布之前,这只能通过在你的WebBrowser's 
            container中实现IDocHostUIHandler接口而做到。在IE5.0里,增强的DHTML object 
            model让你用script代码就能得到相同的结果。在最新的Platform 
            SDK中,\samples\internet\ie\ie50\OnContextMenu路径下,有个made-to-measure例子。<BR>==============<BR>To 
            hide the standard context menu, just use the following piece of 
            script code: &lt;body oncontextmenu="return 
            false"&gt;<BR><BR>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.<BR>==============<BR>翻译讲解:欲隐藏标准的context 
            menu,只要下面的script代码片断即可:&amp;nbsp;&lt;body oncontextmenu="return 
            false"&gt;然而,如果你给oncontextmenu属性指定了一个procedure 
            ,那么你可以在运行时刻才决定是否显示一个菜单,并且,如果你愿意,还可以决定显示哪一个。你也可以象Platform 
            SDK中的例子所演示的那样,动态地创建你自己的菜单。<BR>==============<BR>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<BR>&nbsp; \Software<BR>&nbsp; &nbsp; 
            \Microsoft<BR>&nbsp; &nbsp; &nbsp; \Internet Explorer<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; \MenuExt<BR><BR>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 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -