MyEarth Posted February 22, 2015 Share Posted February 22, 2015 (edited) Hello I have searched before opening but i don't have found nothing for an internal autoit GUI, something for external window. There is a function to collect all ID of the control in a GUI? I have think at the ID because this value never change, right? Handle and other things change at every execution: $hGUI = GUICreate("") $A = GUICtrlCreateButton("", -1, -1) $B = GUICtrlCreateLabel("", -1, -1) $C = GUICtrlCreatePic("", -1, -1) $D = GUICtrlCreateProgress("", -1, -1) $E = GUICtrlCreateListView("", -1, -1) $F = GUICtrlCreateTreeView("", -1, -1) ;etc Global $aIDs[1] ;<<<<<<<<<<<<<<<<<<<<< INSERT HERE Thanks Edited February 22, 2015 by MyEarth Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2015 Moderators Share Posted February 22, 2015 MyEarth,Normal practice would be to store the ControlIDs in the array when creating them: Global $aControls[5] $hGUI = GUICreate("") $aControls[0] = GUICtrlCreateButton(...) $aControls[1] = GUICtrlCreateLabel(...) $aControls[2] = GUICtrlCreatePic(...) $aControls[3] = GUICtrlCreateProgress(...) $aControls[4] = GUICtrlCreateListView(...)You can also use Enum to help you in identifying the controls once created: Global Enum $eButton, $eLabel, $ePic, $eProgress, $eListView, $eMax Global $aControls[$eMax] $hGUI = GUICreate("") $aControls[$eButton] = GUICtrlCreateButton(...) $aControls[$eLabel] = GUICtrlCreateLabel(...) $aControls[$ePic] = GUICtrlCreatePic(...) $aControls[$eProgress] = GUICtrlCreateProgress(...) $aControls[$eListView] = GUICtrlCreateListView(...)Then you can use something like guinness' PreExpand to replace the Enum constants with their numerical equivalent before compiling to speed up the execution. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MyEarth Posted February 22, 2015 Author Share Posted February 22, 2015 Your solution absolutely work but i prefer to avoid that because i need to change all the scripts and rewrite it. I'd like something i can apply without modify anything of the existing script. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2015 Moderators Share Posted February 22, 2015 MyEarth,If all you want is to have a collection of the current controls you could just add a dummy control before and behind the control creation code to check the ControlID bounds. You could also check the class of control associated with each ControlID by doing something like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cStart = GUICtrlCreateDummy() GUICtrlCreateButton("Test", 10, 10, 80, 30) GUICtrlCreateLabel("Test", 10, 50, 80, 20) GUICtrlCreatePic("", 10, 100, 100, 100) GUICtrlCreateProgress(10, 250, 200, 20) GUICtrlCreateListView("", 10, 300, 200, 100) $cEnd = GUICtrlCreateDummy() GUISetState() ; Count controls $iCount = $cEnd - $cStart ; Create an array to hold their details Global $aControls[$iCount][2] For $i = 1 To $iCount - 1 ; Save ControlID $aControls[$i][0] = $cStart + $i ; Get control handle $hHandle = GUICtrlGetHandle($cStart + $i) ; Save control class $aControls[$i][1] = _WinAPI_GetClassName($hHandle) Next ; And here is the result _ArrayDisplay($aControls, "", Default, 8) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndObviously the best solution depends on why you need to collect the controls of a GUI you have created. If you explained why you need to do this we could perhaps offer better focused advice. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MyEarth Posted February 22, 2015 Author Share Posted February 22, 2015 Pratically i want to save the position of the control ( with the corrisponding ID of the control ) in a file and edit that file ( if exist ) for change/save the new position of the controls. I'm checking your script P.S. This is an example for external window, if someone need: _WinGetControls() - Controls eines Fensters auslesen Link to comment Share on other sites More sharing options...
MyEarth Posted February 22, 2015 Author Share Posted February 22, 2015 (edited) I have stripped out partially the (Großvater & progandy & UEZ) function for getting the ID only: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> $hGUI = GUICreate("Test", 500, 500) ConsoleWrite(GUICtrlCreateButton("Test", 10, 10, 80, 30)) ConsoleWrite(GUICtrlCreateLabel("Test", 10, 50, 80, 20)) ConsoleWrite(GUICtrlCreatePic("", 10, 100, 100, 100)) ConsoleWrite(GUICtrlCreateProgress(10, 250, 200, 20)) ConsoleWrite(GUICtrlCreateListView("", 10, 300, 200, 100)) ConsoleWrite(GUICtrlCreateTreeView("", 10, 300, 200, 100)) $aTest = _WinGetControlsID($hGUI) _ArrayDisplay($aTest) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WinGetControlsID($hWnd) Local $UClasses = 50 Local $aClasses[$UClasses + 1][2] Local $aReturn[1000], $iNum = 0 Local $sClasses = WinGetClassList($hWnd) Local $aSplit = StringSplit(StringStripWS($sClasses, 2), @LF) For $I = 1 To $aSplit[0] $Class = $aSplit[$I] $ClassExist = False $C = $aClasses[0][0] For $J = 1 To $C If $aClasses[$J][0] = $Class Then $NN = $aClasses[$J][1] + 1 $aClasses[$J][1] = $NN $ClassExist = True ExitLoop EndIf Next If Not $ClassExist Then $NN = 1 $C += 1 If $C > $UClasses Then $UClasses += 50 ReDim $aClasses[$UClasses + 1][2] EndIf $aClasses[0][0] = $C $aClasses[$C][0] = $Class $aClasses[$C][1] = $NN EndIf $Handle = ControlGetHandle($hWnd, "", $Class & $NN) $aResult = DllCall("User32.dll", "Int", "GetDlgCtrlID", "HWND", $Handle) If @error Or $aResult[0] = 0 Then $ID = "" Else $aReturn[$iNum] = $aResult[0] $iNum += 1 EndIf Next ReDim $aReturn[$iNum] Return $aReturn EndFunc ;==>_WinGetControlsID I don't know if have "extra" information i don't care or do something i don't need EDIT: The Melba version but require the two dummy: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> $hGUI = GUICreate("Test", 500, 500) $cStart = GUICtrlCreateDummy() ConsoleWrite(GUICtrlCreateButton("Test", 10, 10, 80, 30)) ConsoleWrite(GUICtrlCreateLabel("Test", 10, 50, 80, 20)) ConsoleWrite(GUICtrlCreatePic("", 10, 100, 100, 100)) ConsoleWrite(GUICtrlCreateProgress(10, 250, 200, 20)) ConsoleWrite(GUICtrlCreateListView("", 10, 300, 200, 100)) ConsoleWrite(GUICtrlCreateTreeView("", 10, 300, 200, 100)) $cEnd = GUICtrlCreateDummy() $aTest = _WinGetControlsID($cStart, $cEnd) _ArrayDisplay($aTest) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WinGetControlsID($cStart, $cEnd) ; Count controls Local $iCount = $cEnd - $cStart ; Create an array to hold their details Local $aControls[$iCount] = [$iCount - 1] For $i = 1 To $iCount - 1 ; Save ControlID $aControls[$i] = $cStart + $i Next Return $aControls EndFunc ;==>_WinGetControlsID Edited February 22, 2015 by MyEarth Link to comment Share on other sites More sharing options...
mikell Posted February 22, 2015 Share Posted February 22, 2015 #include <Array.au3> #include <WinAPISys.au3> Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 310, 360) $a = GUICtrlCreateButton("Test", 10, 10, 80, 30) $b = GUICtrlCreateLabel("Test", 10, 50, 80, 20) $c = GUICtrlCreatePic("", 10, 100, 100, 100) $d = GUICtrlCreateProgress(10, 250, 200, 20) $e = GUICtrlCreateListView("", 10, 300, 200, 100) GUISetState(@SW_SHOW) ; Msgbox(0,"", $a &@crlf& $b &@crlf& $c &@crlf& $d &@crlf& $e ) $aRes = _GetControls($hForm) _ArrayDisplay($aRes) Func _GetControls($hWnd) Local $aData = _WinAPI_EnumChildWindows($hWnd) _ArrayColInsert($aData, 2) For $i = 1 to $aData[0][0] $aData[$i][2] = _WinAPI_GetDlgCtrlID($aData[$i][0]) Next Return $aData EndFunc GUIDelete() ? Link to comment Share on other sites More sharing options...
MyEarth Posted February 22, 2015 Author Share Posted February 22, 2015 Mikell, Intresting. I'll think i'll edit the WinAPI_EnumChildWindows for return directly the ID instead to add another column, another loop etc. Link to comment Share on other sites More sharing options...
mikell Posted February 22, 2015 Share Posted February 22, 2015 It was just an example Instead of editing the udf (not a very good idea) you'd better do it like this, and get 2 cols with handles and IDs only - handles could be useful Func _GetControls($hWnd) Local $aData = _WinAPI_EnumChildWindows($hWnd) For $i = 1 to $aData[0][0] $aData[$i][1] = _WinAPI_GetDlgCtrlID($aData[$i][0]) Next Return $aData EndFunc Link to comment Share on other sites More sharing options...
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