Sign in to follow this  
Followers 0
rakudave

_GUICtrlCreateContainer()

7 posts in this topic

#1 ·  Posted (edited)

this UDF if made for controing multiple GUIControls, with one command.

the times when you had to use for-loops and arrays to disable 5 bottons at the same time are over.

one line of code and *whoosh*, all buttons are disabled...

i made this 'cause I was looking for something like this and could'nt find it...

and there is a post in the support discussing this problem ( http://www.autoitscript.com/forum/index.ph...=29267&st=0 )

(almost) all functions that are available in GUICtrlSet* are also in the UDF: _GUIContainerSet*

such as: _GUIContainerSetData, _GUIContainerSetStyle, _GUIContainerSetState, _GUIContainerSetColor and so forth

;===============================================================================

;

; Function Name: _GUICtrlCreateContainer($ctrl_1, ctrl_2, ... , ctrl_n)

; Description: Creates a container for mass GUIcontrol handling

; Parameter(s): $ctrl_1 = the first id of the container

; $ctrl_2 = the second id

; $ctrl_n = ... the n'th id (up to 255 id's supported)

; Requirement(s): none

; Return Value(s): the id of the container

; Author(s): rakudave

;

;===============================================================================

here's the UDF including an example:

_GUICtrlCreateContainer.au3

Edited by rakudave

Share this post


Link to post
Share on other sites



cool job rakudave. i'm looking into making it support more than 255 controls right now

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@rakudave I like your UDF. This is different way which allow you to set as many controls you want and have all the GUICtrlSet on one UDF.

;example
#include <GUIConstants.au3>

Dim $container1[3]

GUICreate("my gui")
$a1 = GUICtrlCreateButton("asfds",5,5)
$a2 = GUICtrlCreateButton("sdfg",25,25)
$a3 = GUICtrlCreateButton("vcmn",45,45)
$a4 = GUICtrlCreateButton("fgj",65,65)
$a5 = GUICtrlCreateButton("fgj",85,85)
$a6 = GUICtrlCreateButton("uir",105,105)

$container1[0] = $a2
$container1[1] = $a4
$container1[2] = $a6

$container2 = StringSplit($a1 & '|' & $a3 & '|' & $a5, '|')

_GUICtrlSetContainer($container2, 'GUICtrlSetState', $GUI_HIDE)
GUISetState()

sleep(500)
_GUICtrlSetContainer($container1, 'GUICtrlSetState', $GUI_HIDE)
_GUICtrlSetContainer($container2, 'GUICtrlSetState', $GUI_SHOW)

sleep(500)
_GUICtrlSetContainer($container1, 'GUICtrlSetState', $GUI_SHOW)
_GUICtrlSetContainer($container2, 'GUICtrlSetState', $GUI_HIDE)
sleep(500)
; /example

#include-once
;===============================================================================
;
; Function Name:   _GUICtrlContainer(ByRef $aCtrl, $sFunction, $Param1 = '', $Param2 = '', $Param3 = '', $Param4 = '')
; Description:     Set a container for mass GUIcontrol handling
; Parameter(s):    $aCtrl = an array with all control ID
;                  $sFunction = name of set function (guictrlsetstate, guictrlsetcolor, guictrlsetlimit, etc...)
;                  $Param1 to $Param4 = information need it for the called function
; Requirement(s):  none
; Return Value(s): an array of called function success or failure codes
; Failure(s):      return 1 if called function is not found
;                  return 2 when using GUICtrlSetStyle and $Param1 = ''
;
; Author(s):       Danny35d
;
;===============================================================================

Func _GUICtrlSetContainer(ByRef $aCtrl, $sFunction, $Param1 = '', $Param2 = '', $Param3 = '', $Param4 = '')
        Local $ret = ''
        Local $sFunctionNames = 'GUICtrlSetState|GUICtrlSetBkColor|GUICtrlSetColor|GUICtrlSetData|' & _
            'GUICtrlSetCursor|GUICtrlSetFont|GUICtrlSetImage|GUICtrlSetLimit|GUICtrlSetStyle|GUICtrlSetTip'
        
        If $aCtrl[0] <> (UBound($aCtrl) - 1) Then
            ReDim $aCtrl[UBound($aCtrl) + 1]
            For $x = (UBound($aCtrl) - 1) To 1 Step -1
                $aCtrl[$x] = $aCtrl[$x - 1]
            Next
            $aCtrl[0] = UBound($aCtrl) - 1      
        EndIf
        If StringInStr($sFunctionNames, $sFunction) == 0 Then Return(1)
        $sFunction = StringLower($sFunction)
        Dim $ret[$aCtrl[0] + 1]
        $ret[0] = $aCtrl[0]
        For $x = 1 To $aCtrl[0]
            Select          
            Case $sFunction = 'guictrlsetbkcolor'
                If $Param1 == '' Then $Param1 = 0x00ff00  ;Green
                $ret[$x] = GUICtrlSetBkColor($aCtrl[$x], $Param1)
            Case $sFunction = 'guictrlsetcolor'
                If $Param1 == '' Then $Param1 = 0x00ff00  ;Green
                $ret[$x] = GUICtrlSetColor($aCtrl[$x], $Param1)         
            Case $sFunction = 'guictrlsetcursor'
                If $Param1 == '' Then $Param1 = 2
                GUICtrlSetCursor($aCtrl[$x], $Param1)
            Case $sFunction = 'guictrlsetdata'
                If $Param2 == '' Then $Param2 = -1
                $ret[$x] = GUICtrlSetData($aCtrl[$x], $Param1, $Param2)
            Case $sFunction = 'guictrlsetfont'
                If $Param1 == '' Then $Param1 = 9
                If $Param2 == '' Then $Param2 = 400
                If $Param3 == '' Then $Param3 = 0
                If $Param4 == '' Then $Param4 = 'Arail'
                $ret[$x] = GUICtrlSetFont($aCtrl[$x], $Param1, $Param2, $Param3, $Param4)           
            Case $sFunction = 'guictrlsetimage'
                If $Param1 == '' Then $Param1 = 'Shell32.dll'
                If $Param2 == '' Then $Param2 = -1
                If $Param3 == '' Then $Param3 = 1
                $ret[$x] = GUICtrlSetImage($aCtrl[$x], $Param1, $Param2, $Param3)
            Case $sFunction = 'guictrlsetlimit'
                If $Param1 == '' Then $Param1 = $aCtrl[0]
                If $Param2 == '' Then $Param2 = 0
                $ret[$x] = GUICtrlSetLimit($aCtrl[$x], $Param1, $Param2)
            Case $sFunction = 'guictrlsetstate'
                If $Param1 == '' Then $Param1 = $GUI_SHOW+$GUI_ENABLE
                $ret[$x] = GUICtrlSetState($aCtrl[$x], $Param1)
            Case $sFunction = 'guictrlsetstyle'
                If $Param1 == '' Then Return(2)
                If $Param2 == '' Then $Param2 = -1
                $ret[$x] = GUICtrlSetStyle($aCtrl[$x], $Param1, $Param2)
            Case $sFunction = 'guictrlsettip'
                $ret[$x] = GUICtrlSetTip($aCtrl[$x], $Param1)
            EndSelect
        Next
        Return($ret)
EndFunc
Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

nice one, danny

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