- ControlSetChecked (AHK v2) and Control Check/Uncheck (AHK v1), check/uncheck(tick/untick) the checkbox in a Button control.
- The functions/subcommands, which use BM_CLICK in the source code, have the side effect of *focusing* the control.
- BM_SETCHECK does not have this side effect.
- [EDIT:] Presumably BM_CLICK has some advantage over BM_SETCHECK, perhaps it's more likely to work, otherwise why was it chosen?
- [EDIT:] In the tests I did, BM_SETCHECK worked, so any examples where BM_SETCHECK doesn't work would be useful.
- I'm posting in case anyone has any examples where ControlSetChecked (or Control Check/Uncheck) works, but where BM_SETCHECK doesn't work.
- Note: ticking/unticking a checkbox could conceivably fail in two ways:
- (1) complete failure: there is no change in appearance, and the window doesn't register the change
- (2) partial failure: there is a change in appearance (the tick is added/removed), however, the window does not seem to have registered the change [perhaps in such cases, a way to notify the control/window could be found]
- My 2 use cases were the Notepad Find dialog, and my own AutoHotkey GUIs, BM_SETCHECK worked fine in both cases.
- Thanks for reading.
Code: Select all
q:: ;toggle checkbox via BM_CLICK (ControlSetChecked) ;e.g. test on Notepad Find dialog ;note: has the side effect of focusing the checkbox ControlGet, hCtl, Hwnd,, Button2, A ControlGet, vIsChecked, Checked,,, % "ahk_id " hCtl vSubCmd := vIsChecked ? "Uncheck" : "Check" Control, % vSubCmd,,, % "ahk_id " hCtl ;uses BM_CLICK in the source code return w:: ;toggle checkbox via BM_SETCHECK ;e.g. test on Notepad Find dialog ;note: has the benefit of not focusing the checkbox ControlGet, hCtl, Hwnd,, Button2, A ControlGet, vIsChecked, Checked,,, % "ahk_id " hCtl SendMessage, 0xF1, % !vIsChecked, 0,, % "ahk_id " hCtl ;BM_SETCHECK := 0xF1 return