我想通过PID在autohotkey中获取窗口句柄,因为窗口的标题总是在变化。如果有人想知道,我想要处理last.fm主窗口。如何通过PID在autohotkey中获取窗口句柄?
0
A
回答
0
您可以使用WinGet
命令和Cmd参数作为PID
。
WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
Cmd的是执行,其中,如果空白默认为ID的操作。
PID:检索窗口的进程ID(PID)。
6
通过Honest Abe给出的答案是不正确。 Suitup想要将PID转换为窗口句柄。不是窗口句柄到PID。
为了得到一个PID的第一窗口类/ ID,你可以做到以下几点:
Process, Exist, "notepad.exe"
NewPID = %ErrorLevel% ; Save the value immediately since ErrorLevel is often changed.
if NewPID
{ ; process exists!
WinGetClass, ClassID, ahk_pid %NewPID% ; ClassID will be read here for the process
WinGetTitle, Title, ahk_pid %NewPID% ; Title will contain the processe's first window's title
IfWinExist ahk_class %ClassID% ; this will find the first window by the ClassID
{
WinGet, WinID, ID ; this will get the ID of the window into WinID variable
WinActivate ; this will bring this window to front (not necessary for example)
ListVars ; this will display your variables
Pause
}
IfWinExist %Title% ; this will find the first window with the window title
{
WinGet, WinID, ID
WinActivate ; this will bring this window to front (not necessary for example)
ListVars
Pause
}
}
还有其他的方法来对PID等将大于IfWinExist我敢肯定,并且可以有具有相同类ID的多个进程。 :) 此外,您可以使用
0
作为可重复使用的功能:
getHwndForPid(pid) {
pidStr := "ahk_pid " . pid
WinGet, hWnd, ID, %pidStr%
return hWnd
}
相关问题
- 1. 通过PID获取进程句柄
- 2. 获取VB.NET中PID进程的所有子窗口的句柄
- 3. 获取窗口句柄
- 4. 如何获取桌面窗口句柄?
- 5. Autoit - 通过PID获取窗口类
- 6. Linux通过pid获取窗口图标
- 7. 获取的窗口句柄在Java中
- 8. 获取C#中窗口的句柄#
- 9. 获取PyGI中的窗口句柄
- 10. 获取窗口的句柄在C#
- 11. 获取主窗口的句柄在WPF
- 12. 通过窗口句柄获取未知进程的名称?
- 13. 通过C++获取外部运行程序的窗口句柄
- 14. 通过窗口句柄获取父进程ID
- 15. 如何在Python中获取主窗口的句柄?
- 16. 使用窗口句柄获取IUKOWN
- 17. Python Selenium获取当前窗口句柄
- 18. 获取C子窗口句柄#
- 19. 从GtkWidget获取X11窗口句柄
- 20. 获取窗口的所有句柄
- 21. 获取窗口在光标下的窗口句柄
- 22. AutoHotKey:获取mdi窗口
- 23. 如何获得VBA中执行过程窗口的句柄?
- 24. 如何从WndProc中获取窗口句柄?
- 25. 如何从chrome扩展中获取窗口句柄(int)?
- 26. 如何获取gwt中弹出窗口的句柄?
- 27. 如何使用子窗口中的句柄获取父窗口的resize事件?
- 28. 如何获得最小化窗口的窗口句柄
- 29. 通过C#中的点击获取一个流程窗口句柄。
- 30. 从Selenium webdriver的当前窗口获取窗口句柄(IntPtr)GUID
我还没有仔细研究,特别是提问/回答,但你肯定@Suitup的答案是不正确的? OP已被接受为正确。 – Magnilex 2015-01-04 18:47:56
它回答了问题的反面。因此 - 这是错误的 – user1167442 2015-12-02 04:23:01
一个进程可以有多达[10,000个窗口](https://blogs.msdn.microsoft.com/oldnewthing/20070718-00/?p=25963)。在_winget_中使用'ID'和'IDLast'和'ahk_PID'。如果结果相同,则只有一个hwnd。 – 2017-02-09 11:55:45