Moist Posted October 9, 2018 Share Posted October 9, 2018 Hello guys, I looked everywhere but could not find exacly what was looking for. I want to have a window with a single button and 2 checkboxes. When the user presses the button, the script detect which checkboxes are pressed and will act accordingly. I am having problems creating the Switch and If Statements. Also, I want one of the checkboxes to be pressed be default, and the user can deactivate them if he desires. Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc $Form=GUICreate(... $Button=GUICtrlCreateButton(... $Checkbox1 = GUICtrlCreateCheckbox(... $Check1 = GUICtrlRead($Checkbox1) $Checkbox2 = GUICtrlCreateCheckbox(... GUICtrlSetState(-1, $GUI_CHECKED) $Check2 = GUICtrlRead($Checkbox2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 If _IsChecked($Checkbox1) AND _IsChecked($Checkbox2) Then MsgBox("", "1 and 2 Checked", "")) Sleep(1000) Exit EndIf If _IsChecked($Checkbox1) AND NOT _IsChecked($Checkbox2) Then MsgBox("", "1 Checked", "")) Sleep(1000) Exit EndIf If NOT _IsChecked($Checkbox1) AND _IsChecked($Checkbox2) Then MsgBox("", 2 Checked", "")) Sleep(1000) Exit EndIf If NOT _IsChecked($Checkbox1) AND NOT _IsChecked($Checkbox2) Then MsgBox("", "0 Checked", "")) Sleep(1000) Exit EndIf EndSwitch WEnd Can someone help me? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 9, 2018 Share Posted October 9, 2018 (edited) @Moist You can use the Select statement to do what you are trying to do expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 161, 112, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") Global $chkCheckbox1 = GUICtrlCreateCheckbox("First Checkbox", 16, 15, 113, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $chkCheckbox2 = GUICtrlCreateCheckbox("Second Checkbox", 16, 39, 129, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $btnButton1 = GUICtrlCreateButton("Button", 43, 71, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetOnEvent(-1, "ButtonPress") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc Func ButtonPress() Select Case _IsChecked($chkCheckbox1) And _IsChecked($chkCheckbox2) ConsoleWrite("Both Checkboxes are selected." & @CRLF) Case _IsChecked($chkCheckbox1) ConsoleWrite("Checkbox1 is selected." & @CRLF) Case _IsChecked($chkCheckbox2) ConsoleWrite("Checkbox2 is selected." & @CRLF) Case Else ConsoleWrite("No checkboxes selected." & @CRLF) EndSelect EndFunc Edited October 9, 2018 by FrancescoDiMuro pixelsearch 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moist Posted October 9, 2018 Author Share Posted October 9, 2018 48 minutes ago, FrancescoDiMuro said: @Moist You can use the Select statement to do what you are trying to do expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 161, 112, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") Global $chkCheckbox1 = GUICtrlCreateCheckbox("First Checkbox", 16, 15, 113, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $chkCheckbox2 = GUICtrlCreateCheckbox("Second Checkbox", 16, 39, 129, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $btnButton1 = GUICtrlCreateButton("Button", 43, 71, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetOnEvent(-1, "ButtonPress") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc Func ButtonPress() Select Case _IsChecked($chkCheckbox1) And _IsChecked($chkCheckbox2) ConsoleWrite("Both Checkboxes are selected." & @CRLF) Case _IsChecked($chkCheckbox1) ConsoleWrite("Checkbox1 is selected." & @CRLF) Case _IsChecked($chkCheckbox2) ConsoleWrite("Checkbox2 is selected." & @CRLF) Case Else ConsoleWrite("No checkboxes selected." & @CRLF) EndSelect EndFunc Thanks, I got the checkboxes working as intended. However, I can't close the window. I have created another button to EXIT but it doesn't work. I used GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") and GUISetOnEvent(-1, "ExitApplication") right after creating the EXIT button but with no luck. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 9, 2018 Share Posted October 9, 2018 @Moist GUISetOnEvent() is to set a function to run when an event is fired from a GUI; GUICtrlSetOnEvent() is to set a function to run when a control fire some events ( a click, for example ). So, use: GUICtrlSetOnEvent($btnExitButton, "ExitApplication") ; For a Control GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") ; For the GUI Moist 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moist Posted October 9, 2018 Author Share Posted October 9, 2018 @FrancescoDiMuro Thank you so much. Everything works great. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 9, 2018 Share Posted October 9, 2018 Happy to have helped Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moist Posted October 9, 2018 Author Share Posted October 9, 2018 55 minutes ago, FrancescoDiMuro said: Happy to have helped I have another question, though. When I use the Select function can my script only run one "Case"? Because I have, in fact, 5 checkboxes and I didn't want to make cases for all possible combinations. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 9, 2018 Share Posted October 9, 2018 @Moist I think not, since, if you need to do some combinations with your checkboxes (i.e.: checking 1st and 3rd checkbox will run a function, checking only 1st will run another function ), you have to separate them logically. Post your script and let us see if we can help you more Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moist Posted October 9, 2018 Author Share Posted October 9, 2018 @FrancescoDiMuro Well, if it's not possible, it's okay. I'll just create some functions that repeat in multiple cases and call them. Thanks Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 9, 2018 Share Posted October 9, 2018 @Moist As I said, post your script ( if you want ), so we can see how we can help you Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
spudw2k Posted October 10, 2018 Share Posted October 10, 2018 You could use an array. Here's one example: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $aCheckbox[2] #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 161, 112, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $aCheckbox[0] = GUICtrlCreateCheckbox("First Checkbox", 16, 15, 113, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") $aCheckbox[1] = GUICtrlCreateCheckbox("Second Checkbox", 16, 39, 129, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $btnButton1 = GUICtrlCreateButton("Button", 43, 71, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetOnEvent(-1, "ButtonPress") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc Func ButtonPress() For $iCheckbox = 0 to UBound($aCheckbox)-1 If _IsChecked($aCheckbox[$iCheckbox]) Then ConsoleWrite("$aCheckbox[" & $iCheckbox & "] is selected." & @CRLF) Else ConsoleWrite("$aCheckbox[" & $iCheckbox & "] is NOT selected." & @CRLF) EndIf Next EndFunc If you wanted to get fancy, you could keep track of the checked boxes as they are checked and not have to enumerate through all of them later. FrancescoDiMuro and Moist 2 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
caramen Posted November 15, 2018 Share Posted November 15, 2018 (edited) On 09/10/2018 at 1:04 PM, FrancescoDiMuro said: GUISetOnEvent() is to set a function to run when an event is fired from a GUI; GUICtrlSetOnEvent() is to set a function to run when a control fire some events ( a click, for example ). So, use: GUICtrlSetOnEvent($btnExitButton, "ExitApplication") ; For a Control GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") ; For the GUI @FrancescoDiMuro This mean this technic is dodging the fact that you do nothing if you are in a while ? Well just so you both know it... HotKeySet also doging it. But i would like to know about GUICtrlSetOnEvent Edited November 15, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted November 15, 2018 Share Posted November 15, 2018 (edited) @caramen Basically, GUICtrlSetOnEvent() is used when you don't want to continuousely see if there is an event (captured by GUIGetMsg()). Other events, like double click or any other event that is not "captured" from the GUICtrlSetOnEvent(), has to br captured from a WM_* handler Edited November 15, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
caramen Posted November 16, 2018 Share Posted November 16, 2018 (edited) 11 hours ago, FrancescoDiMuro said: @caramen Basically, GUICtrlSetOnEvent() is used when you don't want to continuousely see if there is an event (captured by GUIGetMsg()). Other events, like double click or any other event that is not "captured" from the GUICtrlSetOnEvent(), has to br captured from a WM_* handler Ok i got that. But you dont said me. Is it réacting as a hotkeyset ? I mean if you are actually inside a sleep. Does it register évent and do them directly instead of waiting the end of the sleep ? Edited November 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki 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