dufran3 Posted September 22, 2006 Posted September 22, 2006 (edited) I am trying to create a GUI with checkboxes. 2 Tabs, that each contain checkboxes. Here is what I am trying to accomplish. My Code is complicated, but I just need help with a little part in it. The checkboxes, when I run the script, I'm not sure how to tell the script whether to check or uncheck them...here is an example of what I am talking about. expandcollapse popup#include <GuiConstants.au3> #include <H:\AutoIt\Scripts\Beta\KMC PC GUI\GUI_Functions_1.0.au3> Opt("GUIOnEventMode", 1) ; GUI $main1 = GuiCreate("Blah Blah Blah", 400, 400) GuiSetIcon("H:\AutoIt\pc.ico", 0) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") ;BUTTON $start1 = GuiCtrlCreateButton("Start",300,30,75,25) GUICtrlSetOnEvent($start1, "StartInstall") $exit1 = GuiCtrlCreateButton("Exit",300,70,75,25) GUICtrlSetOnEvent($exit1, "ExitButton") ; TAB0 GuiCtrlCreateTab(0, 80, 402, 400) $tab0=GUICtrlCreateTabitem ("Customization") $Ctrl01=GuiCtrlCreateCheckbox("Disable Automatic Updates", 5, 120, 150, 20) GuiCtrlSetState(-1, $GUI_UNCHECKED + $GUI_ENABLE) $Ctrl02=GuiCtrlCreateCheckbox("Disable Firewall", 5, 140, 100, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl03=GuiCtrlCreateCheckbox("Classic Start Menu", 5, 160, 120, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl04=GuiCtrlCreateCheckbox("Classic Windows Theme", 5, 180, 140, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl05=GuiCtrlCreateCheckbox("Add Domain Users", 5, 200, 110, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl06=GuiCtrlCreateCheckbox("IE Settings", 5, 220, 75, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl07=GuiCtrlCreateCheckbox("Power Settings (PC)", 5, 240, 115, 20) GuiCtrlSetState(-0, $GUI_CHECKED) $Ctrl08=GuiCtrlCreateCheckbox("Power Settings (Laptop)", 5, 260, 135, 20) GuiCtrlSetState(-0, $GUI_CHECKED) $Ctrl09=GuiCtrlCreateCheckbox("Remove Windows Messenger", 5, 280, 160, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $Ctrl10=GuiCtrlCreateCheckbox("Disable Print Balloon Notification", 5, 300, 185, 20) GuiCtrlSetState(-1, $GUI_CHECKED) Func StartInstall() If GUICtrlRead($Ctrl01,$GUI_CHECKED) Then MsgBox(0,"","Disable Automatic Updates Checked") EndIf If GUICtrlRead($Ctrl02,$GUI_CHECKED) Then MsgBox(0,"","Disable Firewall Checked") EndIf EndFunc Func TestMessage() MsgBox(0,"","Testing Starting Install") EndFunc Func ExitButton() ;Note: at this point @GUI_CTRLID would equal $okbutton GUISetOnEvent($GUI_EVENT_CLOSE,$main1) EndFunc ;GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd Func SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Exit EndSelect EndFunc What is happening, is I am creating a GUI with checkboxes, I want to be able to check certain things, and the have something run, like the If statement, to see if it is checked or not, if it is checked, I want it to message box that it is, if it isn't checked, I want it to do nothing. The problem is, even the items that I uncheck in the GUI are still messaging that they are checked. Can someone please assist me with this??? Thanks! Edited September 22, 2006 by dufran3
Ruud0209 Posted September 22, 2006 Posted September 22, 2006 Hi, i am not sure but I think the error might be in this bit : Func StartInstall() If GUICtrlRead($Ctrl01,$GUI_CHECKED) Then MsgBox(0,"","Disable Automatic Updates Checked") EndIf If GUICtrlRead($Ctrl02,$GUI_CHECKED) Then MsgBox(0,"","Disable Firewall Checked") EndIf EndFunc oÝ÷ Ù:ç$iÈ^rFèÄ(ºWn±æ®¶s`¢buT7G&Å&VBb33c´7G&ÃÒFVâ²26V6¶VBÂBÒVæ6V6¶V@¢Fõ÷F2¢VÇ6P¢FõöFöÖWFævVÇ6R¢VæF` You can always put in a MsgBox(0,"value is:",GUICtrlRead($Ctrl02)) to get actualy see what is returned... a short look at the help file on the GUICtrlRead command also tells me your 2nd parmater is probably invalid. For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.Hope this helps...
CWorks Posted September 23, 2006 Posted September 23, 2006 (edited) don't put your while loop inside a function Edited September 23, 2006 by CWorks
Moderators SmOke_N Posted September 23, 2006 Moderators Posted September 23, 2006 don't put your while loop inside a functionIt's not in a function...However:OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
CWorks Posted September 23, 2006 Posted September 23, 2006 yeah it's not a while loop either after taking anther look i'm just use to doing it like this smal snip While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Cancel ExitLoop Case $msg = $add _GUICtrlComboResetContent($DSCombo) _GUICtrlComboAddString($DSCombo,"scrnsave.scr") CDSOURCE() ;_GUICtrlComboSetCurSel($DSCombo,$default) $ret = _GUICtrlListGetSelItemsText ($listbox) If (Not IsArray($ret)) Then ;;; ;MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItemsText") Else For $i = 1 To $ret[0] _GUICtrlComboAddString($DSCombo,$ret[$i]) Next EndIf Case $msg = $UsePass If GUICtrlRead($UsePass) = $GUI_CHECKED Then GUICtrlSetState($RC, $GUI_ENABLE) GUICtrlSetState($MD, $GUI_ENABLE) GUICtrlSetState($SHA, $GUI_ENABLE) GUICtrlSetState($Passinput, $GUI_ENABLE) Else GUICtrlSetState($RC, $GUI_DISABLE) GUICtrlSetState($RC, $GUI_CHECKED) GUICtrlSetState($MD, $GUI_DISABLE) GUICtrlSetState($SHA, $GUI_DISABLE) GUICtrlSetState($Passinput, $GUI_DISABLE) EndIf
dufran3 Posted September 25, 2006 Author Posted September 25, 2006 Thanks for you help, I didn't realize that the control id changed when the item was checked as apposed to unchecked. That helped me out a great deal!!
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