supersonic Posted June 17, 2010 Share Posted June 17, 2010 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... 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 More sharing options...
water Posted June 17, 2010 Share Posted June 17, 2010 (edited) 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 June 17, 2010 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 More sharing options...
Moderators Melba23 Posted June 17, 2010 Moderators Share Posted June 17, 2010 supersonic,Just run a loop from the first ControlID to the last: #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 WEndOf 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. I hope that helps. M23 JoshuaBarnette and Xandy 1 1 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...
supersonic Posted June 17, 2010 Author Share Posted June 17, 2010 Hi water! Good point to start, thank you! I will give it a try... Link to comment Share on other sites More sharing options...
supersonic Posted June 17, 2010 Author Share Posted June 17, 2010 M23, thank you, this helps me a lot! Yes, I read your linked post AND I have understood! I have another idea; I will post it later on... Link to comment Share on other sites More sharing options...
supersonic Posted June 17, 2010 Author Share Posted June 17, 2010 M23, what about this idea? expandcollapse popup#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 More sharing options...
Moderators Melba23 Posted June 17, 2010 Moderators Share Posted June 17, 2010 supersonic, A bit overcomplex to my mind. How often do you have a variable number of controls at GUI creation time? 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: expandcollapse popup#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! 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...
Yoriz Posted June 17, 2010 Share Posted June 17, 2010 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. expandcollapse popup#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 More sharing options...
Yashied Posted June 17, 2010 Share Posted June 17, 2010 I usually do as follows:expandcollapse popup#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 ;==>_GUILockWinAPIEx.au3 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2010 Moderators Share Posted June 17, 2010 Yoriz,Nice touch. Edward de Bono would be proud of you. 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...
supersonic Posted June 17, 2010 Author Share Posted June 17, 2010 Yashied, does '_WinAPI_EnumChildWindows()' always grab all controls of a GUI? Link to comment Share on other sites More sharing options...
supersonic Posted June 17, 2010 Author Share Posted June 17, 2010 Yoriz, indeed, nice! 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]. When using many controls this could make a script hard to read... Link to comment Share on other sites More sharing options...
Yoriz Posted June 17, 2010 Share Posted June 17, 2010 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 expandcollapse popup#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 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 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