zoukankan      html  css  js  c++  java
  • 在InternetExplorer.Application中显示本地图片

    忘记了,喜欢一个人的感觉

    在InternetExplorer.Application中显示本地图片

    标签: 

    很久以前的问题了,一直没解决,今天无意中搜到了答案。

    在InternetExplorer.Application对象中显示远程服务器上的图片是没有问题的:

    Dim IE
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "about:blank"
    IE.Document.write "<img src='http://demon.tw/demon.gif' />"
    IE.Visible = True

    然而,在IE默认的设置下,却无法显示本地图片:

    Dim IE
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "about:blank"
    IE.Document.write "<img src='D:/demon.gif' />"
    IE.Visible = True

    有人说要使用相对路径,有人说路径要用反斜杠

    IE.Document.write "<img src='D:demon.gif' />"

    也有人说要加上协议名称

    IE.Document.write "<img src='file:///D:/demon.gif' />"

    还有人说加上协议名称并使用反斜杠

    IE.Document.write "<img src='file:///D:demon.gif' />"

    我都试过了,没用,百思不得其解。

    今天却无意中搜索到一段微软网站上的代码,终于豁然开朗:

    Option Explicit
    Dim objWshShell, objFSO, strVariableName, objExplorer, strScriptFileDirectory
    
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    strVariableName = "WhateverYouWant"
    strScriptFileDirectory = objFSO.GetParentFolderName(wscript.ScriptFullName)
    
    ' Displays the Internet Explorer informational message window.
    DisplayIEwindow
    
    wscript.Sleep 4000
    
    CloseIEwindow
    Wscript.Quit
    
    
    ' ~$~----------------------------------------~$~
    '            FUNCTIONS & SUBROUTINES
    ' ~$~----------------------------------------~$~
    Sub DisplayIEwindow
    ' Executes an Internet Explorer window.
    Dim strIEregistryKey, strCheckAssociationsKey
    strIEregistryKey = "NotExist"
    
    On Error Resume Next
    
    ' The following registry entry will enable local files such as .GIFs to be displayed using IE 7.0, but this setting will not take effect if the web browser is already open (there will be no error messages displayed if this is the case).
    strIEregistryKey = objWshShell.RegRead("HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslankabout")
    
    wscript.echo strIEregistryKey
    
    If strIEregistryKey = "NotExist" Then
        objWshShell.RegWrite "HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslankabout", 2, "REG_DWORD"
     wscript.echo "escreve"
    End If
    
    ' Attempts to temporarily prevent Internet Explorer checking to see if it is the default browser (storing the existing value to be restored after disaplying the script's IE window).
    strCheckAssociationsKey = objWshShell.RegRead("HKCUSoftwareMicrosoftInternet ExplorerMainCheck_Associations")
    objWshShell.RegWrite "HKCUSoftwareMicrosoftInternet ExplorerMainCheck_Associations", "no", "REG_SZ"
    
    Set objExplorer = CreateObject ("InternetExplorer.Application")
    objExplorer.Navigate "about:blank"
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Left = 200
    objExplorer.Top = 100
    objExplorer.Width = 450
    objExplorer.Height = 220
    objExplorer.Visible = 1
    objExplorer.Document.Body.Scroll = "no"
    objExplorer.Document.Body.Style.Cursor = "wait"
    objExplorer.Document.Title = "Window Title Name Goes Here" & String(50, ".")
    
    objExplorer.Document.Body.InnerHTML = "<img src='file:///" & strScriptFileDirectory & "pro.gif' align='left'> " & "<b><font size='4'><font color='#008000'>" & strVariableName & " . . .</font></b><br>This application is currently being installed, and may take up to 5 minutes to complete.<p align='center'><font size='3'><b>Installation Start Time:</b> " & Time & "</p></p><p align='center'><font size='2'>*closing this window will <u>not</u> abort the installation<font color='#808080'><br> (this window will close automatically after the process completes)</font></font>"
    
    ' Attempts to make the open IE window active.
    WScript.Sleep 1000
    objWshShell.AppActivate "Window Title Name Goes Here"
    WScript.Sleep 1001
    
    ' Removes the added registry key setting used with IE 7.0 if it did not already exist.
    If strIEregistryKey = "NotExist" Then
        objWshShell.RegDelete "HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslank"
    End If
    
    ' Restores the original Check_Associations registry setting from the script's stored value.
    objWshShell.RegWrite "HKCUSoftwareMicrosoftInternet ExplorerMainCheck_Associations", strCheckAssociationsKey, "REG_SZ"
    End Sub
    
    ' ~$~----------------------------------------~$~
    Sub CloseIEwindow
    ' Attemps to close the Internet Explorer window if it was opened by this script.
    On Error Resume Next
    objExplorer.Quit
    End Sub

    代码里的注释写得很详细,我就不解释了。什么?看不懂英文?那你点参考链接进去看看原文吧,代码以外的部分都是葡萄牙语,作者不用葡萄牙写注释已经很不错了。

    图片显示的问题解决后,VBS也可以写出漂亮的WEB界面了。

    参考链接:Script InternetExplorer.Application + img scr

    随机文章:

    1. 利用WMI打造完美“三无”后门-终焉
    2. 用C语言实现PHP的base64_encode函数
    3. VBS实现Unicode(UTF-16)转UTF-8
    4. NETGEAR WNDRMAC路由器刷OpenWrt
    5. Windows 7 快速共享Internet无线网络
  • 相关阅读:
    Apache-一个IP多个主机域名
    Apache-配置详解
    Apache-配置、测试和调试
    Linux-Memcache和Redis常用命令
    Linux-Linux下安装redis报错"undefined reference to__sync_add_and_fetch_4"解决办法
    C-从源文件到可执行文件的详细编译链接过程
    JavaScript-jQuery报TypeError $(...) is null错误(jQuery失效)解决办法
    MSSQL-SQL SERVER一些使用中的技巧
    unity 在Game视图中显示Gizmos
    unity Transform.TransformPoint
  • 原文地址:https://www.cnblogs.com/developer-ios/p/6354554.html
Copyright © 2011-2022 走看看