Jump to content
batfastad

[SOLVED] GUICtrlGetState and GUICtrlSetState... Bitwise comparison

Recommended Posts

batfastad

Hi everyone

I've got a collection of radio buttons and checkboxes. When a user presses some radio buttons I want to uncheck and disable a particular checkbox.

This is easy, done by just summing the state flags...

Func _RadioOutputPNGClick()
If GUICtrlGetState($RadioOutputPNG) = $GUI_CHECKED Then
; PNG RADIO BUTTON CHECKED, TEXT PATHS CHECKBOX UNCHECK AND DISABLE
GUICtrlSetState($CheckboxTextPaths, $GUI_UNCHECKED + $GUI_DISABLE)
Else
; PNG RADIO BUTTON CHECKED, TEXT PATHS CHECKBOX CHECK AND ENABLE
GUICtrlSetState($CheckboxTextPaths, $GUI_CHECKED + $GUI_ENABLE)
EndIf
EndFunc

But when trying to assertain whether the radio button $RadioOutputPNG is checked or not, is my comparison above flawed if $RadioOutputPNG has another state flag set?

Lets say $GUI_CHECKED = 1 and $GUI_DISABLE = 128 (from GUIConstantsEx.au3) and both are set for $RadioOutputPNG

In my comparison above I'm basically checking whether $RadioOutputPNG = 1.

Does this return false if both state flags are set, as the state of $RadioOutputPNG would actually be 129.

So should I actually be doing a Bitwise comparison here?

Cheers, B

Edited by batfastad

Share this post


Link to post
Share on other sites
batfastad

Don't worry! Solved by RTFM!

The answer is yes, I should do bitwise comparison...

If BitAND(GUICtrlRead($RadioOutputPNG), $GUI_CHECKED) Then

EDIT:

For completeness, if you want to check that a radio/checkbox is checked AND enabled then I think you need to do two different comparisons.

I was expecting this to work but it doesn't...

If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED, $GUI_ENABLE) Then

Because GUICtrlRead() doesn't return the state for checkboxes.

Instead you have to additionally check GUICtrlGetState()...

If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED) AND BitAND(GUICtrlGetState($CheckboxText), $GUI_ENABLE) Then

This is something that I just fell into because of the wording in the help under GUICtrlRead()... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm

In the table under the "Return Value" section, the "Checkbox, Radio" row has a link to this table of states... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm#StateTable

By linking to that table in the return value on the GUICtrlRead() page, I assumed that all the items in that table of states would be valid return values for GUICtrlRead() but it turns out to not be the case.

I'm not an expert so I might be wrong here and I would appreciate someone correcting me if I am wrong :D

But I hope this helps someone out!

Cheers, B

Edited by batfastad
  • Like 1

Share this post


Link to post
Share on other sites
AutoBert

It's not better just a other possible way, both did same for a checkbox:

Quote

For Checkbox and Radio controls only the $GUI_CHECKED (1), $GUI_UNCHECKED (4) or $GUI_INDETERMINATE (2) states are returned so the value can be used directly.

so, why necroing a old thread?

Share this post


Link to post
Share on other sites
blk_panther

Because it's shorter and faster. And I don't want to leave the ones that come here in search for a solution with an inferior one.

Share this post


Link to post
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

×