Jump to content

SetState Control with dummy


 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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

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

 

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

 

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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

#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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

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

 

Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

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