Sign in to follow this  
Followers 0
Floppy

Get Control Type

15 posts in this topic

#1 ·  Posted (edited)

Hello,

is there a way to know the control type hovered by mouse?

For example, if the mouse is over a button...then, the script return $button...if is over an edit...return $edit

Thanks and bye!

# Sorry for english #

Edited by FSoft

Share this post


Link to post
Share on other sites



I'm tried with this script:

#include <ControlPos.au3>
#include <GuiConstants.au3>

$w=GUICreate("Test")
$b1=GUICtrlCreateButton("Test",50,10,100,100)
$b2=GUICtrlCreateButton("Test",50,150,100,100)
GUISetState()

while 1
    $m=GUIGetMsg()
    Select
    Case $m=$gui_event_close 
        ExitLoop
    Case $m=$b1
        MsgBox(0,"",_CtrlGetByPos($w))
        EndSelect
    WEnd

But, when I click on the button 1, the message box text is "0".

Why?

Share this post


Link to post
Share on other sites

I'm tried with this script:

#include <ControlPos.au3>
#include <GuiConstants.au3>

$w=GUICreate("Test")
$b1=GUICtrlCreateButton("Test",50,10,100,100)
$b2=GUICtrlCreateButton("Test",50,150,100,100)
GUISetState()

while 1
    $m=GUIGetMsg()
    Select
    Case $m=$gui_event_close 
        ExitLoop
    Case $m=$b1
        MsgBox(0,"",_CtrlGetByPos($w))
        EndSelect
    WEnd

But, when I click on the button 1, the message box text is "0".

Why?

You have to read how to use functions in order to get the right results :)

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I think, you wnat something like this? ( It is the same like the first link from SmOke_N, but with WinAPI.au3)

#include <WinAPI.au3>

While 1
    Sleep(40)
    $tPoint = _WinAPI_GetMousePos()
        $hWnd = _WinAPI_WindowFromPoint($tPoint)
        $ClassName = _WinAPI_GetClassName($hWnd)
    ToolTip($ClassName,Default,Default,"ClassName: ")
WEnd
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Try this example, it shows the CLASS Name of hovered windows/controls:

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

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

Global $hLast_Hovered_Wnd = 0

GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST)

GUICtrlCreateButton("Button", 20, 20, 60, 20)
GUICtrlCreateCheckbox("Checkbox", 100, 20)
GUICtrlCreateEdit("", 20, 50, 150, 60)

GUISetState()

AdlibEnable("_CheckHoveredClassName_Proc", 300)

While 1
    $aMsg = GUIGetMsg()
    
    Switch $aMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CheckHoveredClassName_Proc()
    $hHovered_Wnd = _WinGetHoveredHandle()
    $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2) ;To get properly CLASSNN with non active windows
    
    ;If $hLast_Hovered_Wnd <> $hHovered_Wnd Then
        ToolTip(StringFormat("hWnd: %s\r\nCLASSNN: %s", _
            $hHovered_Wnd, _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd)), _
            Default, Default, "Hovered CLASSNN Info", 1, 5)
        
        $hLast_Hovered_Wnd = $hHovered_Wnd
    ;EndIf
EndFunc

Func _WinGetHoveredHandle()
    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 _WinGetClassNameNN($hCtrlWnd, $hWinWnd="")
    $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd)
    $sClassName = _WinGetClassName($hCtrlWnd)
    $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF)
    
    For $i In $aClassList
        If $i = $sClassName Then
            For $j = 1 To UBound($aClassList)
                If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j
            Next
        EndIf
    Next
    
    Return $sClassName
EndFunc

Func _WinGetClassName($hWnd)
    Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256)
    
    If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2]
    Return @error
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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You have to read how to use functions in order to get the right results :)

Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinates

But I don't want the Control ID...

I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...

I don't want to know the class, the handle and others...

Edited by FSoft

Share this post


Link to post
Share on other sites

Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinates

But I don't want the Control ID...

I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...

I don't want to know the class, the handle and others...

is there a way to know the control type hovered by mouse?

Was I supposed to interpret this correctly and magically know exactly what you were talking about?

It returns the ClassNameNN as well if you choose, which will in fact give the type of control that it is. What you do with that information is locked away in your own mind somewhere I'm sure.


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.

Share this post


Link to post
Share on other sites

Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinates

But I don't want the Control ID...

I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...

I don't want to know the class, the handle and others...

MrCreatoR solve your problem, I change very little his script:

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

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

Global $hLast_Hovered_Wnd = 0

GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST)

GUICtrlCreateButton("Button", 20, 20, 60, 20)
GUICtrlCreateCheckbox("Checkbox", 100, 20)
GUICtrlCreateEdit("", 20, 50, 150, 60)

GUISetState()

AdlibEnable("_CheckHoveredClassName_Proc", 300)

While 1
    $aMsg = GUIGetMsg()
   
    Switch $aMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CheckHoveredClassName_Proc()
    $hHovered_Wnd = _WinGetHoveredHandle()
    $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2);To get properly CLASSNN with non active windows
    $WIN_CLASS = _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd)
    ToolTip(StringRegExpReplace($WIN_CLASS,"\d",""),Default,Default,"Control Type")
    $hLast_Hovered_Wnd = $hHovered_Wnd
EndFunc

Func _WinGetHoveredHandle()
    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 _WinGetClassNameNN($hCtrlWnd, $hWinWnd="")
    $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd)
    $sClassName = _WinGetClassName($hCtrlWnd)
    $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF)
   
    For $i In $aClassList
        If $i = $sClassName Then
            For $j = 1 To UBound($aClassList)
                If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j
            Next
        EndIf
    Next
   
    Return $sClassName
EndFunc

Func _WinGetClassName($hWnd)
    Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256)
   
    If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2]
    Return @error
EndFunc

Func Quit()
    Exit
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...

I don't want to know the class, the handle and others...

That's exactly what i wrote in Post #5 Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

MrCreatoR solve your problem, I change very little his script:

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

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

Global $hLast_Hovered_Wnd = 0

GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST)

GUICtrlCreateButton("Button", 20, 20, 60, 20)
GUICtrlCreateCheckbox("Checkbox", 100, 20)
GUICtrlCreateEdit("", 20, 50, 150, 60)

GUISetState()

AdlibEnable("_CheckHoveredClassName_Proc", 300)

While 1
    $aMsg = GUIGetMsg()
   
    Switch $aMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CheckHoveredClassName_Proc()
    $hHovered_Wnd = _WinGetHoveredHandle()
    $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2);To get properly CLASSNN with non active windows
    $WIN_CLASS = _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd)
    ToolTip(StringRegExpReplace($WIN_CLASS,"\d",""),Default,Default,"Control Type")
    $hLast_Hovered_Wnd = $hHovered_Wnd
EndFunc

Func _WinGetHoveredHandle()
    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 _WinGetClassNameNN($hCtrlWnd, $hWinWnd="")
    $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd)
    $sClassName = _WinGetClassName($hCtrlWnd)
    $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF)
   
    For $i In $aClassList
        If $i = $sClassName Then
            For $j = 1 To UBound($aClassList)
                If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j
            Next
        EndIf
    Next
   
    Return $sClassName
EndFunc

Func _WinGetClassName($hWnd)
    Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256)
   
    If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2]
    Return @error
EndFunc

Func Quit()
    Exit
EndFunc

The script is good...but not correct because the checkbox tooltip is "Button" and not "Checkbox"!

Share this post


Link to post
Share on other sites

@FSoft (and others if need be).

You seem to need to do some homework on MSDN if you are confused on why the results returned are "Static" or "Button" for different types of controls.

If you need it to be very specific, then "You" yourself will need to write something that has a base of what the control id is: eg... $a_mycontrol[3][2] = [[1, "Button"], etc...]

This way you can use the control ID to tell what the control type is in your script. But for all sakes and aguments ... A label is Static, a image is Static, a Checkbox is a Button, ... Hell, even an Input is an Edit... so get to scripting :) ...

@FSoft, when responding to those helping you, don't be a stupid and put exclamations and italics around things (without an explanation) unless you want them to be considered insulting. You'll lose any future help you could hope to gain here that way.


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.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@FSoft, when responding to those helping you, don't be a stupid and put exclamations and italics around things (without an explanation) unless you want them to be considered insulting. You'll lose any future help you could hope to gain here that way.

Sorry, but you live in another country that it isn't Italy

In Italy there's a proverb: Paese che vai, usanza che trovi! that (more or less) in english means: In each country you go, there are different customs!

Regarding the exclamations and italics (and others), we use it in Italy to highlight something and not to insult someone...

bye

Edited by FSoft

Share this post


Link to post
Share on other sites

Regarding the exclamations and italics (and others), we use it in Italy to highlight something and not to insult someone...

Welcome to these English forums!

Share this post


Link to post
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
Sign in to follow this  
Followers 0