geasiki Posted January 26, 2009 Posted January 26, 2009 I've made some checkbox in an array and I wanted to know its status(check, unchecked) so I enabled GUICtrlOnEvent so if a checkbox is checked or unchecked it would go through a function and state its status. The problem I'm having is... since I've made just 'one' function that checks the status of the checkbox.. the function is not able to determine which checkbox it was called from.. Not sure if I made myself clear.. I'll write the code down.. $CheckBox[0] = GUICtrlCreateCheckbox("", 7, 48, 97, 17) GUICtrlSetOnEvent(-1, "_CheckStatus") $CheckBox[1] = GUICtrlCreateCheckbox("", 7, 71, 97, 17) GUICtrlSetOnEvent(-1, "_CheckStatus)") $CheckBox[2] = GUICtrlCreateCheckbox("", 7, 119, 97, 17) GUICtrlSetOnEvent(-1, "_CheckStatus") Func _CheckStatus() ; some function that will setstate, like $CheckBox[0] = Checked. EndFunc While 1 If $CheckBox[0] = Checked Then _DoThis() If $CheckBox[1] = UnChecked Then _DoThat() Do I have to make different functions for each of the "_CheckStatus" as in _CheckStatus1, 2, 3 ? or is there a way to pass arguments/variables into the "_CheckStatus".
FireFox Posted January 26, 2009 Posted January 26, 2009 @geasiki #Include <GuiConstants.au3> $ck = GuiCtrlCreateCheckBox() Func _Check() If $ck = $GUI_CHECKED then ; do stuff Else ; do another stuff EndIf EndFunc Cheers, FireFox.
JSThePatriot Posted January 26, 2009 Posted January 26, 2009 Here is my template script for OnEventMode GUI Scripts... expandcollapse popup;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;Program Name: Template - OnEventMode ;Description: Template for OnEventMode GUI scripts ;Filename: Template - OnEventMode.au3 ;Used With: ;Created by: Jarvis J Stubblefield (support "at" vortexrevolutions "dot" com) ;Created on: 06/20/2006 ;Modified on: ;Modified by: ;Version: 0.0.2 ;Copyright: Copyright (C) 2006 Vortex Revolutions. All Rights Reserved. ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Declare Variables ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;Window Variables Enum $ID_winHEIGHT, $ID_winWIDTH, $ID_winMAIN, $ID_winTITLE, $ID_winMAX Global $g_arrWin[$ID_winMAX] ;Control Variables Enum $ID_btnOPTIONS, $ID_btnHELP, $ID_btnEXIT, $ID_conMAX Global $g_arrCon[$ID_conMAX] ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Preprocessor ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ;Set GUI to ONEvent Mode. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** File Installations ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Registry Information ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Command Line Options ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #cs UNCOMMENT FOR COMMANDLINE! If $CmdLine[0] > 0 Then If StringRight($CmdLine[1], 4) = ".ext" Then _SomeFunc($CmdLine[1]) Else _ErrorMsg("Incorret file extension. Please try again.") _TerminateApp() EndIf EndIf #ce ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Define Variables ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $g_arrWin[$ID_winHEIGHT] = 300 $g_arrWin[$ID_winWIDTH] = 300 $g_arrWin[$ID_winTITLE] = "Template - OnEventMode" ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** GUI Creation ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;Main GUI Creation $g_arrWin[$ID_winMAIN] = GUICreate($g_arrWin[$ID_winTITLE], $g_arrWin[$ID_winWIDTH], $g_arrWin[$ID_winHEIGHT]) ;Main Options $g_arrCon[$ID_btnOPTIONS] = GUICtrlCreateButton("Options", 5, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20) ;Main Help $g_arrCon[$ID_btnHELP] = GUICtrlCreateButton("Help", 103, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20) ;Main Exit $g_arrCon[$ID_btnEXIT] = GUICtrlCreateButton("Exit", 201, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20) ;Disable Options and Help until added GUICtrlSetState($g_arrCon[$ID_btnOPTIONS], $GUI_DISABLE) GUICtrlSetState($g_arrCon[$ID_btnHELP], $GUI_DISABLE) ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** GUI Set Events ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;GUI Events Handled by _GUIEventHandler() GUICtrlSetOnEvent($g_arrCon[$ID_btnOPTIONS], "_GUIEventHandler") GUICtrlSetOnEvent($g_arrCon[$ID_btnEXIT], "_GUIEventHandler") GUICtrlSetOnEvent($g_arrCon[$ID_btnHELP], "_GUIEventHandler") ;System Events Handled by _SysEventHandler() GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $g_arrWin[$ID_winMAIN]) GUISetState(@SW_SHOW, $g_arrWin[$ID_winMAIN]) ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Main Program Loop ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Sleep(100) WEnd ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** GUI Event Functions ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Func _GUIEventHandler() Switch @GUI_CtrlId Case $g_arrCon[$ID_btnEXIT] _TerminateApp() Case $g_arrCon[$ID_btnOPTIONS] Case $g_arrCon[$ID_btnHELP] EndSwitch EndFunc Func _SysEventHandler() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE If @GUI_WinHandle <> $g_arrWin[$ID_winMAIN] Then _TerminateGUI(@GUI_WinHandle) Else _TerminateApp() EndIf Case $GUI_EVENT_MINIMIZE Case $GUI_EVENT_RESTORE Case $GUI_EVENT_MAXIMIZE Case $GUI_EVENT_PRIMARYDOWN Case $GUI_EVENT_PRIMARYUP Case $GUI_EVENT_SECONDARYDOWN Case $GUI_EVENT_SECONDARYUP Case $GUI_EVENT_MOUSEMOVE Case $GUI_EVENT_RESIZED Case $GUI_EVENT_DROPPED EndSwitch EndFunc ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;---*** Define Functions ***--- ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #region --- Internal Functions ;Displays an error message to the user, and optionally times out. Func _ErrorMsg($message, $time = 0) MsgBox(48 + 262144, "Error!", $message, $time) EndFunc ;Function to be used to terminate the application. (Clean up Application) Func _TerminateApp() Exit EndFunc ;This function is to be used with programs that have multiple GUI's and ;will optionally terminate application if called incorrectly on the main ;GUI. Func _TerminateGUI($gui_hWnd, $gui_title = "") If $gui_title = "" Then $gui_title = $g_arrWin[$ID_winTITLE] If $gui_hWnd = $hSome3rdLayerGUI Then ;Do 3rd Layer GUI stuff (for example look at RAS-NEW.au3) GUIDelete($gui_hWnd) Else GUIDelete($gui_hWnd) If $gui_hWnd = $g_arrWin[$ID_winMAIN] Then _TerminateApp() Else WinActivate($gui_title) EndIf EndIf EndFunc #endregion Internal Functions You would need to create a Case for each one of your CheckBoxes in _GUIEventHandler(), but then you could easily call your other function as follows... _CheckStatus($ctrlID) which would actually end up being _CheckStatus($g_arrCon[$CheckBox1]). I hope this helps some, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
andybiochem Posted January 26, 2009 Posted January 26, 2009 This is how I would do it: Opt("GUIOnEventMode", 1) GUICreate("",223,155) Global $aCheckboxArray[4] $aCheckboxArray[1] = GUICtrlCreateCheckbox("Checkbox1", 32, 24, 121, 17) GUICtrlSetOnEvent(-1,"_CheckStatus") $aCheckboxArray[2] = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 137, 17) GUICtrlSetOnEvent(-1,"_CheckStatus") $aCheckboxArray[3] = GUICtrlCreateCheckbox("Checkbox3", 32, 88, 145, 17) GUICtrlSetOnEvent(-1,"_CheckStatus") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func _CheckStatus() $state = "Checked" If GUICtrlRead(@GUI_CtrlId) = 4 Then $state = "Unchecked" Switch @GUI_CtrlId Case 3 MsgBox(0,"","Checkbox 1 clicked, state is " & $state) Case 4 MsgBox(0,"","Checkbox 2 clicked, state is " & $state) Case 5 MsgBox(0,"","Checkbox 3 clicked, state is " & $state) EndSwitch EndFunc - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
geasiki Posted January 26, 2009 Author Posted January 26, 2009 (edited) @andybiochem Exactly what I was looking for. @GUI_CtrlId Thanks~ But how would I be able to make "If...Then" loops in the main loop? While 1 If $state = "Checked" Then ~~ ; or something like Checkbox1 = "Checked' ?? Can't get it to work ㅜ.ㅜ If $state = ; for checkbox2 If $state = ; for checkbox3 @JSThePatriot I'll keep that in mind and use it when my script gets larger. Never thought of doing that. Thanks~ @FireFox Didn't know I could do that without the GUICtrlRead. Thanks~ Edited January 26, 2009 by geasiki
geasiki Posted January 26, 2009 Author Posted January 26, 2009 Uhm. Nvm I got it, I think.... Func _CheckStatus() $State = "ON" If GUICtrlRead(@GUI_CtrlId) = 4 Then $State = "OFF" Switch @GUI_CtrlId Case @GUI_CtrlId = $CheckBox[0] $Status[0] = $State Case @GUI_CtrlId = $CheckBox[1] $Status[1] = $State Case @GUI_CtrlId = $CheckBox[2] $Status[2] = $State EndSwitch EndFunc
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