Terenz Posted October 4, 2014 Share Posted October 4, 2014 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 More sharing options...
mikell Posted October 4, 2014 Share Posted October 4, 2014 (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 October 4, 2014 by mikell Link to comment Share on other sites More sharing options...
Terenz Posted October 4, 2014 Author Share Posted October 4, 2014 (edited) I don't see any difference 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 October 4, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Terenz Posted October 4, 2014 Author Share Posted October 4, 2014 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 More sharing options...
Gianni Posted October 4, 2014 Share Posted October 4, 2014 .... 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted October 4, 2014 Share Posted October 4, 2014 Argh ! The dummy is gone away Link to comment Share on other sites More sharing options...
Gianni Posted October 4, 2014 Share Posted October 4, 2014 (edited) Argh ! The dummy is gone away yes, I don't like the dummy Edited October 4, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted October 4, 2014 Share Posted October 4, 2014 Personally I totally agree but it's deviating from the topic title ... Link to comment Share on other sites More sharing options...
Gianni Posted October 4, 2014 Share Posted October 4, 2014 (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 October 4, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Terenz Posted October 4, 2014 Author Share Posted October 4, 2014 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 More sharing options...
Gianni Posted October 4, 2014 Share Posted October 4, 2014 (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 October 4, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now