Code: Select all
#SingleInstance force
#NoEnv
; RadioToggler: allows for Radio buttons that can be clicked off, like a Checkbox,
; but they still switch off other Radio buttons in the same group, like a Radio button.
ButtonCount := 0 ; You need some way to keep track of the classNN Button number for the Radio buttons you want to uncheck
CurrentButtonStatus := 0
Gui,Add, Radio, vMyRadioGroup1 group gRadioToggler, good
++ButtonCount
Gui,Add, Radio, ys vMyRadioGroup2 gRadioToggler, better
++ButtonCount
Gui,Add, Radio, ys vMyRadioGroup3 gRadioToggler, best
++ButtonCount
Gui,Add, Checkbox, ys , box one ; no need to put gRadioToggler for other Checkboxes or Radio buttons you don't wish to ever uncheck
++ButtonCount
Gui,Add, Checkbox, ys gRadioToggler, box two ; but it doesn't hurt anything if you do put it in except is "uses up" your g-label
++ButtonCount
Gui, Show
loop, %ButtonCount%
{
TogglerButton%A_Index% := 0
}
return
RadioToggler:
{
; The variable CurrentButtonStatus will be zero or one representing the state of the button just BEFORE you clicked it
MouseGetPos,,,, TempNN ; TempNN is (ClassNN) like Button1, Button2, etc
CurrentButtonStatus := Toggler%TempNN% ; e.g. Toggler%TempNN% could be TogglerButton1
If (CurrentButtonStatus = 0)
{
Toggler%TempNN% := 1
GuiControl, ,%TempNN%,1
}
If (CurrentButtonStatus = 1)
{
Toggler%TempNN% := 0
GuiControl, ,%TempNN%,0
}
loop, %ButtonCount% ; see note below
{
ControlGet, TogglerButton%A_Index%, Checked , , Button%A_Index%
}
;One of the Radio Buttons may have been ON prior to this Radio Button click.
;If so, it switched off when this button was clicked.
;If I were more clever, I would just switch that one button's TogglerButton variable.
;But I'm not, so I'll just update the TogglerButton variable for all buttons
;You can omit this ControlGet step but then you have to click twice to turn on a button
Return
}
Escape:
Guiclose:
GuiEscape:
Exitapp