ILLBeBack Posted May 28, 2011 Posted May 28, 2011 Is there a function to determine the type of a control in an AutoIt GUI (Button, Label, Group, etc.)? For example, $iType = GuiCtrlGetType(ControlID).
Zedna Posted May 28, 2011 Posted May 28, 2011 _WinAPI_GetClassName($CtrlId) hudsonhock 1 Resources UDF ResourcesEx UDF AutoIt Forum Search
ILLBeBack Posted May 29, 2011 Author Posted May 29, 2011 _WinAPI_GetClassName($CtrlId)Thanks very much Zedna! That gets me closer. Unfortunately, _WinAPI_GetClassName classes many different control types are buttons. For example, it reports that radio buttons, check boxes, and groups are all "buttons", without a way to determine sub-types.Do you have any other ideas?
Moderators SmOke_N Posted May 29, 2011 Moderators Posted May 29, 2011 (edited) Thanks very much Zedna! That gets me closer. Unfortunately, _WinAPI_GetClassName classes many different control types are buttons. For example, it reports that radio buttons, check boxes, and groups are all "buttons", without a way to determine sub-types.Those are in fact buttons ( the ones you listed ).You can use _WinAPI_GetClassName(), if the class is a button, then you can _WinAPI_GetWindowLong() ( with GWL_STYLE param ) and BitAnd() through the different $BS_* styles to determine specific type I suppose. Edited May 29, 2011 by SmOke_N 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.
ILLBeBack Posted May 29, 2011 Author Posted May 29, 2011 You can use _WinAPI_GetClassName(), if the class is a button, then you can _WinAPI_GetWindowLong() ( with GWL_STYLE param ) and BitAnd() through the different $BS_* styles to determine specific type I suppose. Thanks SmOke_N! Well, maybe, but so far all I can identify using $GWL_STYLE are “Groups” and “HScrolls”, and that’s a bit flakey in that it always reports the first control in a GUI as a Group. Below is the test code that illustrates this. It writes the results to the Console Window (I’m using SciTe). expandcollapse popup#include <WinAPI.au3> #include <Constants.au3> #include <WindowsConstants.au3> $sGUITitle1 = "Test Getting GUI Control Types" $hGUI1 = GUICreate($sGUITitle1, 400, 500, -1, -1) $x3 = GUICtrlCreateButton("button1", 10, 10, 60, 20) ; button, it's a Group $x4 = GUICtrlCreateButton("button2", 10, 40, 60, 20) ; button $x5 = GUICtrlCreateButton("button3", 10, 70, 60, 20) ; button $x6 = GUICtrlCreateEdit("Edit1", 10, 100, 60, 20) ; edit, it's a HScroll $x7 = GUICtrlCreateInput("Input1", 10, 130, 60, 20) ; edit $x8 = GUICtrlCreateLabel("Label1", 10, 160, 60, 20) ; static $x9 = GUICtrlCreateRadio("Radio1", 10, 190, 60, 20) ; button $x10 = GUICtrlCreateRadio("Radio2", 10, 220, 60, 20) ; button $x11 = GUICtrlCreateCheckbox("CheckBox1", 10, 250, 60, 20) ; button $x12 = GUICtrlCreateGroup("Group1", 10, 280, 80, 50) ; button, it's a Group $x13 = GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group, it's a Group $x14 = GUICtrlCreateCombo("", 10, 340, 60, 20) ; ComboBox GUICtrlSetData(-1, "ComboItem1|Comboitem2|Comboitem3", "Comboitem3") $x15 = GUICtrlCreateList("List1", 10, 370, 60, 20) ; ListBox GUICtrlSetData(-1, "ListItem1|Listitem2|Listitem3", "Listitem2") GUISetState(@SW_SHOW, $sGUITitle1) ConsoleWrite(@LF & "--------The first control of GUI " & $sGUITitle1 & " is " & $x3) For $i = $x3 To 15 ConsoleWrite(@LF & $i & ". " & _WinAPI_GetClassName(GUICtrlGetHandle($i))) ConsoleWrite(". " & _WinAPI_GetWindowLong(GUICtrlGetHandle($i), $GWL_ExSTYLE)) ConsoleWrite(". " & _WinAPI_GetWindowLong(GUICtrlGetHandle($i), $GWL_STYLE)) ;; The following will identify Groups and HScrolls. ;; It also reports the first control in a GUI is a group, regardless of its real type. $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($i), $GWL_STYLE) If BitAND($iStyle, $WS_GROUP) = $WS_GROUP Then ConsoleWrite(", it's a Group.") If BitAND($iStyle, $WS_HSCROLL) = $WS_HSCROLL Then ConsoleWrite(", it's a HScroll.") Next ConsoleWrite(@LF & @LF) MsgBox(4096, "Testing", "Results are in the console window") Exit
Moderators SmOke_N Posted May 29, 2011 Moderators Posted May 29, 2011 I'm not sure if I'd trust this, or why it even matters for what you're doing specifically. But this is "kind of" what I had in mind.expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIButton.au3> $sGUITitle1 = "Test Getting GUI Control Types" $hGUI1 = GUICreate($sGUITitle1, 400, 500, -1, -1) $x3 = GUICtrlCreateButton("button1", 10, 10, 60, 20) ; button, it's a Group $x4 = GUICtrlCreateButton("button2", 10, 40, 60, 20) ; button $x5 = GUICtrlCreateButton("button3", 10, 70, 60, 20) ; button $x6 = GUICtrlCreateEdit("Edit1", 10, 100, 60, 20) ; edit, it's a HScroll $x7 = GUICtrlCreateInput("Input1", 10, 130, 60, 20) ; edit $x8 = GUICtrlCreateLabel("Label1", 10, 160, 60, 20) ; static $x9 = GUICtrlCreateRadio("Radio1", 10, 190, 60, 20) ; button $x10 = GUICtrlCreateRadio("Radio2", 10, 220, 60, 20) ; button $x11 = GUICtrlCreateCheckbox("CheckBox1", 10, 250, 60, 20) ; button $x12 = GUICtrlCreateGroup("Group1", 10, 280, 80, 50) ; button, it's a Group $x13 = GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group, it's a Group $x14 = GUICtrlCreateCombo("", 10, 340, 60, 20) ; ComboBox GUICtrlSetData(-1, "ComboItem1|Comboitem2|Comboitem3", "Comboitem3") $x15 = GUICtrlCreateList("List1", 10, 370, 60, 20) ; ListBox GUICtrlSetData(-1, "ListItem1|Listitem2|Listitem3", "Listitem2") GUISetState(@SW_SHOW, $sGUITitle1) ConsoleWrite(@LF & "--------The first control of GUI " & $sGUITitle1 & " is " & $x3) For $i = $x3 To 15 ConsoleWrite($i & ") " & __myCtrlGetClass($i) & @CRLF) Next ConsoleWrite(@LF & @LF) MsgBox(4096, "Testing", "Results are in the console window") Exit Func __myCtrlGetClass($h_wnd) If Not IsHWnd($h_wnd) Then $h_wnd = GUICtrlGetHandle($h_wnd) If Not IsHWnd($h_wnd) Then Return SetError(1, 0, 0) EndIf Local $s_class = _WinAPI_GetClassName($h_wnd) If $s_class <> "Button" Then Return $s_class Local $n_long = _WinAPI_GetWindowLong($h_wnd, -16) ; -16 = GWL_STYLE If Not $n_long Then Return SetError(3, 0, 0) If BitAND($n_long, $BS_GROUPBOX) = $BS_GROUPBOX Then Return "Groupbox" If BitAND($n_long, $BS_CHECKBOX) = $BS_CHECKBOX Then Return "Checkbox" If BitAND($n_long, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then Return "Checkbox" If BitAND($n_long, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Then Return "Radio" If BitAND($n_long, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Then Return "Radio" Return "Button" 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.
Zedna Posted May 29, 2011 Posted May 29, 2011 Also consider that ClassName "Static" can be of of these: picture,icon,label not only label Resources UDF ResourcesEx UDF AutoIt Forum Search
guinness Posted May 29, 2011 Posted May 29, 2011 (edited) Came up with this by expanding what SmOke_N & Zedna suggested.Function:expandcollapse popupFunc _GetCtrlClass($hHandle) Local Const $GWL_STYLE = -16 Local $iLong, $sClass If IsHWnd($hHandle) = 0 Then $hHandle = GUICtrlGetHandle($hHandle) If IsHWnd($hHandle) = 0 Then Return SetError(1, 0, "Unknown") EndIf EndIf $sClass = _WinAPI_GetClassName($hHandle) If @error Then Return "Unknown" EndIf $iLong = _WinAPI_GetWindowLong($hHandle, $GWL_STYLE) If @error Then Return SetError(2, 0, 0) EndIf Switch $sClass Case "Button" Select Case BitAND($iLong, $BS_GROUPBOX) = $BS_GROUPBOX Return "Group" Case BitAND($iLong, $BS_CHECKBOX) = $BS_CHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Return "Radio" Case BitAND($iLong, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Return "Radio" EndSelect Case "Edit" Select Case BitAND($iLong, $ES_WANTRETURN) = $ES_WANTRETURN Return "Edit" Case Else Return "Input" EndSelect Case "Static" Select Case BitAND($iLong, $SS_BITMAP) = $SS_BITMAP Return "Pic" Case BitAND($iLong, $SS_ICON) = $SS_ICON Return "Icon" Case BitAND($iLong, $SS_LEFT) = $SS_LEFT If BitAND($iLong, $SS_NOTIFY) = $SS_NOTIFY Then Return "Label" EndIf Return "Graphic" EndSelect Case "ComboBox" Return "Combo" Case "ListBox" Return "List" Case "msctls_progress32" Return "Progress" Case "msctls_trackbar32" Return "Slider" Case "SysDateTimePick32" Return "Date" Case "SysListView32" Return "ListView" Case "SysMonthCal32" Return "MonthCal" Case "SysTabControl32" Return "Tab" Case "SysTreeView32" Return "TreeView" EndSwitch Return $sClass EndFunc ;==>_GetCtrlClassExample use of Function:expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <EditConstants.au3> #include <GUIButton.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $aReturn[24] = [ _ "Avi", "Button", "Checkbox", "Combo", "ContextMenu", _ "Date", "Dummy", "Edit", "Graphic", "Group", _ "Icon", "Input", "Label", "List", "ListView", _ "Menu", "MonthCal", "Pic", "Progress", "Radio", _ "Slider", "Tab", "TreeView", "Updown"] Global $hGUI, $iCount = 0, $iDummyEnd, $iDummyStart, $sData, $sReturn $hGUI = GUICreate("_GetCtrlClass() Example") $iDummyStart = GUICtrlCreateDummy() GUICtrlCreateAvi("", 0, 0, 0) GUICtrlCreateButton("", 0, 0) GUICtrlCreateCheckbox("", 0, 0) GUICtrlCreateCombo("", 0, 0) GUICtrlCreateContextMenu() GUICtrlCreateDate("", 0, 0) GUICtrlCreateDummy() GUICtrlCreateEdit("", 0, 0) GUICtrlCreateGraphic(0, 0) GUICtrlCreateGroup("", 0, 0) GUICtrlCreateIcon("", 0, 0, 0) GUICtrlCreateInput("", 0, 0) GUICtrlCreateLabel("", 0, 0) GUICtrlCreateList("", 0, 0) GUICtrlCreateListView("", 0, 0) GUICtrlCreateMenu("") GUICtrlCreateMonthCal("", 0, 0) GUICtrlCreatePic("", 0, 0) GUICtrlCreateProgress(0, 0) GUICtrlCreateRadio("", 0, 0) GUICtrlCreateSlider("", 0) GUICtrlCreateTab(0, 0) GUICtrlCreateTreeView(0, 0) GUICtrlCreateUpdown(0) $iDummyEnd = GUICtrlCreateDummy() For $A = $iDummyStart To $iDummyEnd $sData = ($iCount + 1) & ") GUICtrlCreate" & _GetCtrlClass($A) & "() >> GUICtrlCreate" & $aReturn[$iCount] & "()" & @CRLF ConsoleWrite($sData) $sReturn &= $sData $iCount += 1 Next ClipPut($sReturn) Exit Func _GetCtrlClass($hHandle) Local Const $GWL_STYLE = -16 Local $iLong, $sClass If IsHWnd($hHandle) = 0 Then $hHandle = GUICtrlGetHandle($hHandle) If IsHWnd($hHandle) = 0 Then Return SetError(1, 0, "Unknown") EndIf EndIf $sClass = _WinAPI_GetClassName($hHandle) If @error Then Return "Unknown" EndIf $iLong = _WinAPI_GetWindowLong($hHandle, $GWL_STYLE) If @error Then Return SetError(2, 0, 0) EndIf Switch $sClass Case "Button" Select Case BitAND($iLong, $BS_GROUPBOX) = $BS_GROUPBOX Return "Group" Case BitAND($iLong, $BS_CHECKBOX) = $BS_CHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Return "Radio" Case BitAND($iLong, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Return "Radio" EndSelect Case "Edit" Select Case BitAND($iLong, $ES_WANTRETURN) = $ES_WANTRETURN Return "Edit" Case Else Return "Input" EndSelect Case "Static" Select Case BitAND($iLong, $SS_BITMAP) = $SS_BITMAP Return "Pic" Case BitAND($iLong, $SS_ICON) = $SS_ICON Return "Icon" Case BitAND($iLong, $SS_LEFT) = $SS_LEFT If BitAND($iLong, $SS_NOTIFY) = $SS_NOTIFY Then Return "Label" EndIf Return "Graphic" EndSelect Case "ComboBox" Return "Combo" Case "ListBox" Return "List" Case "msctls_progress32" Return "Progress" Case "msctls_trackbar32" Return "Slider" Case "SysDateTimePick32" Return "Date" Case "SysListView32" Return "ListView" Case "SysMonthCal32" Return "MonthCal" Case "SysTabControl32" Return "Tab" Case "SysTreeView32" Return "TreeView" EndSwitch Return $sClass EndFunc ;==>_GetCtrlClassWarning: Changing the Default Styles could cause the Function to not Return the correct control name. Edited May 30, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
ILLBeBack Posted May 29, 2011 Author Posted May 29, 2011 (edited) Thanks SmOke_N, guinness and Zedna! The following is what I find using the code from both SmOke_N and guinness: guinness’s code makes a distinction between “Edit” and “Input”, as well as between “Icon”, “Label” & “Pic”. For “Graphic”, SmOke_N returns “Static” and guinness returns “Label”. Neither identify the following: ContextMenu Dummy ListViewItem Menu MenuItem Obj TabItem TreeViewItem The code below uses the functions from both SmOke_N and guinness on all 29 AutoIt GUI Controls, and outputs the following results: SmOke_N 3) SysAnimate32 .......... for AVI guinness 3) SysAnimate32 .......... for AVI SmOke_N 4) Button ................ for Button guinness 4) Button ................ for Button SmOke_N 5) Checkbox .............. for Checkbox guinness 5) Checkbox .............. for Checkbox SmOke_N 6) ComboBox .............. for Combo guinness 6) Combo ................. for Combo SmOke_N 7) 0 ..................... for ContextMenu guinness 7) Unknown ............... for ContextMenu SmOke_N 8) SysDateTimePick32 ..... for Date guinness 8) Date .................. for Date SmOke_N 9) 0 ..................... for Dummy guinness 9) Unknown ............... for Dummy SmOke_N 10) Edit ................. for Edit guinness 10) Edit ................. for Edit SmOke_N 11) Static ............... for Graphic guinness 11) Label ................ for Graphic SmOke_N 12) Groupbox ............. for Group (start and end) guinness 12) Group ................ for Group (start and end) SmOke_N 13) Static ............... for Icon guinness 13) Icon ................. for Icon SmOke_N 14) Edit ................. for Input guinness 14) Input ................ for Input SmOke_N 15) Static ............... for Label guinness 15) Label ................ for Label SmOke_N 16) ListBox .............. for List guinness 16) List ................. for List SmOke_N 17) SysListView32 ........ for ListView guinness 17) ListView ............. for ListView SmOke_N 18) 0 .................... for ListViewItem guinness 18) Unknown .............. for ListViewItem SmOke_N 19) 0 .................... for Menu guinness 19) Unknown .............. for Menu SmOke_N 20) 0 .................... for MenuItem (for Menu) guinness 20) Unknown .............. for MenuItem (for Menu) SmOke_N 21) SysMonthCal32 ........ for MonthCal guinness 21) MonthCal ............. for MonthCal SmOke_N 22) 0 .................... for Obj guinness 22) Unknown .............. for Obj SmOke_N 23) Static ............... for Pic guinness 23) Pic .................. for Pic SmOke_N 24) msctls_progress32 .... for Progress guinness 24) Progress ............. for Progress SmOke_N 25) Radio ................ for Radio guinness 25) Radio ................ for Radio SmOke_N 26) msctls_trackbar32 .... for Slider guinness 26) Slider ............... for Slider SmOke_N 27) SysTabControl32 ...... for Tab guinness 27) Tab .................. for Tab SmOke_N 28) 0 .................... for TabItem guinness 28) Unknown .............. for TabItem SmOke_N 29) SysTreeView32 ........ for TreeView guinness 29) TreeView ............. for TreeView SmOke_N 30) 0 .................... for TreeViewItem guinness 30) Unknown .............. for TreeViewItem SmOke_N 31) msctls_updown32 ...... for Updown guinness 31) msctls_updown32 ...... for Updown SmOke_N 32) 0 .................... for MenuItem (for Context Menu) guinness 32) Unknown .............. for MenuItem (for Context Menu) Note: If for any reason a control fails to create, the controls that follow will be out of sync with the $aTypes array. Check that the JPG exists, or this will happen. expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIButton.au3> #include <TreeViewConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> $sGUITitle1 = "Test Getting GUI Control Types" $hGUI1 = GUICreate($sGUITitle1, 360, 640, @DesktopWidth - 380, 20) ;; There are 29 GUI controls in AutoIt3, the ControlID for the first one is always 3. Global $aTypes[33] $iCol1 = 10 $iRow = 0 ;; Note: The first successful control is always 3. $x3 = GUICtrlCreateAvi(@SystemDir & "\shell32.dll", 165, 50, $iRow, 100, 50) ; SysAnimate32, $aTypes[3] = "AVI" $iRow += 60 $x4 = GUICtrlCreateButton("Button1 (x4)", $iCol1, $iRow, 120, 20) ; Button $aTypes[4] = "Button" $iRow += 30 $x5 = GUICtrlCreateCheckbox("Check1 (x5)", $iCol1, $iRow, 120, 20) ; Checkbox $aTypes[5] = "Checkbox" $iRow += 30 $x6 = GUICtrlCreateCombo("Combo1 (x6)", $iCol1, $iRow, 120, 20) ; Combobox, Combo $aTypes[6] = "Combo" $x7 = GUICtrlCreateContextMenu() ; 0, Unknown $aTypes[7] = "ContextMenu" $iRow += 30 $x8 = GUICtrlCreateDate(@YEAR & "/" & @MON & "/" & @MDAY, $iCol1, $iRow, 120, 60) ; SysDateTimePick32, Date $aTypes[8] = "Date" $iRow += 70 $x9 = GUICtrlCreateDummy() ; 0, Unknown $aTypes[9] = "Dummy" $x10 = GUICtrlCreateEdit("Edit1 (x10)", $iCol1, $iRow, 120, 20) ; Edit $aTypes[10] = "Edit" $iRow += 30 $x11 = GUICtrlCreateGraphic(10, $iRow, 120, 20) ; Static, Label (both incorrect) $aTypes[11] = "Graphic" GUICtrlSetBkColor(-1, 0xff00ff) $iRow += 30 $x12 = GUICtrlCreateGroup("Group1 (x12)", $iCol1, $iRow, 120, 50) ; Groupbox, Group $aTypes[12] = "Group (start and end)" $iRow += 60 $x13 = GUICtrlCreateIcon("shell32.dll", 10, $iCol1, $iRow, 75, 32, 32) ; Static, Icon $aTypes[13] = "Icon" $iRow += 42 $x14 = GUICtrlCreateInput("Input1 (x14)", $iCol1, $iRow, 120, 20) ; Edit, Input $aTypes[14] = "Input" $iRow += 30 $x15 = GUICtrlCreateLabel("Label1 (x15)", $iCol1, $iRow, 120, 20) ; Static, Label $aTypes[15] = "Label" $iRow += 30 $x16 = GUICtrlCreateList("List1a (x16)", $iCol1, $iRow, 120, 20) ; ListBox, List $aTypes[16] = "List" GUICtrlSetData($x16, "List1b") GUICtrlSetData($x16, "List1c") $iRow += 30 $x17 = GUICtrlCreateListView("ListView (x17)|Col 2|Col 3", $iCol1, $iRow, 120, 60) ; SysListView32, ListView $aTypes[17] = "ListView" $x18 = GUICtrlCreateListViewItem("1 (x18)|2|3", $x17) ; 0, Unknown $aTypes[18] = "ListViewItem" $iRow += 70 $x19 = GUICtrlCreateMenu("Menu1 (x19)") ; 0, Unknown $aTypes[19] = "Menu" $x20 = GUICtrlCreateMenuItem("MenuItem1 (x20)", $x19) ; 0, Unknown $aTypes[20] = "MenuItem (for Menu)" $x21 = GUICtrlCreateMonthCal("MonthCal (x21)", $iCol1, $iRow, 120, 60) ; SysMonthCal32, MonthCal $aTypes[21] = "MonthCal" ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; column 2 $iCol2 = 160 $iRow = 10 $oIE = ObjCreate("Shell.Explorer.2") $x22 = GUICtrlCreateObj($oIE, $iCol2, $iRow, 180, 100) ; 0, Unknown $aTypes[22] = "Obj" $iRow += 110 $x23 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\mslogo.jpg", $iCol2, $iRow, 120, 50) ; Static, Pic $aTypes[23] = "Pic" $iRow += 60 $x24 = GUICtrlCreateProgress($iCol2, $iRow, 120, 20) ; msctls_progress32, Progress $aTypes[24] = "Progress" GUICtrlSetData($x24, 25) $iRow += 30 $x25 = GUICtrlCreateRadio("Radio1 (x24)", $iCol2, $iRow, 120, 20) ; Radio $aTypes[25] = "Radio" $iRow += 30 $x26 = GUICtrlCreateSlider($iCol2, $iRow, 120, 20) ; msctls_trackbar32, Slider $aTypes[26] = "Slider" $iRow += 30 $x27 = GUICtrlCreateTab($iCol2, $iRow, 180, 150) ; SysTabControl32, Tab $aTypes[27] = "Tab" $x28 = GUICtrlCreateTabItem("TabItem1 (x27)") ; 0, Unknown $aTypes[28] = "TabItem" $iRow += 160 $x29 = GUICtrlCreateTreeView($iCol2, $iRow, 180, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) ; SysTreeView32, TreeView $aTypes[29] = "TreeView" $x30 = GUICtrlCreateTreeViewItem("TreeViewItem (X29)", $x28) ; 0, Unknown $aTypes[30] = "TreeViewItem" $x31 = GUICtrlCreateUpdown($x14) ; msctls_updown32 $aTypes[31] = "Updown" ;; Add a menu item to Context Menu $x7 $x32 = GUICtrlCreateMenuItem("Context Menu Item 1 (x31)", $x7) ; 0, Unknown $aTypes[32] = "MenuItem (for Context Menu)" GUISetState(@SW_SHOW, $sGUITitle1) For $i = $x3 To $x32 ConsoleWrite(StringLeft("SmOke_N " & $i & ") " & __myCtrlGetClass($i) & " ...................................", 35) & " for " & $aTypes[$i] & @CRLF) ConsoleWrite(StringLeft("guinness " & $i & ") " & _GetCtrlClass($i) & " ...................................", 35) & " for " & $aTypes[$i] & @CRLF) Next ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Exit Func __myCtrlGetClass($h_wnd) ;; Function by SmOke_N, 2011/05/29 If Not IsHWnd($h_wnd) Then $h_wnd = GUICtrlGetHandle($h_wnd) If Not IsHWnd($h_wnd) Then Return SetError(1, 0, 0) EndIf Local $s_class = _WinAPI_GetClassName($h_wnd) If $s_class <> "Button" Then Return $s_class Local $n_long = _WinAPI_GetWindowLong($h_wnd, -16) ; -16 = GWL_STYLE If Not $n_long Then Return SetError(3, 0, 0) If BitAND($n_long, $BS_GROUPBOX) = $BS_GROUPBOX Then Return "Groupbox" If BitAND($n_long, $BS_CHECKBOX) = $BS_CHECKBOX Then Return "Checkbox" If BitAND($n_long, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then Return "Checkbox" If BitAND($n_long, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Then Return "Radio" If BitAND($n_long, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Then Return "Radio" Return "Button" EndFunc ;==>__myCtrlGetClass Func _GetCtrlClass($hHandle) ;; Function by guinness, 2011/05/29 Local Const $GWL_STYLE = -16 Local $iLong, $sClass If IsHWnd($hHandle) = 0 Then $hHandle = GUICtrlGetHandle($hHandle) If IsHWnd($hHandle) = 0 Then Return SetError(1, 0, "Unknown") EndIf EndIf $sClass = _WinAPI_GetClassName($hHandle) If @error Then Return "Unknown" EndIf $iLong = _WinAPI_GetWindowLong($hHandle, $GWL_STYLE) If @error Then Return SetError(2, 0, 0) EndIf Switch $sClass Case "Button" Select Case BitAND($iLong, $BS_GROUPBOX) = $BS_GROUPBOX Return "Group" Case BitAND($iLong, $BS_CHECKBOX) = $BS_CHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Return "Radio" Case BitAND($iLong, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Return "Radio" EndSelect Case "Edit" Select Case BitAND($iLong, $ES_WANTRETURN) = $ES_WANTRETURN Return "Edit" Case Else Return "Input" EndSelect Case "Static" Select Case BitAND($iLong, $SS_BITMAP) = $SS_BITMAP Return "Pic" Case BitAND($iLong, $SS_ICON) = $SS_ICON Return "Icon" Case BitAND($iLong, $SS_LEFT) = $SS_LEFT If BitAND($iLong, $SS_NOTIFY) = $SS_NOTIFY Then Return "Label" EndIf Return "Graphic" EndSelect Case "ComboBox" Return "Combo" Case "ListBox" Return "List" Case "msctls_progress32" Return "Progress" Case "msctls_trackbar32" Return "Slider" Case "SysDateTimePick32" Return "Date" Case "SysListView32" Return "ListView" Case "SysMonthCal32" Return "MonthCal" Case "SysTabControl32" Return "Tab" Case "SysTreeView32" Return "TreeView" EndSwitch Return $sClass EndFunc ;==>_GetCtrlClass Exit Edited May 30, 2011 by ILLBeBack
Moderators SmOke_N Posted May 30, 2011 Moderators Posted May 30, 2011 (edited) Guinness'es approach will not work if someone removes any style value added. Bottom line. There are only specific types of controls. What we call a label is still a static control, what we call a pic/graphic control is still a static control. There's seriously little to no way programatically to tell the actual "autoit referenced" type of control 100%, other than what is provided by class, and how I showed you to look at buttons. Having said that, now you know why I stopped at button, and just returned the actual class type of the others. Edit: P.S. What makes you think those "Items" are controls? I've hinted to this before, but maybe if you actually tell us what your end goal is, we can provide a "real" means to accomplish it. Edited May 30, 2011 by SmOke_N 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.
guinness Posted May 30, 2011 Posted May 30, 2011 When I started to delve into it a little bit more I realised it was a little more complex than first imagined. I should have added the warning about Styles being changed would render the Function useless. For Example the only Default/Forced Styles that separate Graphic And Label is $SS_LEFT! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
ILLBeBack Posted May 30, 2011 Author Posted May 30, 2011 P.S. What makes you think those "Items" are controls?I've hinted to this before, but maybe if you actually tell us what your end goal is, we can provide a "real" means to accomplish it.I believe I’ve only referenced them as “AutoIt” GUI controls. I call them controls because AutoIt calls them GUI controls. I appreciate that Windows generically classes many of them as a common type, but that doesn’t make their intent generically equal.I would like to know the specific type because I’m mapping GUIs for documentation purposes, and since not all controls have names attached to them (like “Play”, “Fast” “Slow”), I would like to give those controls a somewhat meaningful name, like “Radio Button” or “Check Box”, not simply “Button”. In the case of Groups, they surround other controls and instead of shading inside its boundaries, a shaded boundary is to be drawn. And so on, depending on the control type.If everyone agrees this can’t be done, I’ll just have to manually edit the documentation afterwards.Thanks to everyone for their assistance.
junkew Posted May 30, 2011 Posted May 30, 2011 You can do more with this thread remember that it only works under windows XP with UI Automation API 3.0 installed (Windows 7 should work directly) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
ILLBeBack Posted May 30, 2011 Author Posted May 30, 2011 You can do more with this threadremember that it only works under windows XP with UI Automation API 3.0 installed (Windows 7 should work directly)Thanks junkew! I'm afraid that's beyond my skill level.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now