Jump to content
Sign in to follow this  
morevolume

GUISetOnEvent with checkboxes

Recommended Posts

Hi,

i have a GUI with many checkboxes masked with $BS_PUSHLIKE and $BS_ICON. Want to switch the image in case of the current checkbox state after clicking the checkbox.

Therefor i wrote a funktion wich updates the image state.

The problem is to start the funktion by using "GUISetOnEvent". Indeed GUISetOnEvent works fine with buttons.

Thanks for your ideas!

#include <GUIConstants.au3>

GUICreate("test",240,180)
$Checkbox_1 = GUICtrlCreateCheckbox("", 20,20,40,40,$BS_PUSHLIKE+$BS_ICON)
GUICtrlSetImage ($Checkbox_1,"shell32.dll",22)
GUISetOnEvent($Checkbox_1,"_UpdateGUI")

$Checkbox_2 = GUICtrlCreateCheckbox("", 20,80,40,40,$BS_PUSHLIKE+$BS_ICON)
GUICtrlSetImage ($Checkbox_2,"shell32.dll",22)
GUISetOnEvent($Checkbox_1,"_UpdateGUI")
; Checkbox_3
;
;
;Checkbox_20
GUISetState()

Func _UpdateGUI();make GUI Refresh

if GuiCtrlRead($Checkbox_1) = $GUI_CHECKED then   
        GUICtrlSetImage ($Checkbox_1,"shell32.dll",22); if checked
        else
        GUICtrlSetImage ($Checkbox_1,"shell32.dll",23); if unchecked
        endif
    
        if GuiCtrlRead($Checkbox_2) = $GUI_CHECKED then   
        GUICtrlSetImage ($Checkbox_2,"shell32.dll",22); if checked
        else
        GUICtrlSetImage ($Checkbox_2,"shell32.dll",23); if unchecked
        endif
; Checkbox_3
;
;
;Checkbox_20
EndFunc

While 1
    $msg = GUIGetMsg()
Select
    case $msg = $GUI_EVENT_CLOSE
        exitloop
    
EndSelect
WEnd
GUIDelete()

Share this post


Link to post
Share on other sites

you can not mix "on event" and "Guigetmsg()

#include <GUIConstants.au3>


Dim $State_1 = True, $State_2 = True

GUICreate("test", 240, 180)
$Checkbox_1 = GUICtrlCreateCheckbox("", 20, 20, 40, 40, $BS_PUSHLIKE + $BS_ICON)
GUICtrlSetImage($Checkbox_1, "shell32.dll", 22)

$Checkbox_2 = GUICtrlCreateCheckbox("", 20, 80, 40, 40, $BS_PUSHLIKE + $BS_ICON)
GUICtrlSetImage($Checkbox_2, "shell32.dll", 22)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Checkbox_1 Then _UpdateGUI_1()
    If $msg = $Checkbox_2 Then _UpdateGUI_2()
    If $msg = -3 Then Exit
WEnd

Func _UpdateGUI_1();make GUI Refresh
    $State_1 = Not $State_1
    
    If $State_1 Then
        GUICtrlSetImage($Checkbox_1, "shell32.dll", 22); if checked
    Else
        GUICtrlSetImage($Checkbox_1, "shell32.dll", 23); if unchecked
    EndIf

EndFunc   ;==>_UpdateGUI_1

Func _UpdateGUI_2();make GUI Refresh
    $State_2 = Not $State_2
    
    If $State_2 Then
        GUICtrlSetImage($Checkbox_2, "shell32.dll", 22); if checked
    Else
        GUICtrlSetImage($Checkbox_2, "shell32.dll", 23); if unchecked
    EndIf

EndFunc   ;==>_UpdateGUI_2

8)

Share this post


Link to post
Share on other sites

OK i was bored... here is on event mode

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

GUICreate("test", 240, 180)
GUISetOnEvent($GUI_EVENT_CLOSE, "Exiter")
$Checkbox_1 = GUICtrlCreateCheckbox("", 20, 20, 40, 40, BitOR($BS_PUSHLIKE, $BS_ICON))
GUICtrlSetOnEvent($Checkbox_1, "UpdateGUI")
GUICtrlSetImage($Checkbox_1, "shell32.dll", 22)

$Checkbox_2 = GUICtrlCreateCheckbox("", 20, 80, 40, 40, BitOR($BS_PUSHLIKE, $BS_ICON))
GUICtrlSetOnEvent($Checkbox_2, "UpdateGUI")
GUICtrlSetImage($Checkbox_2, "shell32.dll", 22)
GUISetState()

Func UpdateGUI();make GUI Refresh

    If GUICtrlRead($Checkbox_1) = $GUI_CHECKED Then
        GUICtrlSetImage($Checkbox_1, "shell32.dll", 23); if checked
    Else
        GUICtrlSetImage($Checkbox_1, "shell32.dll", 22); if unchecked
    EndIf

    If GUICtrlRead($Checkbox_2) = $GUI_CHECKED Then
        GUICtrlSetImage($Checkbox_2, "shell32.dll", 23); if checked
    Else
        GUICtrlSetImage($Checkbox_2, "shell32.dll", 22); if unchecked
    EndIf

EndFunc   ;==>UpdateGUI

While 1
    Sleep(200)
WEnd

Func Exiter()
    Exit
EndFunc   ;==>Exiter

Your problem is you did not use this at all

GUICtrlSetOnEvent()

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

morevolume

And if you used many checkbox controls, then better be use @GUI_CtrlId macro instead of checking each controls:

#include <GUIConstants.au3>

Opt("GuiOnEventMode", 1)

GUICreate("test",240,180)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Checkbox_1 = GUICtrlCreateCheckbox("", 20,20,40,40,$BS_PUSHLIKE+$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",22)
GUICtrlSetOnEvent(-1, "_UpdateGUI")

$Checkbox_2 = GUICtrlCreateCheckbox("", 20,80,40,40,$BS_PUSHLIKE+$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",22)
GUICtrlSetOnEvent(-1, "_UpdateGUI")

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc

Func _UpdateGUI();make GUI Refresh
    If BitAND(GuiCtrlRead(@GUI_CtrlId), $GUI_CHECKED) Then
        GUICtrlSetImage(@GUI_CtrlId, "shell32.dll", 23); if checked
    Else
        GUICtrlSetImage (@GUI_CtrlId, "shell32.dll", 22); if unchecked
    EndIf
EndFunc
:)

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
Sign in to follow this  

×
×
  • Create New...