windows 如何找到当前关注的程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8402237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find the program with the current focus?
提问by Fabian
How can I know which process has the current focus?
我如何知道当前关注的是哪个进程?
Edit: Windows OS, anywhere from XP to 7
编辑:Windows 操作系统,从 XP 到 7
回答by Rob Kennedy
Call GetForegroundWindow
to get the handle of the focused window, and then call GetWindowThreadProcessId
to get the ID of the process that created that window. What you do with that ID is up to you.
调用GetForegroundWindow
获取焦点窗口的句柄,然后调用GetWindowThreadProcessId
获取创建该窗口的进程的 ID。您如何使用该 ID 由您决定。
回答by Luchian Grigore
You can use EnumProcesses
to get the list of running processes.
您可以使用EnumProcesses
来获取正在运行的进程列表。
After you retrieve the handles, check out GetProcessInformation
, there might be something there that can help you.
取回手柄后,请查看GetProcessInformation
,那里可能有一些可以帮助您的东西。
回答by Alek86
the first steps are winapi function EnumProcesses (and maybe OpenProcess)
第一步是 winapi 函数 EnumProcesses(也可能是 OpenProcess)