使用vbscript保存快照
问题描述:
我是vbscript的新手。我想保存使用vbscript打开的Internet Explorer窗口的vbscript拍摄的快照。使用vbscript保存快照
代码加载页面
Dim IE, stateString
Set IE = WScript.CreateObject("InternetExplorer.Application")
ie.toolbar = 1
ie.statusbar = 1
ie.width = 999
ie.height = 500
ie.left = 20
ie.theatermode = false
ie.theatermode = true
ie.theatermode = false
ie.top = 50
ie.navigate("file:///C:\Users\Vinit_Tiwari\Documents\vbscripts\someform.html")
'stateString = cstr(ie.readystate)
waitforload(ie)
ie.visible = 1
Set wshShell = CreateObject("Wscript.Shell")
wshShell.AppActivate "Some Form"
wshShell.SendKeys "% x"
代码执行快照
Dim oWordBasic
set oWordBasic = CreateObject("Word.Basic")
oWordBasic.sendkeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"
Set oWordBasic = Nothing
Wscript.Sleep 2000
保存快照
dim paint
set paint = wshShell.exec("mspaint")
do while paint.status = 0:loop
wshShell.appactivate("untitled-Paint")'this returns false
Wscript.sleep 500
WshShell.SendKeys "^v"
wscript.sleep 500
wshshell.sendkeys "^s"
wscript.sleep 500
wshshell.sendkeys "d:\test.png"
wscript.sleep 500
wshell.sendkeys "{Enter}"
Set wshshell = Nothing
其实先前打开的IE窗口是有重点和击键发送给ie而不是绘画。那么是否有任何执行AppActivate
的相反工作的功能。
答
这不起作用。按下“打印屏幕”按钮时,Microsoft Word处于焦点状态。通过完全不使用Microsoft Word,您可以轻松消除此问题。这不是必需的。打印屏幕功能是一个系统热键,与Microsoft Word无关。您应该使用Alt + PrintScreen组合,该组合将当前聚焦的窗口截图捕获到剪贴板。
其次,如果Paint不是焦点而不是IE,那是因为你的窗口标题是错误的。你正在做那个部分。如果AppActivate找不到具有指定标题的窗口,则返回false。说实话,Paint应该已经着眼于开始,但确保首先激活窗口是一种很好的做法。
此外,这是一个非常旧的系统?为什么你出于好奇使用Word.Basic自动化对象?
嗨Nilpo,感谢您的回复......但是请您告诉我在AppActivate中传递的正确标题是什么,以便应用程序可以在前台... – codeomnitrix 2012-04-10 11:22:00
这对于每个版本的视窗。您需要打开MS Paint并查看标题栏。 – Nilpo 2012-04-10 14:37:00
其实我使用的是Windows 7,标题栏显示mspaint的'Untitled-Paint',这就是我想要的。 – codeomnitrix 2012-04-11 12:00:41