Sign in to follow this  
Followers 0
Terenz

SetState Control with dummy

11 posts in this topic

Hello guys

Partically i want to fire a "Case" event using a dummy but not work, advice?

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

Global $Dummy = GUICtrlCreateDummy()

$Form1 = GUICreate("Form1", 201, 75, 208, 178)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
_GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1, $Dummy
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                GUICtrlSetState($Checkbox2, $GUI_CHECKED)
            Else
                GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
            EndIf
    EndSwitch
WEnd

Func _GUICtrlSetState($hControl, $sStatus)
    If $sStatus = $GUI_CHECKED Then
        GUICtrlSendToDummy($Dummy, $GUI_CHECKED)
    Else
        GUICtrlSendToDummy($Dummy, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>_GUICtrlSetState

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It will work better if you create the control after the GuiCreate  :)

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

;Global $Dummy = GUICtrlCreateDummy()

$Form1 = GUICreate("Form1", 201, 75, 208, 178)
$Dummy = GUICtrlCreateDummy()
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            _GUICtrlSetState(GUICtrlRead($Checkbox1))
        Case $Dummy
            GUICtrlSetState($Checkbox2, GUICtrlRead($Dummy))
    EndSwitch
WEnd

Func _GUICtrlSetState($sStatus)
    If $sStatus = $GUI_CHECKED Then
        GUICtrlSendToDummy($Dummy, $GUI_CHECKED)
    Else
        GUICtrlSendToDummy($Dummy, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>_GUICtrlSetState
Edited by mikell

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't see any difference :sweating:

Pratically the expected result ( is only an example, indeed ) is both checkbox checked at the startup of the script, like the click on the "Case $Checkbox1". Yes i know i can use a separate Func() etc. but i'd like to do it with Dummy

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

Well, after a couple of hour i have found a solution by myself:

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

$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Dummy = GUICtrlCreateDummy()

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)

GUICtrlSendToDummy($Dummy)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy
            ConsoleWrite("DUMMY" & @CRLF)
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
            ContinueCase
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                GUICtrlSetState($Checkbox2, $GUI_CHECKED)
            Else
                GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
            EndIf
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
    EndSwitch
WEnd

If someone has better one, just post it


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

....

If someone has better one, just post it

 

don't know if is better, at least it's shorter...

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)
ControlClick("", "", $Checkbox1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
    EndSwitch
WEnd

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Argh !

The dummy is gone away  :D

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Argh !

The dummy is gone away  :D

 

yes, I don't like the dummy :pirate:

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Personally I totally agree but it's deviating from the topic title ...

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <GUIConstantsEx.au3>
$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Dummy = GUICtrlCreateDummy()
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)
GUICtrlSendToDummy($Dummy)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
        Case $Dummy
            ConsoleWrite("DUMMY" & @CRLF)
            ControlClick("", "", $Checkbox1)
    EndSwitch
WEnd

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

I'll not use ControlClick ( for the first parameter you don't use the handle of the Gui? ) short or not i prefer to "send" the command not "click" the checkbox, is more elegant ;)

Thanks for the alternative.


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

try this then

edit: Buggy code (do not use this)

#include <GUIConstantsEx.au3>
$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Dummy = GUICtrlCreateDummy()
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)
GUICtrlSendToDummy($Dummy)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy
            ConsoleWrite("DUMMY" & @CRLF)
            GUICtrlSetState($Checkbox1, GUICtrlSetState($Checkbox2, 1))
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
    EndSwitch
WEnd

you could also select if initial state must be checked or unchecked by setting dummy to 1 or 0

#include <GUIConstantsEx.au3>
$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Dummy = GUICtrlCreateDummy()
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)
GUICtrlSendToDummy($Dummy, 1) ; 1 = checked; 0 = unchecked
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy
            ConsoleWrite("DUMMY" & @CRLF)
            GUICtrlSetState($Checkbox1, GUICtrlSetState($Checkbox2, 1 = GUICtrlRead($Dummy)))
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
    EndSwitch
WEnd

Edit: posted new code (this should work correctly)

set $GUI_CHECKED or $GUI_UNCHECKED to dummy to decide initial status of checkboxes

#include <GUIConstantsEx.au3>
$Form1 = GUICreate("Form1", 201, 75, -1, -1)
$Dummy = GUICtrlCreateDummy()
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 40, 97, 17)
GUISetState(@SW_SHOW)
GUICtrlSendToDummy($Dummy, $GUI_CHECKED) ; set $GUI_CHECKED or $GUI_UNCHECKED
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy
            ConsoleWrite("DUMMY" & @CRLF)
            GUICtrlSetState($Checkbox1, BitOR(GUICtrlRead($Checkbox1), GUICtrlRead($Dummy)))
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox1
            ConsoleWrite("CHCKBOX1" & @CRLF)
            GUICtrlSetState($Checkbox2, GUICtrlRead($Checkbox1))
        Case $Checkbox2
            ConsoleWrite("CHCKBOX2" & @CRLF)
    EndSwitch
WEnd
Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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  
Followers 0