码迷,mamicode.com
首页 > 移动开发 > 详细

在InternetExplorer.Application中显示本地图片

时间:2017-01-28 22:09:18      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:window   函数   head   c语言实现   相对路径   oci   color   tin   file   

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

在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("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about")

wscript.echo strIEregistryKey

If strIEregistryKey = "NotExist" Then
    objWshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about", 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("HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations")
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_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 "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\"
End If

‘ Restores the original Check_Associations registry setting from the script‘s stored value.
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_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无线网络

在InternetExplorer.Application中显示本地图片

标签:window   函数   head   c语言实现   相对路径   oci   color   tin   file   

原文地址:http://www.cnblogs.com/developer-ios/p/6354554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!