gpt4 book ai didi

AutoIt:在鼠标指针下查找窗口

转载 作者:行者123 更新时间:2023-12-01 08:35:31 25 4
gpt4 key购买 nike

我正在使用 AutoIt3,我需要一种方法让用户选择一个窗口。在我看来,最快的方法是让它们指向一个窗口。那么问题来了,如何查看鼠标指针下的窗口是什么?

最佳答案

我从我为选择屏幕上的区域而放置的一些代码中推断出这一点。这只会弹出鼠标下方的窗口标题(按 Escape 退出循环):

#include <WinAPI.au3>
#include <Misc.au3>

Func _WindowFromPoint($iX,$iY)
Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
DllStructSetData($stPoint,1,$iX)
DllStructSetData($stPoint,2,$iY)
$stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
If @error Then Return SetError(2,@error,0)
If $aRet[0]=0 Then Return SetError(3,0,0)
Return $aRet[0]
EndFunc

Local $hControl, $hWin, $hOldWin, $aMousePos
$hOldWin = ""
While Not _IsPressed("1B")
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
$hWin=_WinAPI_GetAncestor($hControl,2)
If $hWin <> $hOldWin Then
TrayTip("Window Info","Window under mouse = " & WinGetTitle($hWin), 1)
$hOldWin = $hWin
EndIf
Sleep(10)
WEnd

关于AutoIt:在鼠标指针下查找窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com