Jump to content

How to disable ALL controls of a GUI at once?


Recommended Posts

Hi!

Is there a function or an UDF to disable (= grey them out) ALL controls of a GUI at once?

Of course, I could disable the whole GUI... But it's not what I'm looking for... :mellow:

Sure, I also could disable control by control... And enable control by control...

That's not very practical... May be there is a function or an UDF to list ALL

controls used in a GUI?

Anyone any ideas?

Greets,

-supersonic.

Link to comment
Share on other sites

Hi supersonic,

I've seen something similar with checkboxes. The handle of all checkboxes are stored in an array. Then you can loop through the array to check/uncheck all checkboxes in one go.

An example can be found here or here.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

supersonic,

Just run a loop from the first ControlID to the last: :mellow:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$iStart = GUICtrlCreateDummy()

GUICtrlCreateButton("Press", 10, 10, 80, 30)
GUICtrlCreateButton("Press", 10, 50, 80, 30)
GUICtrlCreateButton("Press", 10, 90, 80, 30)
GUICtrlCreateButton("Press", 10, 130, 80, 30)
GUICtrlCreateButton("Press", 10, 170, 80, 30)
GUICtrlCreateButton("Press", 10, 210, 80, 30)

$iEnd = GUICtrlCreateDummy()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iStart To $iEnd
            For $i = $iStart To $iEnd
                GUICtrlSetState($i, $GUI_DISABLE)
            Next
    EndSwitch

WEnd

Of course if you have stored the controlIDs of your first and last controls, you can use those rather than the Dummy IDs.

But please read this post where I explain how ControlIDs work and why using them in loops can be problematic. The earlier code in the same topic shows similar loops using ControlIds to the one above. :party:

I hope that helps. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

M23,

what about this idea?

#include <Array.au3>
#include <GUIConstantsEx.au3>

Global $___HWND[1]

$hGUI = GUICreate("Test", 500, 500)

Local $a    = _HWnd(GUICtrlCreateButton("a", 10, 10, 80, 30), $___HWND)
Local $b    = _HWnd(GUICtrlCreateButton("b", 10, 50, 80, 30), $___HWND)
Local $c    = _HWnd(GUICtrlCreateButton("c", 10, 90, 80, 30), $___HWND)
Local $d    = _HWnd(GUICtrlCreateButton("d", 10, 130, 80, 30), $___HWND)
Local $e    = _HWnd(GUICtrlCreateButton("e", 10, 170, 80, 30), $___HWND)
Local $f    = _HWnd(GUICtrlCreateButton("f", 10, 210, 80, 30), $___HWND)
Local $off  = GUICtrlCreateButton("OFF", 10, 250, 80, 30)
Local $on   = GUICtrlCreateButton("ON", 10, 290, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $off
            _GUICtrlOFF($___HWND)
        Case $on
            _GUICtrlON($___HWND)
    EndSwitch
WEnd

Func _GUICtrlOFF(ByRef $aHWnd)
    For $i = 1 To UBound($aHWnd) - 1 Step 1
        ConsoleWrite("OFF - " & $aHWnd[$i] & @CRLF)
        GUICtrlSetState($aHWnd[$i], $GUI_DISABLE)
    Next
EndFunc

Func _GUICtrlON(ByRef $aHWnd)
    For $i = 1 To UBound($aHWnd) - 1 Step 1
        ConsoleWrite("ON - " & $aHWnd[$i] & @CRLF)
        GUICtrlSetState($aHWnd[$i], $GUI_ENABLE)
    Next
EndFunc

Func _HWnd($hWnd, ByRef $aHWnd)
    If IsArray($aHWnd) = 1 Then _ArrayAdd($___HWND, $hWnd)
    Return $hWnd
EndFunc

Greets,

-supersonic.

Link to comment
Share on other sites

  • Moderators

supersonic,

A bit overcomplex to my mind. How often do you have a variable number of controls at GUI creation time? :mellow: Once you have your GUI sorted, you could just declare an array with the correct number of elements and make the whole thing much simpler:

#include <Array.au3>
#include <GUIConstantsEx.au3>

Global $aArray[6]

$hGUI = GUICreate("Test", 500, 500)

$aArray[0] = GUICtrlCreateButton("a", 10, 10, 80, 30)
$aArray[1] = GUICtrlCreateButton("b", 10, 50, 80, 30)
$aArray[2] = GUICtrlCreateButton("c", 10, 90, 80, 30)
$aArray[3] = GUICtrlCreateButton("d", 10, 130, 80, 30)
$aArray[4] = GUICtrlCreateButton("e", 10, 170, 80, 30)
$aArray[5] = GUICtrlCreateButton("f", 10, 210, 80, 30)
Local $off  = GUICtrlCreateButton("OFF", 10, 250, 80, 30)
Local $on   = GUICtrlCreateButton("ON", 10, 290, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $off
            _Action($aArray, "OFF")
        Case $on
            _Action($aArray, "ON")
    EndSwitch
WEnd

Func _Action(ByRef $aHWnd, $sAction)
    $sState = $GUI_ENABLE
    If $sAction = "OFF" Then $sState = $GUI_DISABLE
    For $i = 0 To UBound($aArray) - 1 ; No need for Step 1 = default
        ConsoleWrite($sAction & " - " & $aArray[$i] & @CRLF)
        GUICtrlSetState($aArray[$i], $sState)
    Next
EndFunc

But full marks for lateral thinking! :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Just a slight tweak on Melba23's method, so you can freely move around/add/takeaway controls without keeping track of the array size or the need to number up each time.

All you need is to paste the same line '$hControlIDs &= "|" & ' in front of any control you want in the array and do a stringsplit at the end to get your array.

#include <GUIConstantsEx.au3>

Global $hControlIDs

$hGUI = GUICreate("Test", 500, 500)

$hControlIDs &= "|" & GUICtrlCreateButton("a", 10, 10, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("b", 10, 50, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("c", 10, 90, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("d", 10, 130, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("e", 10, 170, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("f", 10, 210, 80, 30)
Local $off  = GUICtrlCreateButton("OFF", 10, 250, 80, 30)
Local $on   = GUICtrlCreateButton("ON", 10, 290, 80, 30)

$hControlIDs = StringSplit(StringTrimLeft($hControlIDs, 1), "|", 2)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $off
            _Action($hControlIDs, "OFF")
        Case $on
            _Action($hControlIDs, "ON")
    EndSwitch
WEnd

Func _Action(ByRef $hControlIDs, $sAction)
    $sState = $GUI_ENABLE
    If $sAction = "OFF" Then $sState = $GUI_DISABLE
    For $i = 0 To UBound($hControlIDs) - 1 ; No need for Step 1 = default
        ConsoleWrite($sAction & " - " & $hControlIDs[$i] & @CRLF)
        GUICtrlSetState($hControlIDs[$i], $sState)
    Next
EndFunc
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

I usually do as follows:

#Include <GUIConstantsEx.au3>
#Include <GUIMenu.au3>
#Include <WinAPIEx.au3>

$hForm = GUICreate('MyGUI', 310, 360)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
GUICtrlCreateGroup('Group', 10, 10, 140, 95)
GUICtrlCreateCheckbox('Check1', 22, 26, 120, 23)
GUICtrlCreateCheckbox('Check2', 22, 49, 120, 23)
GUICtrlCreateCheckbox('Check3', 22, 72, 120, 23)
GUICtrlCreateGroup('Group', 160, 10, 140, 95)
GUICtrlCreateRadio('Radio1', 172, 26, 120, 23)
GUICtrlCreateRadio('Radio2', 172, 49, 120, 23)
GUICtrlCreateRadio('Radio3', 172, 72, 120, 23)
$Button = GUICtrlCreateButton('Test', 120, 330, 70, 23)
GUICtrlCreateTab(10, 118, 292, 206)
GUICtrlCreateTabItem('Tab1')
GUICtrlCreateTabItem('Tab2')
GUICtrlCreateTabItem('')
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            _GUILock($hForm, 1)
            Sleep(5000)
            _GUILock($hForm, 0)
    EndSwitch
WEnd

Func _GUILock($hWnd, $fLock)

    Local $Data, $State

    If $fLock Then
        GUISetCursor(15, 1, $hWnd)
        $State = $GUI_DISABLE
    Else
        GUISetCursor(2, 1, $hWnd)
        $State = $GUI_ENABLE
    EndIf
    _GUICtrlMenu_EnableMenuItem(_GUICtrlMenu_GetSystemMenu($hWnd), $SC_CLOSE, $fLock, 0)
    $Data = _WinAPI_EnumChildWindows($hWnd)
    If IsArray($Data) Then
        For $i = 1 To $Data[0][0]
            GUICtrlSetState(_WinAPI_GetDlgCtrlID($Data[$i][0]), $State)
        Next
    EndIf
EndFunc   ;==>_GUILock

WinAPIEx.au3

Link to comment
Share on other sites

  • Moderators

Yoriz,

Nice touch. Edward de Bono would be proud of you. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Yoriz,

indeed, nice! :P

But how to identify a control later on in the script by "name"?

All control handles will be numbered from $hControlIDs[0] to $hControlIDs[n]. :mellow:

When using many controls this could make a script hard to read...

Link to comment
Share on other sites

I guess you could split them up into smaller groups and keep the big grp, or keep various important ones in there own variable but still add them to the grp, or use guictrlread to get there text to identify them. ect

#include <GUIConstantsEx.au3>

Global $hControlIDs, $hMoreControlIDs, $hButGrp1, $hButGrp2, $hButGrp3, $hOnButGrp, $hOffButGrp, $hTemp

$hGUI = GUICreate("Test", 500, 500)

$hControlIDs &= "|" & GUICtrlCreateButton("a", 10, 10, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("b", 10, 50, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("c", 10, 90, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("d", 10, 130, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("e", 10, 170, 80, 30)
$hControlIDs &= "|" & GUICtrlCreateButton("f", 10, 210, 80, 30)
$hButGrp1 = StringSplit(StringTrimLeft($hControlIDs, 1), "|", 2)
$hOffButGrp &= "|" & GUICtrlCreateButton("OFF", 10, 250, 80, 30)
$hOnButGrp &= "|" & GUICtrlCreateButton("ON", 10, 290, 80, 30)

$hMoreControlIDs &= "|" & GUICtrlCreateButton("g", 110, 10, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("h", 110, 50, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("i", 110, 90, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("j", 110, 130, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("k", 110, 170, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("l", 110, 210, 80, 30)
$hButGrp2 = StringSplit(StringTrimLeft($hMoreControlIDs, 1), "|", 2)
$hOffButGrp &= "|" & GUICtrlCreateButton("OFF", 110, 250, 80, 30)
$hOnButGrp &= "|" & GUICtrlCreateButton("ON", 110, 290, 80, 30)

$hControlIDs &= $hMoreControlIDs
$hMoreControlIDs = ""

$hButonM = GUICtrlCreateButton("m", 210, 10, 80, 30)
$hMoreControlIDs &= "|" & $hButonM
$hButonN = GUICtrlCreateButton("n", 210, 50, 80, 30)
$hMoreControlIDs &= "|" & $hButonN
$hButonO = GUICtrlCreateButton("o", 210, 90, 80, 30)
$hMoreControlIDs &= "|" & $hButonO
$hMoreControlIDs &= "|" & GUICtrlCreateButton("p", 210, 130, 80, 30) ; you get the idea :P
$hMoreControlIDs &= "|" & GUICtrlCreateButton("q", 210, 170, 80, 30)
$hMoreControlIDs &= "|" & GUICtrlCreateButton("u", 210, 210, 80, 30)
$hButGrp3 = StringSplit(StringTrimLeft($hMoreControlIDs, 1), "|", 2)
$hOffButGrp &= "|" & GUICtrlCreateButton("OFF", 210, 250, 80, 30)
$hOnButGrp &= "|" & GUICtrlCreateButton("ON", 210, 290, 80, 30)

$hOffButGrp = StringSplit(StringTrimLeft($hOffButGrp, 1), "|", 2)
$hOnButGrp = StringSplit(StringTrimLeft($hOnButGrp, 1), "|", 2)

$hControlIDs &= $hMoreControlIDs
$hMoreControlIDs = ""

Local $Alloff = GUICtrlCreateButton("ALL OFF", 60, 330, 80, 30)
Local $Allon = GUICtrlCreateButton("All ON", 160, 330, 80, 30)

$hControlIDs = StringSplit(StringTrimLeft($hControlIDs, 1), "|", 2)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hOffButGrp[0], $hOffButGrp[1], $hOffButGrp[2]
            Switch $msg
                Case $hOffButGrp[0]
                    $hTemp = $hButGrp1
                Case $hOffButGrp[1]
                    $hTemp = $hButGrp2
                Case $hOffButGrp[2]
                    $hTemp = $hButGrp3
            EndSwitch
            _Action($hTemp, "OFF")
        Case $hOnButGrp[0], $hOnButGrp[1], $hOnButGrp[2]
            Switch $msg
                Case $hOnButGrp[0]
                    $hTemp = $hButGrp1
                Case $hOnButGrp[1]
                    $hTemp = $hButGrp2
                Case $hOnButGrp[2]
                    $hTemp = $hButGrp3
            EndSwitch
            _Action($hTemp, "ON")
        Case $Alloff
            _Action($hControlIDs, "OFF")
        Case $Allon
            _Action($hControlIDs, "ON")
        Case $hButGrp1[0] To $hButGrp1[UBound($hButGrp1) - 1]
            MsgBox(0, "", "A button in Grp1 was clicked" & @CR & "The button is " & GUICtrlRead($msg))
        Case $hButGrp2[0] To $hButGrp2[UBound($hButGrp2) - 1]
            MsgBox(0, "", "A button in Grp2 was clicked" & @CR & "Its No " & $msg - $hButGrp2[0] + 1 & " Of the Grp")
        Case $hButonM
            MsgBox(0, "", "Button m Clicked")
        Case $hButonN
            MsgBox(0, "", "Button n Clicked")
        Case $hButonO
            MsgBox(0, "", "Button o Clicked")
    EndSwitch
WEnd

Func _Action(ByRef $hControlIDs, $sAction)
    $sState = $GUI_ENABLE
    If $sAction = "OFF" Then $sState = $GUI_DISABLE
    For $i = 0 To UBound($hControlIDs) - 1 ; No need for Step 1 = default
        ConsoleWrite($sAction & " - " & $hControlIDs[$i] & @CRLF)
        GUICtrlSetState($hControlIDs[$i], $sState)
    Next
EndFunc   ;==>_Action

Yea i got a bit carried away :mellow:

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
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...