Jump to content

How to get Control handle and wintitle @mouse location?


Recommended Posts

How do I get win title and controlID which is at mouse location?I want something like autoit window info, but simplified version. I need it to be function and it must work so it finds out on which window is mouse (title) and 2nd return value must be control handle.

example:

My mouse Coords are x=500 and y=600, and Notepad window is there then it must return something like.

$value[0] "Untitled - Notepad"

$value[1] "0x00210226"

But there is 1 problem.I have no idea how to do it.

edited

Link to comment
Share on other sites

#Include <WinAPI.au3>
sleep(3000)
$tPoint = MouseGetPos()
MsgBox(1,1,_WinAPI_WindowFromPoint($tPoint))

instead of notepad handle it returns SciTE handle :S

Whats wrong?

EDIT: and even if I know window title, I still don't know Control handle

Edited by E1M1

edited

Link to comment
Share on other sites

Smoke_N gave a good example here: how to get the GUI the mouse is hovering over ?

I modified it to use the WinAPI UDF functions and also display the Control handle/Class...

#include <WinAPI.au3>
#include <WindowsConstants.au3>

AdlibEnable("_Mouse_Win_GetInfoAdlib", 10)

While 1
    ConsoleWrite("Start Sleep" & @CRLF)
    Sleep(0x7FFFFFFF)
WEnd

Func _Mouse_Win_GetInfoAdlib()
    Local $a_info = _Mouse_Win_GetInfo()
    If @error Then Return

    ToolTip("Window Handle = " & $a_info[0] & @CRLF & _
            "Window Title = " & $a_info[1] & @CRLF & _
            "Control Handle = " & $a_info[2] & @CRLF & _
            "Control Class = " & $a_info[3] & @CRLF & _
            "Mouse X Pos = " & $a_info[4] & @CRLF & _
            "Mouse Y Pos = " & $a_info[5])
EndFunc   ;==>_Mouse_Win_GetInfoAdlib

Func _Mouse_Win_GetInfo()
    Local $structCoords, $a_mpos, $hWnd, $hControl, $sClass
    $structCoords = DllStructCreate($tagPOINT) ; Build Structure
    $a_mpos = MouseGetPos() ; Get Mouse Position
    If @error Then Return SetError(1, 0, 0)
    
    DllStructSetData($structCoords, "X", $a_mpos[0]) ; Populate Structure
    DllStructSetData($structCoords, "Y", $a_mpos[1]) ; Populate Structure
    $hControl = _WinAPI_WindowFromPoint($structCoords) ; Identify Window
    If Not $hControl Then Return SetError(2, 0, 0)
    
    $hWnd = _WinAPI_GetAncestor($hControl, $GA_ROOTOWNER); Get Parent Window
    $sClass = _WinAPI_GetClassName($hControl) ; Get Control Class
    If Not $hWnd Then Return SetError(3, 0, 0)
    
    Local $a_ret[6] = [$hWnd, WinGetTitle($hWnd), $hControl, $sClass, $a_mpos[0], $a_mpos[1]]
    Return $a_ret
EndFunc   ;==>_Mouse_Win_GetInfo

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...