Xandl Posted June 26, 2008 Posted June 26, 2008 Hello, its now the second time I see people asking to enable/disable controls within a group control. So I liked to try it. The function can use any state used with GUICtrlSetState() on controls within the pixel range of another control. The script searches for the controls, so you dont need to specify which control IDs to work on. Simply copy/paste/try the example below. expandcollapse popup#include <GUIConstants.au3> GUICreate('test',430,160) Global $g1=GUICtrlCreateGroup('Test group - check/uncheck',10,10,200,100) Global $c11=GUICtrlCreateCheckbox('11111',20,30) Global $c12=GUICtrlCreateCheckbox('22222',20,50) Global $c13=GUICtrlCreateCheckbox('33333',20,70) Global $r1=GUICtrlCreateRadio('test',100,50,60) Global $b1Off=GUICtrlCreateButton('off',40,120,60) Global $b1On=GUICtrlCreateButton('on',120,120,60) Global $g2=GUICtrlCreateGroup('Test group - enable/disable',220,10,200,100) Global $c21=GUICtrlCreateCheckbox('11111',230,30) Global $c22=GUICtrlCreateCheckbox('22222',230,50) Global $c23=GUICtrlCreateCheckbox('33333',230,70) Global $b2=GUICtrlCreateButton('test',310,50,60) Global $b2Off=GUICtrlCreateButton('off',250,120,60) Global $b2On=GUICtrlCreateButton('on',330,120,60) GUISetState() While 1 Sleep(20) Switch GUIGetMsg() Case $b1Off _GUICtrlGroup_SetState($g1,$GUI_UNCHECKED,'test') Case $b1On _GUICtrlGroup_SetState($g1,$GUI_CHECKED) Case $b2Off _GUICtrlGroup_SetState($g2,$GUI_DISABLE,'test') Case $b2On _GUICtrlGroup_SetState($g2) Case -3 Exit EndSwitch WEnd ; #FUNCTION# ========================================================================================= ; Name...........: _GUICtrlGroup_SetState ; Description ...: Set state of controls within another control, typically a GUICtrlGroup. ; Syntax.........: _GUICtrlGroup_SetState($hGroup,$iState = $GUI_ENABLE,$sWinTitle = '',$iMaxCtrlId = 500) ; Parameters ....: $hGroup - The control identifier (controlID) as returned by a GUICtrlCreate... function. ; $iState - Can be any value working with GUICtrlSetState, i.e. $GUI_ENABLE and $GUI_DISABLE. ; Default is $GUI_ENABLE. ; $sWinTitle - The title of the GUI window. ; Default is '', referring to the current active window. ; $iMaxCtrlId - Maximum controlID number to search for, starting from 1. ; Default is 500. ; Return values .: Success - Returns 1 ; Failure - Returns 0, and sets @error: ; |1 - Invalid $hGroup identifier, its not a control of the window ; ================================================================================================== Func _GUICtrlGroup_SetState($hGroup,$iState = $GUI_ENABLE,$sWinTitle = '',$iMaxCtrlId = 500) Local $aPosGrp = ControlGetPos($sWinTitle,'',$hGroup) If @error Then Return SetError(1,0,0) Local $aPosCtrl For $i = 1 To $iMaxCtrlId $aPosCtrl = ControlGetPos($sWinTitle,'',$i) If Not @error Then If ($aPosCtrl[0] > $aPosGrp[0]) And ($aPosCtrl[1] > $aPosGrp[1]) And _ ($aPosCtrl[0]+$aPosCtrl[2] < $aPosGrp[0]+$aPosGrp[2]) And ($aPosCtrl[1]+$aPosCtrl[3] < $aPosGrp[1]+$aPosGrp[3]) Then GUICtrlSetState($i,$iState) EndIf EndIf Next Return 1 EndFunc You will only need _GUICtrlGroup_SetState() in your script. I would be interested if it works for you as expected. ciao Xandl
WeMartiansAreFriendly Posted June 26, 2008 Posted June 26, 2008 Excellent idea. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
rasim Posted June 26, 2008 Posted June 26, 2008 XandlHi! There is easy way:expandcollapse popup#include <GUIConstants.au3> GUICreate('test',430,160) Global $g1=GUICtrlCreateGroup('Test group - check/uncheck',10,10,200,100) $DummyStart1 = GUICtrlCreateDummy() Global $c11=GUICtrlCreateCheckbox('11111',20,30) Global $c12=GUICtrlCreateCheckbox('22222',20,50) Global $c13=GUICtrlCreateCheckbox('33333',20,70) Global $r1=GUICtrlCreateRadio('test',100,50,60) $DummyEnd1 = GUICtrlCreateDummy() Global $b1Off=GUICtrlCreateButton('off',40,120,60) Global $b1On=GUICtrlCreateButton('on',120,120,60) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group Global $g2=GUICtrlCreateGroup('Test group - enable/disable',220,10,200,100) $DummyStart2 = GUICtrlCreateDummy() Global $c21=GUICtrlCreateCheckbox('11111',230,30) Global $c22=GUICtrlCreateCheckbox('22222',230,50) Global $c23=GUICtrlCreateCheckbox('33333',230,70) Global $b2=GUICtrlCreateButton('test',310,50,60) $DummyEnd2 = GUICtrlCreateDummy() Global $b2Off=GUICtrlCreateButton('off',250,120,60) Global $b2On=GUICtrlCreateButton('on',330,120,60) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUISetState() While 1 Sleep(20) Switch GUIGetMsg() Case $b1Off _EnableDisable_Group($DummyStart1, $DummyEnd1, $GUI_UNCHECKED) Case $b1On _EnableDisable_Group($DummyStart1, $DummyEnd1, $GUI_CHECKED) Case $b2Off _EnableDisable_Group($DummyStart2, $DummyEnd2, $GUI_DISABLE) Case $b2On _EnableDisable_Group($DummyStart2, $DummyEnd2, $GUI_ENABLE) Case -3 Exit EndSwitch WEnd Func _EnableDisable_Group($iFrom, $iTo, $iState) For $i = $iFrom To $iTo GUICtrlSetState($i, $iState) Next EndFunc
Xandl Posted June 26, 2008 Author Posted June 26, 2008 Hello, thanks for testing this. @rasim: yes, I already saw this solution on the forums, and I like the surprising idea of using dummy controls. But it would require more attention in writing the main script code, i.e. you cannot use that with 'strayed' controls which are not created in sequence. What I do not like about my solution, is the sloppyness of the 'brute force' trying to get the control ids (1-500). While it seems to be fast enough, it would be more elegant to have a list of ids in your window. But to avoid this a little, one could pass the last created control id as $iMaxCtrlId, which could of course be a dummy control :-) ciao Xandl
YellowLab Posted August 19, 2008 Posted August 19, 2008 Hello, thanks for testing this. @rasim: yes, I already saw this solution on the forums, and I like the surprising idea of using dummy controls. But it would require more attention in writing the main script code, i.e. you cannot use that with 'strayed' controls which are not created in sequence. What I do not like about my solution, is the sloppyness of the 'brute force' trying to get the control ids (1-500). While it seems to be fast enough, it would be more elegant to have a list of ids in your window. But to avoid this a little, one could pass the last created control id as $iMaxCtrlId, which could of course be a dummy control :-) ciao Xandl Isn't this what GUICreateGroup is for? You create and open and end group holder (like the dummy file) and use those in rasim's function: expandcollapse popup#include <GUIConstants.au3> GUICreate('test',430,160) Global $g1s=GUICtrlCreateGroup('Test group - check/uncheck',10,10,200,100) Global $c11=GUICtrlCreateCheckbox('11111',20,30) Global $c12=GUICtrlCreateCheckbox('22222',20,50) Global $c13=GUICtrlCreateCheckbox('33333',20,70) Global $r1=GUICtrlCreateRadio('test',100,50,60) Global $g1e=GUICtrlCreateGroup("", -99, -99, 1, 1) ;added Global $b1Off=GUICtrlCreateButton('off',40,120,60) Global $b1On=GUICtrlCreateButton('on',120,120,60) Global $g2s=GUICtrlCreateGroup('Test group - enable/disable',220,10,200,100) Global $c21=GUICtrlCreateCheckbox('11111',230,30) Global $c22=GUICtrlCreateCheckbox('22222',230,50) Global $c23=GUICtrlCreateCheckbox('33333',230,70) Global $b2=GUICtrlCreateButton('test',310,50,60) Global $g2e=GUICtrlCreateGroup("", -99, -99, 1, 1) ;added Global $b2Off=GUICtrlCreateButton('off',250,120,60) Global $b2On=GUICtrlCreateButton('on',330,120,60) GUISetState() While 1 Sleep(20) Switch GUIGetMsg() Case $b1Off _GUICtrlGroup_SetState($GUI_UNCHECKED,$g1s,$g1e) Case $b1On _GUICtrlGroup_SetState($GUI_CHECKED,$g1s,$g1e) Case $b2Off _GUICtrlGroup_SetState($GUI_DISABLE,$g2s,$g2e) Case $b2On _GUICtrlGroup_SetState($GUI_ENABLE,$g2s,$g2e) Case -3 Exit EndSwitch WEnd Func _GUICtrlGroup_SetState($iState, $iFrom, $iTo) For $i = $iFrom To $iTo GUICtrlSetState($i, $iState) Next EndFunc Bob You can't see a rainbow without first experiencing the rain.
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