autoitash Posted April 15, 2011 Share Posted April 15, 2011 (edited) I am trying to check if mutliple checkboxes are checked. Can someone please help me? Here is my code. Thanks! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <GUIScrollBars_Ex.au3> Func Selectapps() $Count = 0 $Distance = 10 GUICreate("Testing checkbox", 500, 550) While $Count < $appIdCount $temp = $AppIdProc[$Count][0] $AppCheckbox = GUICtrlCreateCheckbox($temp, 20, $Distance) $Count = $Count + 1 $distance = $Distance + 20 WEnd $NextButton = GUICtrlCreateButton("Next", 350, 475, 100, 50) ;_GUIScrollbars_Generate($AppsListGUI, 600, 600) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc Edited April 15, 2011 by autoitash Link to comment Share on other sites More sharing options...
BrewManNH Posted April 15, 2011 Share Posted April 15, 2011 Here's your code snippet modified so that you can see how it can be done. Use an array to hold all of the check box handles, and then loop through the array to see which are checked and which aren't. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> ;~ #include <GUIScrollBars_Ex.au3> Global $appIdCount = 5 Global $AppCheckbox[$appIdCount] Global $AppIdProc[$appIdCount][2] = [["Test1", 1],["Test2", 2],["Test3", 3],["Test4", 4],["Test5", 5]] Selectapps() Func Selectapps() $Count = 0 $Distance = 10 GUICreate("Testing checkbox", 500, 550) While $Count < $appIdCount $temp = $AppIdProc[$Count][0] $AppCheckbox[$Count] = GUICtrlCreateCheckbox($temp, 20, $Distance + ($Count * 20)) $Count = $Count + 1 ;~ $Distance = $Distance + 20 WEnd $NextButton = GUICtrlCreateButton("Next", 350, 475, 100, 50) ;_GUIScrollbars_Generate($AppsListGUI, 600, 600) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $NextButton For $I = 0 To $appIdCount - 1 If GUICtrlRead($AppCheckbox[$I]) = $GUI_CHECKED Then ConsoleWrite("!Check box #" & $I & " is checked" & @CRLF) Else ConsoleWrite(">Check box #" & $I & " is unchecked" & @CRLF) EndIf Next EndSwitch WEnd EndFunc ;==>Selectapps If you have any questions, please ask. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
autoitash Posted April 18, 2011 Author Share Posted April 18, 2011 Here's your code snippet modified so that you can see how it can be done. Use an array to hold all of the check box handles, and then loop through the array to see which are checked and which aren't. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> ;~ #include <GUIScrollBars_Ex.au3> Global $appIdCount = 5 Global $AppCheckbox[$appIdCount] Global $AppIdProc[$appIdCount][2] = [["Test1", 1],["Test2", 2],["Test3", 3],["Test4", 4],["Test5", 5]] Selectapps() Func Selectapps() $Count = 0 $Distance = 10 GUICreate("Testing checkbox", 500, 550) While $Count < $appIdCount $temp = $AppIdProc[$Count][0] $AppCheckbox[$Count] = GUICtrlCreateCheckbox($temp, 20, $Distance + ($Count * 20)) $Count = $Count + 1 ;~ $Distance = $Distance + 20 WEnd $NextButton = GUICtrlCreateButton("Next", 350, 475, 100, 50) ;_GUIScrollbars_Generate($AppsListGUI, 600, 600) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $NextButton For $I = 0 To $appIdCount - 1 If GUICtrlRead($AppCheckbox[$I]) = $GUI_CHECKED Then ConsoleWrite("!Check box #" & $I & " is checked" & @CRLF) Else ConsoleWrite(">Check box #" & $I & " is unchecked" & @CRLF) EndIf Next EndSwitch WEnd EndFunc ;==>Selectapps If you have any questions, please ask. Link to comment Share on other sites More sharing options...
UEZ Posted April 19, 2011 Share Posted April 19, 2011 (edited) Here another method: expandcollapse popup;coded by UEZ 2011 #include <GUIConstantsEx.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Checkbox Test", 368, 169) Global $aCheckbox[17][2] $aCheckbox[0][0] = 16 $aCheckbox[1][0] = GUICtrlCreateCheckbox("Checkbox1", 8, 8, 97, 17) $aCheckbox[2][0] = GUICtrlCreateCheckbox("Checkbox2", 8, 24, 97, 17) $aCheckbox[3][0] = GUICtrlCreateCheckbox("Checkbox3", 8, 45, 97, 17) $aCheckbox[4][0] = GUICtrlCreateCheckbox("Checkbox4", 8, 61, 97, 17) $aCheckbox[5][0] = GUICtrlCreateCheckbox("Checkbox5", 8, 85, 97, 17) $aCheckbox[6][0] = GUICtrlCreateCheckbox("Checkbox6", 8, 101, 97, 17) $aCheckbox[7][0] = GUICtrlCreateCheckbox("Checkbox7", 8, 122, 97, 17) $aCheckbox[8][0] = GUICtrlCreateCheckbox("Checkbox8", 8, 138, 97, 17) $aCheckbox[9][0] = GUICtrlCreateCheckbox("Checkbox9", 128, 9, 97, 17) $aCheckbox[10][0] = GUICtrlCreateCheckbox("Checkbox10", 128, 25, 97, 17) $aCheckbox[11][0] = GUICtrlCreateCheckbox("Checkbox11", 128, 46, 97, 17) $aCheckbox[12][0] = GUICtrlCreateCheckbox("Checkbox12", 128, 62, 97, 17) $aCheckbox[13][0] = GUICtrlCreateCheckbox("Checkbox13", 128, 86, 97, 17) $aCheckbox[14][0] = GUICtrlCreateCheckbox("Checkbox14", 128, 102, 97, 17) $aCheckbox[15][0] = GUICtrlCreateCheckbox("Checkbox15", 128, 123, 97, 17) $aCheckbox[16][0] = GUICtrlCreateCheckbox("Checkbox16", 128, 139, 97, 17) $Button = GUICtrlCreateButton("Go", 232, 128, 75, 25) Enum $idAll = 1000, $idNone $hQMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hQMenu, 0, "Select all", $idAll) _GUICtrlMenu_InsertMenuItem($hQMenu, 1, "Select none", $idNone) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) AdlibRegister("Checkbox_Check", 200) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE AdlibUnRegister("Checkbox_Check") GUIRegisterMsg($WM_COMMAND, "") GUIRegisterMsg($WM_CONTEXTMENU, "") Exit Case $Button $checked = "" For $k = 1 To $aCheckbox[0][0] If $aCheckbox[$k][1] Then $checked &= $k & ", " Next MsgBox(0, "Information", "Following checkboxes are checked: " & @CRLF & @CRLF & StringTrimRight($checked, 2)) EndSwitch WEnd Func Checkbox_Check() Local $j, $add For $j = 1 To $aCheckbox[0][0] $aCheckbox[$j][1] = BitAND(GUICtrlRead($aCheckbox[$j][0]), $GUI_CHECKED) $add += $aCheckbox[$j][1] Next If $add Then If Not BitAND(GUICtrlGetState($Button), $GUI_ENABLE) Then GUICtrlSetState($Button, $GUI_ENABLE) Else If Not BitAND(GUICtrlGetState($Button), $GUI_DISABLE) Then GUICtrlSetState($Button, $GUI_DISABLE) EndIf EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $l Switch $wParam Case $idAll For $l = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$l][0], $GUI_CHECKED) Next Case $idNone For $l = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$l][0], $GUI_UNCHECKED) Next EndSwitch Return "GUI_RUNDEFMSG" EndFunc Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam _GUICtrlMenu_TrackPopupMenu ($hQMenu, $hGUI) Return True EndFunc or expandcollapse popup;coded by UEZ 2011 #include <GUIConstantsEx.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Checkbox Test", 368, 169) Global $aCheckbox[17][2] $aCheckbox[0][0] = 16 $aCheckbox[1][0] = GUICtrlCreateCheckbox("Checkbox1", 8, 8, 97, 17) $aCheckbox[2][0] = GUICtrlCreateCheckbox("Checkbox2", 8, 24, 97, 17) $aCheckbox[3][0] = GUICtrlCreateCheckbox("Checkbox3", 8, 45, 97, 17) $aCheckbox[4][0] = GUICtrlCreateCheckbox("Checkbox4", 8, 61, 97, 17) $aCheckbox[5][0] = GUICtrlCreateCheckbox("Checkbox5", 8, 85, 97, 17) $aCheckbox[6][0] = GUICtrlCreateCheckbox("Checkbox6", 8, 101, 97, 17) $aCheckbox[7][0] = GUICtrlCreateCheckbox("Checkbox7", 8, 122, 97, 17) $aCheckbox[8][0] = GUICtrlCreateCheckbox("Checkbox8", 8, 138, 97, 17) $aCheckbox[9][0] = GUICtrlCreateCheckbox("Checkbox9", 128, 9, 97, 17) $aCheckbox[10][0] = GUICtrlCreateCheckbox("Checkbox10", 128, 25, 97, 17) $aCheckbox[11][0] = GUICtrlCreateCheckbox("Checkbox11", 128, 46, 97, 17) $aCheckbox[12][0] = GUICtrlCreateCheckbox("Checkbox12", 128, 62, 97, 17) $aCheckbox[13][0] = GUICtrlCreateCheckbox("Checkbox13", 128, 86, 97, 17) $aCheckbox[14][0] = GUICtrlCreateCheckbox("Checkbox14", 128, 102, 97, 17) $aCheckbox[15][0] = GUICtrlCreateCheckbox("Checkbox15", 128, 123, 97, 17) $aCheckbox[16][0] = GUICtrlCreateCheckbox("Checkbox16", 128, 139, 97, 17) For $i = 1 To $aCheckbox[0][0] GUICtrlSetOnEvent($aCheckbox[$i][0], "Checkbox_Check") Next $Button = GUICtrlCreateButton("Go", 232, 128, 75, 25) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Enum $idAll = 1000, $idNone $hQMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hQMenu, 0, "Select all", $idAll) _GUICtrlMenu_InsertMenuItem($hQMenu, 1, "Select none", $idNone) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While Sleep(1000) WEnd Func _Exit() GUIRegisterMsg($WM_COMMAND, "") GUIRegisterMsg($WM_CONTEXTMENU, "") GUIDelete($hGUI) Exit EndFunc Func Button() $checked = "" For $k = 1 To $aCheckbox[0][0] If $aCheckbox[$k][1] Then $checked &= $k & ", " Next MsgBox(0, "Information", "Following checkboxes are checked: " & @CRLF & @CRLF & StringTrimRight($checked, 2)) EndFunc Func Checkbox_Check() Local $j, $add For $j = 1 To $aCheckbox[0][0] $aCheckbox[$j][1] = BitAND(GUICtrlRead($aCheckbox[$j][0]), $GUI_CHECKED) $add += $aCheckbox[$j][1] Next If $add Then If Not BitAND(GUICtrlGetState($Button), $GUI_ENABLE) Then GUICtrlSetState($Button, $GUI_ENABLE) Else If Not BitAND(GUICtrlGetState($Button), $GUI_DISABLE) Then GUICtrlSetState($Button, $GUI_DISABLE) EndIf EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $l Switch $wParam Case $idAll For $l = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$l][0], $GUI_CHECKED) Next Checkbox_Check() Case $idNone For $l = 1 To $aCheckbox[0][0] GUICtrlSetState($aCheckbox[$l][0], $GUI_UNCHECKED) Next Checkbox_Check() EndSwitch Return "GUI_RUNDEFMSG" EndFunc Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam _GUICtrlMenu_TrackPopupMenu ($hQMenu, $hGUI) Return True EndFunc Br, UEZ Edited April 19, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
autoitash Posted April 26, 2011 Author Share Posted April 26, 2011 Here's your code snippet modified so that you can see how it can be done. Use an array to hold all of the check box handles, and then loop through the array to see which are checked and which aren't. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> ;~ #include <GUIScrollBars_Ex.au3> Global $appIdCount = 5 Global $AppCheckbox[$appIdCount] Global $AppIdProc[$appIdCount][2] = [["Test1", 1],["Test2", 2],["Test3", 3],["Test4", 4],["Test5", 5]] Selectapps() Func Selectapps() $Count = 0 $Distance = 10 GUICreate("Testing checkbox", 500, 550) While $Count < $appIdCount $temp = $AppIdProc[$Count][0] $AppCheckbox[$Count] = GUICtrlCreateCheckbox($temp, 20, $Distance + ($Count * 20)) $Count = $Count + 1 ;~ $Distance = $Distance + 20 WEnd $NextButton = GUICtrlCreateButton("Next", 350, 475, 100, 50) ;_GUIScrollbars_Generate($AppsListGUI, 600, 600) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $NextButton For $I = 0 To $appIdCount - 1 If GUICtrlRead($AppCheckbox[$I]) = $GUI_CHECKED Then ConsoleWrite("!Check box #" & $I & " is checked" & @CRLF) Else ConsoleWrite(">Check box #" & $I & " is unchecked" & @CRLF) EndIf Next EndSwitch WEnd EndFunc ;==>Selectapps If you have any questions, please ask. Link to comment Share on other sites More sharing options...
autoitash Posted April 26, 2011 Author Share Posted April 26, 2011 Thanks BrewManNH, it worked just like I wanted to. Thanks so much. Link to comment Share on other sites More sharing options...
Damein Posted April 26, 2011 Share Posted April 26, 2011 I know you already had your question answered, but I figured I'd post this one up too if anyone else comes by this: #include <GUIConstantsEx.au3> #CS In this script we will learn how to create multiple checkboxes, and then use a button to determine which are checked or unchecked. #CE GuiCreate("GUI Tutorial: CheckBox 2",280,60) ; Create the GUI to display $CheckBox1 = GuiCtrlCreateCheckBox("Checkbox 1", 15,10) ; Create the GuiCtrl CheckBox, assign var CheckBox1 to it. $CheckBox2 = GuiCtrlCreateCheckBox("Checkbox 2", 190,10) ; Create the GuiCtrl CheckBox2, assign var CheckBox2 to it. $SubmitButton = GuiCtrlCreateButton("Submit", 115, 35) ; Create the GuiCtrl SubmitButton, assign var SubmitButton to it GuiSetState() ; Set GUI state to show to display the GUI While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Tell the program to exit if the command from the GUI is infact the close button Case $GuiMsg = $SubmitButton ; A "If" statement for the command from the GUI, in this case the submit button on the GUI $CheckBoxStatus1 = GuiCtrlRead($CheckBox1) ; Read the status for CheckBox1 $CheckBoxStatus2 = GuiCtrlRead($CheckBox2) ; Read the status for CheckBox2 If $CheckBoxStatus1 = $GUI_UNCHECKED Then ; If CheckBox1 was checked and clicked, then display a MsgBox to show it was unchecked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 1 is unchecked") ; Display this MsgBox if CheckBox1 is unchecked ElseIf $CheckBoxStatus1 = $GUI_CHECKED Then ; If CheckBox1 was unchecked and clicked, then display a MsgBox to show it was checked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 1 is checked") ; Display this MsgBox if CheckBox1 is checked EndIf ; End If/ElseIf statement for CheckBox1 If $CheckBoxStatus2 = $GUI_UNCHECKED Then ; If CheckBox2 was checked and clicked, then display a MsgBox to show it was unchecked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 2 is unchecked") ; Display this MsgBox if CheckBox2 is unchecked ElseIf $CheckBoxStatus2 = $GUI_CHECKED Then ; If CheckBox2 was unchecked and clicked, then display a MsgBox to show it was checked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 2 is checked") ; Display this MsgBox if CheckBox2 is checked EndIf ; End If/ElseIf statement for CheckBox1 EndSelect ; End the select statement WEnd ; End the while statement antonioj84 1 Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
FMS Posted April 28, 2011 Share Posted April 28, 2011 I know you already had your question answered, but I figured I'd post this one up too if anyone else comes by this:THNX damein this is realy helpfull for me, escpacialy now that i'm learning to work whit autoit...There shout be more help scripts like this for me it helps a lot to C what happens in each line and why each line is there where it is ....many thnx for this as finishing touch god created the dutch Link to comment Share on other sites More sharing options...
Damein Posted May 8, 2011 Share Posted May 8, 2011 (edited) Your welcome. I don't know if you are interested in GUI's, but I wrote some more sample scripts like this for GUI controls. If your interested, here they are. Button Example using GuiGetMsg: #include <GUIConstantsEx.au3> #CS In this script we will learn how to create multiple button controls and how to detect which button we pressed. #CE Global $OkButton, $SubmitButton _CreateGui() ; Tell the script to run the function _CreateGui Func _CreateGui() ; Start the called function _CreateGui GuiCreate("GUI Tutorial: Buttons 1",280,60) ; Create the GUI to display $OkButton = GuiCtrlCreateButton("Ok", 15,20) ; Create the button control for the ok button $SubmitButton = GuiCtrlCreateButton("Submit",220,20) ; Create the button control for the submit button GuiSetState() ; Set GUI state to show to display the GUI EndFunc ; Close the _CreateGui Function While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Tell the program to exit if the command from the GUI is infact the close button Case $GuiMsg = $OkButton ; A "If" statement for the command from the GUI, in this case the ok button on the GUI MsgBox(0, "GUI Tutorial: Buttons 1", "You pressed the ok button.") ; Display the MsgBox if the command from the GUI if the ok button was pressed. Case $GuiMsg = $SubmitButton ; A "If" statement for the command from the GUI, in this case the submit button on the GUI MsgBox(0, "GUI Tutorial: Buttons 1", "You pressed the submit button.") ; Display the MsgBox if the command from the GUI if the submit button was pressed. EndSelect ; End the select statement WEnd ; End the while statement Button Example using GuiOnEventMode: #include <GUIConstantsEx.au3> #CS In this script we will learn how to use GuiOnEventMode instead of GuiMsg to detect which button we pressed and to call upon the commands we attach to the buttons. #CE Opt("GUIOnEventMode", 1) ; Enable OnEventMode GuiCreate("GUI Tutorial: Buttons 2",280,60) ; Create the GUI to display GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked") ; Set an event to occur if the user presses the close button on the GUI $OkButton = GuiCtrlCreateButton("Ok", 15,20) ; Create the button control for the ok button GUICtrlSetOnEvent($OkButton, "OkButton") ; Set an event to occur if the user presses the ok button on the GUI $SubmitButton = GuiCtrlCreateButton("Submit",220,20) ; Create the button control for the submit button GUICtrlSetOnEvent($SubmitButton, "SubmitButton") ; Set an event to occur if the user presses the submit button on the GUI GuiSetState() ; Set GUI state to show to display the GUI Func CloseClicked() ; The event to happen if the user presses the close button Exit ; Close the program if the close button was closed EndFunc ; End the function Func OkButton() ; The event to happen if the user presses the ok button MsgBox(0, "GUI Tutorial: Buttons 2", "You pressed the ok button.") ; Display the MsgBox if the command from the GuiCtrlSetOnEvent was called on, in this case the ok button. EndFunc ; End the functionFunc OkButton() ; The event to happen if the user presses the ok button Func SubmitButton() ; The event to happen if the user presses the submit button MsgBox(0, "GUI Tutorial: Buttons 2", "You pressed the submit button.") ; Display the MsgBox if the command from the GuiCtrlSetOnEvent was called on, in this case the submit button. EndFunc ; End the function While 1 ; Start a while statement Sleep(10) ; Idle around, so the script stays open WEnd ; End the while statement Combo Box Example: #include <GUIConstantsEx.au3> #CS In this script we will learn how to create, add and control a combo box (Drop down list). #CE GuiCreate("GUI Tutorial: ComboBox 1",280,60) ; Create the GUI to display $ComboBox = GUICtrlCreateCombo("I am a drop-down menu", 10, 10) ; Create combo box (Better known as drop-down menu), set first item in list as "I am a drop-down menu" GUICtrlSetData(-1, "Option A") ; Set a new item in the drop-down menu, by using -1 as the control ID, since it was the last one used. GUICtrlSetData($ComboBox, "Option B") ; Set a new item in the drop-down menu, but this time use the var ComboBox instead of -1, either will work if only 1 control has been created since this command was processed. ; You may also combine them by doing: GuiCtrlSetData(-1, "Option A|Option B") or GuiCtrlSetData($ComboBox, "Option A|Option B") IE: GuiCtrlSetData(-1,"Option A|Option B") GuiSetState() ; Set GUI state to show to display the GUI While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Tell the program to exit if the command from the GUI is infact the close button Case $GuiMsg = $ComboBox ; A "If" statement for the command from the GUI, in this case the selection of an item from the drop-down menu $ComboBoxChoice = GuiCtrlRead($ComboBox,1) ; Read the status for the Combobox and assign var ComboBoxChoice to it If $ComboBoxChoice = "Option A" Then ; An If statement to tell the program what to do if Option A was selected MsgBox(0, "GUI Tutorial: ComboBox 1", "Option A has been selected") ; Display the MsgBox if Option A was selected ElseIf $ComboBoxChoice = "Option B" Then ; An If statement to tell the program what to do if Option B was selected MsgBox(0, "GUI Tutorial: ComboBox 1", "Option B has been selected") ; Display the MsgBox if Option B was selected EndIf ; End If/ElseIf statement EndSelect ; End the select statement WEnd ; End the while statement Context Example: #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #CS In this script we will learn how to create, add to and create sub menu context menus. #CE Global $HelpItem, $SubMenuItem _CreateGui() ; Tell the script to run the function: _CreateGui() Func _CreateGui() ; Begin the function _CreateGui() GuiCreate("GUI Tutorial: Context Menu",300,200) ; Create the Gui $ContextMenu = GuiCtrlCreateContextMenu() ; Create a context menu and assign it to var ContextMenu. To create the context menu control do not enclose anything in the () $HelpItem = GuiCtrlCreateMenuItem("Help", $ContextMenu) ; Create a menu item in the context menu labeled "Help" with the var HelpItem $SubMenu = GuiCtrlCreateMenu("SubMenu", $ContextMenu) ; Create a second menu inside the context menu. $SubMenuItem = GuiCtrlCreateMenuItem("SubMenu Help", $SubMenu) ; Create a second help item inside the sub menu of the context menu. GuiSetState() ; Display the GUI EndFunc ; End the function _CreateGui While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $HelpItem ; An "If" statement to tell the script what to do if the HelpItem var is called. MsgBox(0, "GUI Tutorial: Context Menu", "You pressed the 'Help' item in the main context menu") ; A MsgBox displaying that the HelpItem var was selected Case $GuiMsg = $SubMenuItem ; An "If" statement to tell the script what to do if the SubMenuItem var is called instead. MsgBox(0, "GUI Tutorial: Context Menu", "You pressed the 'Help' item in the sub context menu") ; A MsgBox displaying that the SubMenuItem var was selected Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Tell the program to exit if the command from the GUI is infact the close button EndSelect ; End the select statement WEnd ; End the while statement Edit Box example: #include <GUIConstantsEx.au3> #Include <EditConstants.au3> #CS In this script we will learn how to first create a plain edit box. #CE Global $Status _CreateGui() ; Tell the script to run the function: _CreateGui() Func _CreateGui() GuiCreate("GUI Tutorial: Edit Box",300,200) ; Create the Gui $EditBox1 = GUICtrlCreateEdit("", 30,20,230,150) ; Create an edit box and assign it to var EditBox1. No special properties. GuiSetState() ; Display the GUI EndFunc ; End the function _CreateGui While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI If $Status = 0 Then ; An if statement to determine if the first GUI or the second GUI was closed. _CreateGui2() ; Tell the program to go to the second GUI when the first one is closed. $Status = 1 ; Set status to 1 so next time you close a gui (The second one) the script will end ElseIf $Status = 1 Then ; If the status is indeed 1 then proceed Exit ; Close the script EndIf ; End the If statement EndSelect ; End the select statement WEnd ; End the while statement Func _CreateGui2() GuiCreate("GUI Tutorial: Edit Box 2",300,200) ; Create the Gui $EditBox2 = GUICtrlCreateEdit("", 30,20,230,150,$ES_MULTILINE) ; Create an edit box and assign it to var EditBox2. This time $ES_MULTILINE is used. If you notice in the first EditBox whenever you typed passed a line of text, it didn't wrap around. In this one, it will autowrap so you don't have to press enter. GuiSetState() ; Display the GUI EndFunc ; End the function _CreateGui Group Example: #include <GUIConstantsEx.au3> #CS In this script we will learn how to create groups. Groups can be used to inclose certain controls in order to maintain a nice look to your GUI. #CE _CreateGui() ; Tell the script to run the function: _CreateGui() Func _CreateGui() GuiCreate("GUI Tutorial: Group",300,200) ; Create the Gui GuiCtrlCreateGroup("Group 1", 0,0,150,195) ; Create a group control GuiCtrlCreateGroup("",-99,-99,1,1) ; Close the first group control GuiCtrlCreateGroup("Group 2", 160,0,135,195) ; Create a second group control GuiCtrlCreateGroup("",-99,-99,1,1) ; Close the second group control GuiSetState() ; Display the GUI EndFunc ; End the function _CreateGui While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Close the script EndSelect ; End the select statement WEnd ; End the while statement Edited May 8, 2011 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
FMS Posted May 9, 2011 Share Posted May 9, 2011 (edited) many thnx for these scripts..... once again i've downloaded them all en read them thurly thumbsup 4 Damein PS. maybe is it an idea to have 1 tread specialy for these kind of scripts because i'm thinking that i'm not the only one that wants to know all in's and outs of autoit from a starter point of vieuw an learns a lot from these kind of scripts.... Edit: Iff u got more , let them comming Edited May 9, 2011 by FMS as finishing touch god created the dutch Link to comment Share on other sites More sharing options...
antonioj84 Posted September 22, 2017 Share Posted September 22, 2017 On 4/26/2011 at 2:24 PM, Damein said: I know you already had your question answered, but I figured I'd post this one up too if anyone else comes by this: #include <GUIConstantsEx.au3> #CS In this script we will learn how to create multiple checkboxes, and then use a button to determine which are checked or unchecked. #CE GuiCreate("GUI Tutorial: CheckBox 2",280,60) ; Create the GUI to display $CheckBox1 = GuiCtrlCreateCheckBox("Checkbox 1", 15,10) ; Create the GuiCtrl CheckBox, assign var CheckBox1 to it. $CheckBox2 = GuiCtrlCreateCheckBox("Checkbox 2", 190,10) ; Create the GuiCtrl CheckBox2, assign var CheckBox2 to it. $SubmitButton = GuiCtrlCreateButton("Submit", 115, 35) ; Create the GuiCtrl SubmitButton, assign var SubmitButton to it GuiSetState() ; Set GUI state to show to display the GUI While 1 ; Start a while statement to capture the commands from the GUI $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI Select ; Begin a select statement Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI Exit ; Tell the program to exit if the command from the GUI is infact the close button Case $GuiMsg = $SubmitButton ; A "If" statement for the command from the GUI, in this case the submit button on the GUI $CheckBoxStatus1 = GuiCtrlRead($CheckBox1) ; Read the status for CheckBox1 $CheckBoxStatus2 = GuiCtrlRead($CheckBox2) ; Read the status for CheckBox2 If $CheckBoxStatus1 = $GUI_UNCHECKED Then ; If CheckBox1 was checked and clicked, then display a MsgBox to show it was unchecked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 1 is unchecked") ; Display this MsgBox if CheckBox1 is unchecked ElseIf $CheckBoxStatus1 = $GUI_CHECKED Then ; If CheckBox1 was unchecked and clicked, then display a MsgBox to show it was checked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 1 is checked") ; Display this MsgBox if CheckBox1 is checked EndIf ; End If/ElseIf statement for CheckBox1 If $CheckBoxStatus2 = $GUI_UNCHECKED Then ; If CheckBox2 was checked and clicked, then display a MsgBox to show it was unchecked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 2 is unchecked") ; Display this MsgBox if CheckBox2 is unchecked ElseIf $CheckBoxStatus2 = $GUI_CHECKED Then ; If CheckBox2 was unchecked and clicked, then display a MsgBox to show it was checked MsgBox(0, "GUI Tutorial: CheckBox 2", "Checkbox 2 is checked") ; Display this MsgBox if CheckBox2 is checked EndIf ; End If/ElseIf statement for CheckBox1 EndSelect ; End the select statement WEnd ; End the while statement Thanks for posting, that is exactly what I wanted !! 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