Find window under mouse pointer


/ Published in: AutoIt
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. $aMousePos = MouseGetPos()
  16. $hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
  17. ; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
  18. $hWin=_WinAPI_GetAncestor($hControl,2)
  19. If $hWin <> $hOldWin Then
  20. TrayTip("Window Info","Window under mouse = " & WinGetTitle($hWin), 1)
  21. $hOldWin = $hWin
  22. Sleep(10)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.