【AHK】如何获取前一个窗口的exe信息

 

万年书妖之法 :

F9::
Windo_获取前一个窗口:
    hwnd := WinActive("A")
    Loop
    {
        hwnd := DllCall("GetWindow",uint,hwnd,int,2)
        SetFormat,integer,hex
        hwnd += 0
        SetFormat,integer,d
        if (DllCall("IsWindowVisible",uint,hwnd) = 1)
        break
    }
    WinGetTitle,title,ahk_id %hwnd%
    MsgBox %title%
    return


 

我整理的方案:

这里的神奇数字32772 表示窗口切换

global WindowList:=[]
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd), OnMessage(DllCall("RegisterWindowMessage", "Str", "ShellHook"), "ShellEvent")
return

ShellEvent(wParam, lParam) {
	if (wParam=32772)
	{
		WinGet,thiswin,ProcessPath,ahk_id %lParam%
    if(thiswin!="")
      WindowList.Push(thiswin)
    oldwin:=WindowList[WindowList.MaxIndex()-1]
    thiswin:=WindowList[WindowList.MaxIndex()]
		OutputDebug  % "上一个窗口为" . oldwin . "`n" "当前窗口为" . thiswin
		ToolTip % "上一个窗口为" . oldwin . "`n" "当前窗口为" . thiswin
	}
 }

内容搜集自网络,供各位ahker参考,欢迎学习探讨。

Guess you like

Origin blog.csdn.net/liuyukuan/article/details/121599252