Spongioblast

Get all button controls of GUI into an array

4 posts in this topic

#1 ·  Posted

Hi guys

I am trying to figure out how to loop through all the gui buttons and check if the button contains any description. (The buttons description is read from a function which gets the description from the ini file). If the button has no description, it should be hidden. Now my issue is, how do I get all the buttons of the created UI into an array, so I can loop through them?

Cheers

Share this post


Link to post
Share on other sites



#2 ·  Posted

Spongioblast,

Just place the buttons into an array when creating them - I show how you might do it in this post.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Spongioblast,

If you want to get existing controls try something like this...

#include <array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>

;--------------------------------------------------------------------------------------
; Create A gui with controls
;--------------------------------------------------------------------------------------

Local $gui010 = GUICreate('Class Dump')
For $1 = 1 To 10
    GUICtrlCreateButton('B' & $1, $1 * 30, 20, 25, 20)
    GUICtrlCreateInput('I' & $1, $1 * 30, 45, 25, 20)
    GUICtrlCreateLabel('S' & $1, $1 * 30, 70, 25, 20, $SS_SUNKEN)
Next

Local $btn010 = GUICtrlCreateButton('Show Array of Controls', 10, 350, 200, 20)

GUISetState()

;--------------------------------------------------------------------------------------
; Enumerate child windows (controls) with CTLID and TEXT
;--------------------------------------------------------------------------------------

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $btn010
            _Show()
    EndSwitch
WEnd

Func _Show()

    Local $aWin = _WinAPI_EnumChildWindows($gui010)
    _ArrayDelete($aWin, 0)
    Local $aFinal[UBound($aWin)][4]
    For $1 = 0 To UBound($aWin) - 1
        $aFinal[$1][0] = $aWin[$1][0]
        $aFinal[$1][1] = $aWin[$1][1]
        $aFinal[$1][2] = _WinAPI_GetWindowLong($aFinal[$1][0], $GWL_ID)
        $aFinal[$1][3] = ControlGetText('', '', $aFinal[$1][2])
    Next

    _ArrayDisplay($aFinal, 'Active Window Control Enumeration', '', 0, Default, 'HWND|CLASS|CTLID|TEXT')

EndFunc   ;==>_Show

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted

Good solutions from @Melba23 and @kylomas.  Melba's is good for real-time and programmatic creation of the controls; Kylomas' is good for enumerating controls.  I have one to offer as well which works best (for me) for "static" controls.  I tend to use this method for most "complex" GUIs I make.

Basically I create an array and ENUM constants at the beginning of the script that house all my GUI controls, then assign the array indexes to the controls when I create them.  

For example (snippet from my SubNet Calc script in signature):

I start by creating an array with 1 element, set to "hwnd|id"
Then I create constants using ENUM for the GUI ID/handle itself, each GUI control and a LAST const
I Resize/ReDim the array increase the size to the hwnd/ID count (LAST const simplifies this)

Global $aGUI[1] = ["hwnd|id"]
Global Enum $hGUI = 1, $idDummyEnter, $idIPHost, $idIPSubnetMask, $idIPStart, $idIPEnd, $idIPNet, $idIPBroadcast, $idSubnetBits, $idHostCount, $iGUILast
ReDim $aGUI[$iGUILast]

Then I assign each control to the appropriate Array Index (using the Constants I created for easy reference.

$aGUI[$hGUI] = GUICreate("IP Subnet Calc", 258, 330)
$aGUI[$idDummyEnter] = GUICtrlCreateDummy()

$aGUI[$idIPHost] = _GUICtrlIpAddress_Create($aGUI[$hGUI], 70, 33, 130, 18)

$aGUI[$idSubnetBits] = GUICtrlCreateInput("0", 212, 33, 24, 18, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))

$aGUI[$idIPSubnetMask] = _GUICtrlIpAddress_Create($aGUI[$hGUI], 70, 65, 130, 18)

$aGUI[$idIPStart] = _GUICtrlIpAddress_Create($aGUI[$hGUI], 90, 133, 130, 18, $WS_DISABLED)

$aGUI[$idIPEnd] = _GUICtrlIpAddress_Create($aGUI[$hGUI], 90, 165, 130, 18, $WS_DISABLED)

;etc...

Hopefully this makes sense.  I like doing this as it makes it very easy for me to access my controls from a variable (human readable).  It may not suit your needs, but I figured I'd share yet another method.  Here are a couple more scripts of mine (in my signature) that use this "convention" in case you want more examples:  AU History Plasma_kIt  VMWare ESX Builder

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