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无线网络
  • 相关阅读:
    Android无线测试之—UiAutomator UiSelector API介绍之四
    Android无线测试之—UiAutomator UiSelector API介绍之三
    Android无线测试之—UiAutomator UiSelector API介绍之二
    网页抓取- 3
    VC 6.0 LNK2005 错误 处理
    抓取网页(3)之部分工程文件
    网页抓取 (2)
    网页抓取总结(一)
    nyoj-291 互素数个数 欧拉函数
    nyoj-257 郁闷的C小加(一) 前缀表达式变后缀
  • 原文地址:https://www.cnblogs.com/developer-ios/p/6354554.html
Copyright © 2011-2022 走看看