如何使用窗口脚本宿主查找活动(前景)窗口的窗口标题 [英] How to find the window Title of Active(foreground) window using Window Script Host

查看:26
本文介绍了如何使用窗口脚本宿主查找活动(前景)窗口的窗口标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Window Script Host(WSH) 查找当前处于活动状态(具有焦点)的窗口的标题,因为我希望我的 WSH 脚本仅在所需窗口处于活动状态时发送键.

I want to find the title of the window which is currently active(having focus) using Window Script Host(WSH) because I want my WSH script to Sendkeys only If the desired window is active.

注意*我没有条件使用替代方法,即在调用 sendkeys 之前激活所需的窗口.

Note* I am not in a condition to use the alternative i.e activating the desired window before invoking sendkeys.

感谢任何帮助.

推荐答案

简短回答:你不能.至少要为相关的 Windows API 调用编写 COM 包装器.

Short answer: You can't. At least not without writing a COM wrapper for the relevant Windows API calls.

你不能只使用 AppActivate 并检查结果吗?

Can't you just use AppActivate and check the result?

Set oShell = CreateObject("WScript.Shell")
If oShell.AppActivate "Untitled - Notepad" Then
  oShell.SendKeys "Hello, world!"
End If


长答案:要获取活动窗口标题,您需要调用 Windows API GetWindowText 函数并传递 GetForegroundWindow() 句柄.VBScript 和 Windows Script Host 不支持 Windows API 调用,因此您需要为这些函数编写一个 COM 包装器,然后可以在脚本中使用.以下是示例:


Long answer: To get the active window title, you need to call the Windows API GetWindowText function and pass the GetForegroundWindow() handle. VBScript and Windows Script Host don't support Windows API calls, so you'll need to write a COM wrapper around these functions, that you can then use in your script. Here're examples:

在 C 中获取当前活动的窗口标题

我该怎么做使用c#获取当前活动窗口的标题?

这篇关于如何使用窗口脚本宿主查找活动(前景)窗口的窗口标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆