Jump to content

[SOLVED] GUICtrlGetState and GUICtrlSetState... Bitwise comparison


batfastad
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 years later...

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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...