Jump to content

GUICtrlCreateCheckbox and GUICtrlSetState


Recommended Posts

Hello...the code below should give you an idea of what I'm attempting to do...it's just not working. Essentially, if the "AnalyzeOnly" checkbox is checked, the other two uncheck and disable, if the "AnalyzeOnly" checkbox is unchecked, then $CleanSystem_CB gets enabled and checked and $Install_CB get's enabled. Hope that makes sense. Commented out is my first attempt.

While 1
;~  If GUICtrlRead($AnalyzeOnly_CB) = 1 Then
;~      $STATE = "CHECKED"
;~      GUICtrlSetState($CleanSystem_CB, $GUI_UNCHECKED)
;~      GUICtrlSetState($CleanSystem_CB, $GUI_DISABLE)
;~      GUICtrlSetState($Install_CB, $GUI_UNCHECKED)
;~      GUICtrlSetState($Install_CB, $GUI_DISABLE)

;~  ElseIf GUICtrlRead($AnalyzeOnly_CB) = 0 Then
;~      $STATE = "UNCHECKED"
;~      GUICtrlSetState($CleanSystem_CB, $GUI_ENABLE)
;~      GUICtrlSetState($CleanSystem_CB, $GUI_CHECKED)
;~      GUICtrlSetState($Install_CB, $GUI_ENABLE)
;~  EndIf

    If GUICtrlRead($AnalyzeOnly) = 1 Then
        $STATE = "CHECKED"
        If GUICtrlRead($CleanSystem_CB) < $GUI_DISABLE Then GUICtrlSetState($CleanSystem_CB, $GUI_DISABLE)
        GUICtrlSetState($CleanSystem_CB, $GUI_UNCHECKED)
        If GUICtrlGetState($Install_CB) < $GUI_DISABLE Then GUICtrlSetState($Install_CB, $GUI_DISABLE)
        GUICtrlSetState($Install_CB, $GUI_UNCHECKED)
    ElseIf GUICtrlRead($AnalyzeOnly) < 1 Then
        $STATE = "UNCHECKED"
        If GUICtrlGetState($CleanSystem_CB) > $GUI_ENABLE Then GUICtrlSetState($CleanSystem_CB, $GUI_ENABLE)
        GUICtrlSetState($CleanSystem_CB, $GUI_CHECKED)
        If GUICtrlGetState($Install_CB) > $GUI_ENABLE Then GUICtrlSetState($Install_CB, $GUI_ENABLE)
    EndIf

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Clean
            If $Inst = "No" Then
                Clean()
            ElseIf $Inst = "Yes" Then
                Upgrade()
            EndIf
        Case $Button_Cancel
            _FileWriteLog($log, " Installation was canceled" & @CRLF & @CRLF)
            Exit
        Case $GUI_EVENT_CLOSE
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $exititem
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $aboutitem
            Set_ABT()
        Case $commandline
            Set_CMD()
    EndSwitch
WEnd

Thanks for any suggestions,

-Mike

Edited by mdwerne
Link to comment
Share on other sites

  • Moderators

mdwerne,

How is this? ;)

#include <GUIConstantsEx.au3>

$STATE = "UNCHECKED"

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

$AnalyzeOnly = GUICtrlCreateCheckbox("Analyse", 10, 10, 100, 20)
$CleanSystem_CB = GUICtrlCreateCheckbox("Clean", 10, 50, 100, 20)
$Install_CB = GUICtrlCreateCheckbox("Install", 10, 90, 100, 20)

GUISetState()

While 1

    Switch GUICtrlRead($AnalyzeOnly)
        Case 1
            If $STATE = "UNCHECKED" Then
                GUICtrlSetState($CleanSystem_CB, BitOr($GUI_DISABLE, $GUI_UNCHECKED))
                GUICtrlSetState($Install_CB, BitOr($GUI_DISABLE, $GUI_UNCHECKED))
                $STATE = "CHECKED"
            EndIf
        Case 4
            If $STATE = "CHECKED" Then
                GUICtrlSetState($CleanSystem_CB, BitOr($GUI_ENABLE, $GUI_CHECKED))
                GUICtrlSetState($Install_CB, BitOr($GUI_ENABLE, $GUI_UNCHECKED))
                $STATE = "UNCHECKED"
            EndIf
    EndSwitch

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I hope it helps. :huh2:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

mdwerne,

How is this? ;)

code snipped...

I hope it helps. :huh2:

M23

Thank you! This is exactly what I needed, works perfectly and is a good lesson for me as well.

Have a great day!

-Mike

P.S. I'm also using ExtMsgBox on this project...you do excellent work!

Edited by mdwerne
Link to comment
Share on other sites

You might want to clean up the Code M23 posted too.

Switch followed by Switch = works

Switch Nested within Switch with an extra Case = works even better

New Case Statement with a New Function = better yet

#include <GUIConstantsEx.au3>

$STATE = 0;"UNCHECKED"

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

$AnalyzeOnly = GUICtrlCreateCheckbox("Analyse", 10, 10, 100, 20)
$CleanSystem_CB = GUICtrlCreateCheckbox("Clean", 10, 50, 100, 20)
$Install_CB = GUICtrlCreateCheckbox("Install", 10, 90, 100, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $AnalyzeOnly
            _StateChange()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func _StateChange()
    $State = NOT $State
    If $State Then
        GUICtrlSetState($CleanSystem_CB, BitOr($GUI_ENABLE, $GUI_CHECKED))
        GUICtrlSetState($Install_CB, BitOr($GUI_ENABLE, $GUI_UNCHECKED))
    Else
        GUICtrlSetState($CleanSystem_CB, BitOr($GUI_DISABLE, $GUI_UNCHECKED))
        GUICtrlSetState($Install_CB, BitOr($GUI_ENABLE, $GUI_UNCHECKED))
    EndIf
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

I know you will not believe me but I did think of that. :huh2:

However, I wondered if the OP was using the $STATE variable elsewhere and decided to leave the existing literal string values rather than converting it to True/False.

More elegant code your way though. ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Even doing it your way I would have simply added

Case $AnalyzeOnly

To the main loop and then put your other switch inside of there. It makes no sense to check a Switch until you are reguired to do so.

No matter, he now has a couple of methods and there is still the potential that someone else will learn from the thread.

Edit: Here's what I meant

#include <GUIConstantsEx.au3>

$STATE = "UNCHECKED"

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

$AnalyzeOnly = GUICtrlCreateCheckbox("Analyse", 10, 10, 100, 20)
$CleanSystem_CB = GUICtrlCreateCheckbox("Clean", 10, 50, 100, 20)
$Install_CB = GUICtrlCreateCheckbox("Install", 10, 90, 100, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $AnalyzeOnly
            Switch GUICtrlRead($AnalyzeOnly)
                Case 1
                    If $STATE = "UNCHECKED" Then
                        GUICtrlSetState($CleanSystem_CB, BitOr($GUI_DISABLE, $GUI_UNCHECKED))
                        GUICtrlSetState($Install_CB, BitOr($GUI_DISABLE, $GUI_UNCHECKED))
                        $STATE = "CHECKED"
                    EndIf
                Case 4
                    If $STATE = "CHECKED" Then
                        GUICtrlSetState($CleanSystem_CB, BitOr($GUI_ENABLE, $GUI_CHECKED))
                        GUICtrlSetState($Install_CB, BitOr($GUI_ENABLE, $GUI_UNCHECKED))
                        $STATE = "UNCHECKED"
                    EndIf
            EndSwitch
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

All clear? :huh2:

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

Crystal as always. :huh2:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks Geosoft and M23 for the continued suggestions for improvement...to make things a bit easier, here is what I'm actually working with. At this point I just need to add one more state change. Essentially a toggle between $AnalyzeOnly and $CleanSystem.

if $AnalyzeOnly is checked then: $CleanSystem is unchecked and enabled and $Install is unchecked and disabled

on the other hand

if $CleanSystem is then checked: $AnalyzeOnly is unchecked (still enabled) and $Install is enabled

$AnalyzeOnlyState tells the functions further down the line NOT to do any work. That's the reason for $AnalyzeOnlyState = "CHECKED" or "UNCHECKED"

#include <GUIConstantsEx.au3>
#include <File.au3>

Global $log = @HomeDrive & "\JavaCleaner.log"
Global $AnalyzeOnlyState = "UNCHECKED"
Global $InstJRE = "No"
Global $MSIArray, $uninstallname, $uninstallversion
Global $GUI, $GUIGroupBox1, $GUIText1, $GUIText2, $GUIText3, $GUIText4, $Button_Clean, $Button_Cancel, $Logo
Global $progressbar, $nMsg, $CloseApps, $Install, $commandline, $filemenu, $AnalyzeOnly, $CleanSystem

; =======================================================================
; GUI
; =======================================================================
$GUI = GUICreate("JavaCleaner", 450, 300, -1, -1)
GUISetBkColor(0xFFFFFF)
$GUIGroupBox1 = GUICtrlCreateGroup("", 17, 9, 416, 225)
GUICtrlCreateGroup("Options", 30, 25, 390, 100)
$AnalyzeOnly = GUICtrlCreateCheckbox(" Analyze Only (NO changes will be made to this computer)", 42, 45, 350, 20)
$CleanSystem = GUICtrlCreateCheckbox(" Clean the Java JRE/JDK 1.3.x -> 1.6.x off this computer (Default)", 42, 70, 350, 20)
GUICtrlSetState($CleanSystem, $GUI_DISABLE + $GUI_CHECKED)
$Install = GUICtrlCreateCheckbox(" Install JRE (The latest 32bit Java JRE will be installed after cleaning)", 42, 95, 375, 20)
$Button_Clean = GUICtrlCreateButton("&Run JavaCleaner", 100, 133, 120, 50)
GUICtrlSetFont(-1, 10, 400, 0, "Georgia")
$GUIText1 = GUICtrlCreateLabel("OR", 240, 150, 40, 35)
GUICtrlSetFont(-1, 12, 600, 0, "Georgia")
$Button_Cancel = GUICtrlCreateButton("Cancel", 285, 148, 65, 25)
GUICtrlSetFont(-1, 10, 400, 0, "Georgia")
GUICtrlSetState(-1, $GUI_FOCUS)
$GUIText2 = GUICtrlCreateLabel("Warning!", 85, 190, 60, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetFont(-1, 10, 400, 0, "Georgia")
$GUIText3 = GUICtrlCreateLabel("This utility will automatically close", 146, 190, 250, 20)
GUICtrlSetColor(-1, 0x252525)
GUICtrlSetFont(-1, 10, 400, 0, "Georgia")
$GUIText4 = GUICtrlCreateLabel("all web browsers and Java applications.", 104, 208, 300, 20)
GUICtrlSetColor(-1, 0x252525)
GUICtrlSetFont(-1, 10, 400, 0, "Georgia")
$filemenu = GUICtrlCreateMenu("&File")
$exititem = GUICtrlCreateMenuItem("&Exit", $filemenu)
$infomenu = GUICtrlCreateMenu("&Help")
$commandline = GUICtrlCreateMenuItem("Command-Line &Switches", $infomenu)
$aboutitem = GUICtrlCreateMenuItem("&About JavaCleaner", $infomenu)
$SNL_Logo = GUICtrlCreatePic("", 137, 241, 178, 30)
;_ResourceSetImageToCtrl($Logo, "lineCLR_SM")

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()

        Case $AnalyzeOnly
            _StateChange()
        Case $Button_Clean
            If GUICtrlRead($Install) <> 1 Then
                ;Clean()
            Else
                ;Upgrade()
            EndIf
        Case $Button_Cancel
            _FileWriteLog($log, " Installation was canceled" & @CRLF & @CRLF)
            Exit
        Case $GUI_EVENT_CLOSE
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $exititem
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $aboutitem
            ;Set_ABT()
        Case $commandline
            ;Set_CMD()
    EndSwitch
WEnd

; =======================================================================
; Functions
; =======================================================================

Func _StateChange()
    $AnalyzeOnlyState = Not $AnalyzeOnlyState
    If $AnalyzeOnlyState Then
        GUICtrlSetState($CleanSystem, BitOR($GUI_ENABLE, $GUI_CHECKED))
        GUICtrlSetState($Install, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
    Else
        GUICtrlSetState($CleanSystem, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
        GUICtrlSetState($Install, BitOR($GUI_DISABLE, $GUI_UNCHECKED))
    EndIf
EndFunc   ;==>_StateChange

Again, I thank you both for your time,

-Mike

Edited by mdwerne
Link to comment
Share on other sites

If I understand this correctly just add one more case statement into the Switch

Case $CleanSystem
    GUICtrlSetState($AnalyzeOnly, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
    GUICtrlSetState($Install, $GUI_ENABLE)

Again you could just write another handler function to do it for you. Pretty much the same function I gave before except for the Variable names.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If I understand this correctly just add one more case statement into the Switch

Case $CleanSystem
    GUICtrlSetState($AnalyzeOnly, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
    GUICtrlSetState($Install, $GUI_ENABLE)

Again you could just write another handler function to do it for you. Pretty much the same function I gave before except for the Variable names.

Yes, you understood correctly. I believe this is what I was after.

While 1
    Switch GUIGetMsg()

        Case $AnalyzeOnly
            _AnalyzeOnlyStateChange()
        Case $CleanSystem
            _CleanSystemStateChange()
        Case $Button_Clean
            If GUICtrlRead($Install) <> 1 Then
                ;Clean()
            Else
                ;Upgrade()
            EndIf
        Case $Button_Cancel
            _FileWriteLog($log, " Installation was canceled" & @CRLF & @CRLF)
            Exit
        Case $GUI_EVENT_CLOSE
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $exititem
            _FileWriteLog($log, " GUI was closed" & @CRLF & @CRLF)
            Exit
        Case $aboutitem
            ;Set_ABT()
        Case $commandline
            ;Set_CMD()
    EndSwitch
WEnd

Func _AnalyzeOnlyStateChange()
    If GUICtrlRead($AnalyzeOnly) = 1 Then
        GUICtrlSetState($CleanSystem, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
        GUICtrlSetState($Install, BitOR($GUI_DISABLE, $GUI_UNCHECKED))
    Else
        GUICtrlSetState($CleanSystem, BitOR($GUI_ENABLE, $GUI_CHECKED))
        GUICtrlSetState($Install, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
    EndIf
EndFunc   ;==>_AnalyzeOnlyStateChange

Func _CleanSystemStateChange()
    If GUICtrlRead($CleanSystem) = 1 Then
        GUICtrlSetState($CleanSystem, $GUI_DISABLE)
        GUICtrlSetState($AnalyzeOnly, $GUI_UNCHECKED)
        GUICtrlSetState($Install, BitOR($GUI_ENABLE, $GUI_UNCHECKED))
    Else
        GUICtrlSetState($AnalyzeOnly, $GUI_CHECKED)
        GUICtrlSetState($Install, BitOR($GUI_DISABLE, $GUI_UNCHECKED))
    EndIf
EndFunc   ;==>_CleanSystemStateChange

Seems to work as expected.

Thanks,

-Mike

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...