Jump to content

how to get the GUI the mouse is hovering over ?


jennico
 Share

Recommended Posts

maybe it is VERY simple, but how can i retrieve the information, which gui the mouse cursor is currently hovering over ???

sorry if i'm stupid.

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

maybe it is VERY simple, but how can i retrieve the information, which gui the mouse cursor is currently hovering over ???

sorry if i'm stupid.

j.

Try this:

#include <GUIConstants.au3>

Global $Last_Hovered_hWnd = 0

HotKeySet("{Esc}", "Quit")

GUICreate("_Control_GetHovered")
GUISetState()

While 1
    $aMsg = GUIGetMsg(1)
    
    Switch $aMsg[0]
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MOUSEMOVE
            $Hovered_hWnd = _Control_GetHovered()
            
            If $Last_Hovered_hWnd <> $Hovered_hWnd Then
                Printf(StringFormat("Hovered: hWnd (%s), Text (%s)", $Hovered_hWnd, ControlGetText($Hovered_hWnd, "", "")))
                
                $Last_Hovered_hWnd = $Hovered_hWnd
            EndIf
    EndSwitch
WEnd

Func Printf($Str, $Line=@ScriptLineNumber)
    ConsoleWrite(StringFormat( _
                "!===========================================================\n" & _
                "+======================================================\n" & _
                "--> Script Line (%i):\n!\t%s\n" & _
                "+======================================================\n", $Line, $Str))
EndFunc

Func _Control_GetHovered()
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    
    Opt("MouseCoordMode", $iOld_Opt_MCM)
    
    Return HWnd($Ret[0])
EndFunc

Func Quit()
    Exit
EndFunc
Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Or if it's your GUI, then just check the $aMsg[1] when $GUI_EVENT_MOUSEMOVE event is fired :)

Sorry, that's will not work, the event is fired only from the currently active GUI (last active).

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

thx, it nearly does the job. "WindowFromPoint" - got to learn the winapis by heart.

just one thing: it rather returns the control hovering over, not the winhandle. only if you hover over the title bar or its backgroud or border, you get the winhandle and text.

i need just the window, the control doesn't matter, how to do that ?`

j.

look:

$gui=GUICreate("_Control_GetHovered")
GUICtrlCreateLabel("label",10,10,200,30,513)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUISetState()

Dim $Last_Hovered_hWnd

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
    Sleep(50)
    $Hovered_hWnd = _Control_GetHovered()
    
    If $Last_Hovered_hWnd <> $Hovered_hWnd Then
        WinSetTitle($gui,"",StringFormat("Hovered: hWnd (%s), _
Text (%s)", WinGetTitle($Hovered_hWnd), ControlGetText($Hovered_hWnd, "", "")))
        
        $Last_Hovered_hWnd = $Hovered_hWnd
    EndIf
WEnd

Func _Control_GetHovered()
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    
    Opt("MouseCoordMode", $iOld_Opt_MCM)
    
    Return HWnd($Ret[0])
EndFunc

Func Quit()
    Exit
EndFunc
Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

Try this:

#Include <GuiConstants.au3>

$Gui = GUICreate("_Control_GetHovered")
GUICtrlCreateLabel("label",10,10,200,30,513)
GUICtrlSetBkColor(-1,0xFFFFFF)

$Status = GUICtrlCreateLabel("", 20, 300, 350, 40)

GUISetState()

Dim $Last_Hovered_hWnd

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MOUSEMOVE
            $Hovered_hWnd = _Control_GetHovered()
            
            If $Last_Hovered_hWnd <> $Hovered_hWnd Then
                $Last_Hovered_hWnd = $Hovered_hWnd
                
                $hParent = _Control_GetParent($Hovered_hWnd)
                If IsHWnd($hParent) Then $Hovered_hWnd = $hParent
                
                $sTitle = StringFormat("Hovered: hWnd (%s), Text (%s)", $Hovered_hWnd, WinGetTitle($Hovered_hWnd))
                
                GUICtrlSetData($Status, $sTitle)
            EndIf
    EndSwitch
WEnd

Func _Control_GetParent($hCtrl)
    Local $aRet = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hCtrl)
    Return $aRet[0]
EndFunc

Func _Control_GetHovered()
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    
    Opt("MouseCoordMode", $iOld_Opt_MCM)
    
    Return HWnd($Ret[0])
EndFunc

Func Quit()
    Exit
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

very nice, thanks ! :)

but :

- it works only for AutoIt guis (that's okay for my purposes)

- if you leave away the $GUI_EVENT_MOUSEMOVE it also works while it's inactive.

thanks, man, for me it's okay, but for general use it is still not sufficient. maybe it can be worked over again.

more complicated than it seemed..... i wonder why this hasn't been discussed before....

#Include <GuiConstants.au3>

$Gui = GUICreate("_Control_GetHovered")
GUICtrlCreateLabel("label",10,10,200,30,513)
GUICtrlSetBkColor(-1,0xFFFFFF)

$Status = GUICtrlCreateLabel("", 20, 300, 350, 40)

GUISetState()

Dim $Last_Hovered_hWnd

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $Hovered_hWnd = _Control_GetHovered()
            
    If $Last_Hovered_hWnd <> $Hovered_hWnd Then
        $Last_Hovered_hWnd = $Hovered_hWnd
               
        $hParent = _Control_GetParent($Hovered_hWnd)
        If IsHWnd($hParent) Then $Hovered_hWnd = $hParent
                
        $sTitle = StringFormat("Hovered: hWnd (%s), Text (%s)", $Hovered_hWnd, WinGetTitle($Hovered_hWnd))
                
        GUICtrlSetData($Status, $sTitle)
    EndIf
    
WEnd

Func _Control_GetParent($hCtrl)
    Local $aRet = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hCtrl)
    Return $aRet[0]
EndFunc

Func _Control_GetHovered()
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    
    Opt("MouseCoordMode", $iOld_Opt_MCM)
    
    Return HWnd($Ret[0])
EndFunc

Func Quit()
    Exit
EndFunc
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

  • Moderators

AdlibEnable("_Mouse_Win_GetInfoAdlib", 10)

While 1
    Sleep(0xFFFFFFF)
WEnd

Func _Mouse_Win_GetInfoAdlib()
    Local $a_info = _Mouse_Win_GetInfo()
    If @error Then Return
    ToolTip("Handle = " & $a_info[0] & @CRLF & _
        "Title = " & $a_info[1] & @CRLF & _
        "Mouse X Pos = " & $a_info[2] & @CRLF & _
        "Mouse Y Pos = " & $a_info[3])
EndFunc

Func _Mouse_Win_GetInfo()
    Local $a_mpos = MouseGetPos()
    If @error Then Return SetError(1, 0, 0)
    Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1])
    If @error Then Return SetError(2, 0, 0)
    Local $a_ga = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $a_wfp[0], "int", 3) ; $GW_ROOTOWNER = 3
    If @error Then Return SetError(3, 0, 0)
    Local $a_ret[4] = [$a_ga[0], WinGetTitle($a_ga[0]), $a_mpos[0], $a_mpos[1]]
    Return $a_ret
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...