首页 文章

使用vbscript保存快照

提问于
浏览
3

我是vbscript的新手 . 我想保存使用vbscript打开的Internet Explorer窗口的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而不是paint . 那么是否有任何功能执行 AppActivate 的相反工作 .

1 回答

  • 2

    这不行 . 按下“打印屏幕”按钮时,Microsoft Word处于焦点 . 您可以根本不使用Microsoft Word来轻松解决此问题 . 这不是必需的 . “打印屏幕”功能是系统热键,与Microsoft Word无关 . 您应该使用Alt PrintScreen组合,该组合将当前聚焦的窗口的屏幕截图捕获到剪贴板 .

    其次,如果Paint不是焦点而不是IE,那是因为你的窗口 Headers 错了 . 你正确地做了那个部分 . 如果AppActivate找不到具有指定 Headers 的窗口,则返回false . 说实话,Paint应该开始关注焦点,但确保首先激活窗口是一种好习惯 .

    另外,这是一个非常古老的系统吗?为什么你出于好奇而使用Word.Basic自动化对象呢?

相关问题