Jump to content

Detect type of a control?


Paulchen
 Share

Recommended Posts

If you have handle of control, you can get it's class. In example below you should get "SysTreeView32".

GUICreate("GUI")
$TreeView = GUICtrlCreateTreeView(5, 5, 100, 100)

$sClassName = _GetClassName(GUICtrlGetHandle($TreeView))

MsgBox (0, "Control class", $sClassName)

Func _GetClassName($hWnd)
    $pClassName = DllStructCreate("char[256]")
    DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", DllStructGetPtr($pClassName), "int", 255)
    Return DllStructGetData($pClassName, 1)
EndFunc
Link to comment
Share on other sites

If the control is in an external window then you could first use ChildWindowFromPoint or RealChildWindowFromPoint to get the handle for the control then use Lazycat's function to find the classname.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

How can I detect the difference between a Group, Checkbox Radiobox?

Edit $Input

Static $Label

Button $Button

Button $Group

Button $Checkbox

Button $Radio

GUICreate("GUI")

;////////////////////////////////////////////////////////////////////////////
$TreeView = GUICtrlCreateTreeView(5, 5, 100, 100)
$Input = GUICtrlCreateInput("", 96, 245, 57, 21)
$Label = GUICtrlCreateLabel("Wait after", 177, 249, 50, 17)
$Button = GUICtrlCreateButton("Get Pos", 311, 344, 57, 33, 0)
$Group = GUICtrlCreateGroup("Run", 16, 176, 289, 57)
$Checkbox = GUICtrlCreateCheckbox("Timeout", 118, 205, 65, 17)
$Radio = GUICtrlCreateRadio("Shell", 23, 213, 57, 17)

;////////////////////////////////////////////////////////////////////////////
ConsoleWrite(_GetClassName(GUICtrlGetHandle($TreeView)) & @TAB & "$TreeView" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Input)) & @TAB & "$Input" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Label)) & @TAB & "$Label" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Button)) & @TAB & "$Button" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Group)) & @TAB & "$Group" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Checkbox)) & @TAB & "$Checkbox" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Radio)) & @TAB & "$Radio" & @CRLF)


;////////////////////////////////////////////////////////////////////////////
Func _GetClassName($hWnd)
    $pClassName = DllStructCreate("char[256]")
    DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", DllStructGetPtr($pClassName), "int", 255)
    Return DllStructGetData($pClassName, 1)
EndFunc   ;==>_GetClassName
Link to comment
Share on other sites

You need to look at the styles. See the help for button styles, and compare with the results in the code below. (Least significant byte)

#include <winapi.au3>
#include <constants.au3>

GUICreate("GUI") ;////////////////////////////////////////////////////////////////////////////
$TreeView = GUICtrlCreateTreeView(5, 5, 100, 100)
$Input = GUICtrlCreateInput("", 96, 245, 57, 21)
$Label = GUICtrlCreateLabel("Wait after", 177, 249, 50, 17)
$Button = GUICtrlCreateButton("Get Pos", 311, 344, 57, 33, 0)
$Group = GUICtrlCreateGroup("Run", 16, 176, 289, 57)
$Checkbox = GUICtrlCreateCheckbox("Timeout", 118, 205, 65, 17)
$Radio = GUICtrlCreateRadio("Shell", 23, 213, 57, 17) ;////////////////////////////////////////////////////////////////////////////
ConsoleWrite(_GetClassName(GUICtrlGetHandle($TreeView)) & @TAB & "$TreeView" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Input)) & @TAB & "$Input" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Label)) & @TAB & "$Label" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Button)) & @TAB & "$Button" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Group)) & @TAB & "$Group" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Checkbox)) & @TAB & "$Checkbox" & @CRLF)
ConsoleWrite(_GetClassName(GUICtrlGetHandle($Radio)) & @TAB & "$Radio" & @CRLF) ;////////////////////////////////////////////////////////////////////////////
ConsoleWrite("====STYLES=====" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($TreeView),$GWL_STYLE)) & @TAB & "$TreeView" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Input),$GWL_STYLE)) & @TAB & "$Input" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Label),$GWL_STYLE)) & @TAB & "$Label" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Button),$GWL_STYLE)) & @TAB & "$Button" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Group),$GWL_STYLE)) & @TAB & "$Group" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Checkbox),$GWL_STYLE)) & @TAB & "$Checkbox" & @CRLF)
ConsoleWrite(Hex(_WinAPI_GetWindowLong( GUICtrlGetHandle($Radio),$GWL_STYLE)) & @TAB & "$Radio" & @CRLF)

Func _GetClassName($hWnd)
    $pClassName = DllStructCreate("char[256]")
    DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", DllStructGetPtr($pClassName), "int", 255)
    Return DllStructGetData($pClassName, 1)
EndFunc ;==>_GetClassName
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...