Jump to content

Recommended Posts

Posted (edited)

$Form1 = GUICreate("", 195, 137, 192, 124)

$Checkbox1 = GUICtrlCreateCheckbox("Save UserName", 48, 88, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Save Password", 48, 104, 97, 17)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$check = GUICtrlGetState($Checkbox1)
MsgBox(0, "", $check)

EndSwitch
WEnd
EndFunc

is GuiCtrlGetState not suposed to return the state of the controler ? $GUI_CHECKED, $GUI_ENABLED ....

i get number (checked or unchecked) i get 80 ?!?!?

what is that ?

Edited by HeavenlyDemon
  • Moderators
Posted

HeavenlyDemon,

GUICtrlGetState returns the overall state of the control - which could well be a combination of several states (i.e checked and disabled). If you want to check for a specific state then you need to use BitAND like this:

; Is it checked?
If BitAND(GUICtrlGetState($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
    ; It is checked
Else
    ; It is NOT checked
EndIf

This works as the states are carefully defined so that they only affect single bits. The same is true for styles - look at the Setting Styles tutorial in the Wiki for more information on this. ;)

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

HeavenlyDemon,

Ah sorry, for Checkbox and Radio controls I just remembered that you need to use GUICtrlRead. :wacko:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$cCheck = GUICtrlCreateCheckbox(" Test", 10, 10, 200, 20)

$cButton = GUICtrlCreateButton("Read State", 10, 100, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ConsoleWrite(GUICtrlRead($cCheck) & @CRLF)
            If BitAND(GUICtrlRead($cCheck), $GUI_CHECKED) Then
                MsgBox(0, "Hi", "Checked")
            Else
                MsgBox(0, "Hi", "NOT Checked")
            EndIf
    EndSwitch

WEnd

I posted about it in this thread and GEOSoft offered a possible explanation of why this is the case. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Note the return table in GUICtrlRead. It is a tricky one as I used to make the same assumption as you did about GUICtrlGetState and checkboxes.

GUICtrlRead

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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