Posted By

Walkman on 03/19/13


Tagged


Versions (?)

Find window under mouse pointer


 / Published in: AutoIt
 

URL: http://stackoverflow.com/a/11270659/720077

made by ascend4nt (https://sites.google.com/site/ascend4ntscode/processfunctions)

  1. #include <WinAPI.au3>
  2. #include <Misc.au3>
  3.  
  4. Func _WindowFromPoint($iX,$iY)
  5. Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
  6. DllStructSetData($stPoint,1,$iX)
  7. DllStructSetData($stPoint,2,$iY)
  8. $stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
  9. $aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
  10. If $aRet[0]=0 Then Return SetError(3,0,0)
  11. Return $aRet[0]
  12.  
  13. Local $hControl, $hWin, $hOldWin, $aMousePos
  14. $hOldWin = ""
  15. While Not _IsPressed("1B")
  16. $aMousePos = MouseGetPos()
  17. $hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
  18. ; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
  19. $hWin=_WinAPI_GetAncestor($hControl,2)
  20. If $hWin <> $hOldWin Then
  21. TrayTip("Window Info","Window under mouse = " & WinGetTitle($hWin), 1)
  22. $hOldWin = $hWin
  23. Sleep(10)

Report this snippet  

You need to login to post a comment.