sanhen Posted December 28, 2008 Share Posted December 28, 2008 Once i press button start function... Press the button again to stop function ... I would like to ask how to achieve? expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) $Stop = 0 $hGUI=GUICreate ("test", 300,120,-1,-1) GUISetOnEvent($GUI_EVENT_CLOSE, "GuiMsg") $button1 = GUICtrlCreateCheckbox("test", 100, 20, 80, 25,$BS_PUSHLIKE) GUICtrlSetOnEvent($button1, "ControlMsg") GUISetState() While 1 Sleep(1000) Wend Func GuiMsg() Switch @GUI_CTRLID Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MINIMIZE guisetstate(@SW_MINIMIZE) EndSwitch EndFunc Func ControlMsg() If BitAND(GuiCtrlRead(@GUI_CtrlId), $GUI_CHECKED) Then GUICtrlSetData(@GUI_CtrlId,"11111") $Stop = 0 _test() Else GUICtrlSetData(@GUI_CtrlId,"22222") $Stop = 1 EndIf EndFunc Func _test() $i =0 Do $i+=1 GUICtrlSetData($button1,$i) Sleep(500) Until $Stop = 1 or $i=1000000 EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 28, 2008 Moderators Share Posted December 28, 2008 @sanhen, I believe that you cannot recall a function if it is already running. So if you call your _test() function from within the ControlMsg() function, you cannot "re"call the ControlMsg() function until it has executed. Therefore you need to place the call to _test() outside ControlMsg() to enable it to return. The following shows what I mean:expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) $Stop = 0 $hGUI=GUICreate ("test", 300,120,-1,-1) GUISetOnEvent($GUI_EVENT_CLOSE, "GuiMsg") $button1 = GUICtrlCreateCheckbox("test", 100, 20, 80, 25,$BS_PUSHLIKE) GUICtrlSetOnEvent($button1, "ControlMsg") $label1 = GUICtrlCreateLabel("", 100, 70, 80, 25) GUISetState() While 1 Sleep(100) If $Stop = 0 Then _test() Wend Func GuiMsg() Switch @GUI_CTRLID Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MINIMIZE guisetstate(@SW_MINIMIZE) EndSwitch EndFunc Func ControlMsg() If BitAND(GuiCtrlRead($button1), $GUI_CHECKED) = $GUI_CHECKED Then $Stop = 0 Else $Stop = 1 EndIf EndFunc Func _test() $i =0 Do $i+=1 GUICtrlSetData($button1, $i) Sleep(500) Until $Stop = 1 or $i=1000000 EndFunc Hope this helps, M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rasim Posted December 29, 2008 Share Posted December 29, 2008 @sanhenThis discussed many times:Easy method (not reliable, need a thick loop)expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("test", 300, 120, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "GuiMsg") $button1 = GUICtrlCreateCheckbox("test", 100, 20, 80, 25, $BS_PUSHLIKE) GUICtrlSetOnEvent($button1, "ControlMsg") GUISetState() While 1 Sleep(1000) WEnd Func GuiMsg() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MINIMIZE GUISetState(@SW_MINIMIZE) EndSwitch EndFunc ;==>GuiMsg Func ControlMsg() If BitAND(GUICtrlRead(@GUI_CtrlId), $GUI_CHECKED) Then GUICtrlSetData(@GUI_CtrlId, "11111") _test() Else GUICtrlSetData(@GUI_CtrlId, "22222") EndIf EndFunc ;==>ControlMsg Func _test() Local $iOld_EventMode = Opt("GUIOnEventMode", 0) Local $i = 0 While 1 If (GUIGetMsg() = $button1) Or ($i = 1000000) Then ExitLoop $i += 1 GUICtrlSetData($button1, $i) Sleep(300) WEnd GUICtrlSetData($button1, "22222") Opt("GUIOnEventMode", $iOld_EventMode) EndFunc ;==>_testoÝ÷ ØojwvgkzXnWºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ë]LÉÝÂÚ[ÛYH Ð]ÛÛÛÝ[Ë]LÉÝÂÚ[ÛYH ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÜ ][ÝÑÕRSÛ][[ÙI][ÝËJBÛØ[ ÌÍÔÝÜÌÍÚÕRHHÕRPÜX]J ][ÝÝÝ ][ÝËÌLLKLJBÕRTÙ]Û][ ÌÍÑÕRWÑUSÐÓÔÑK ][ÝÑÝZSÙÉ][ÝÊBÌÍØ]ÛHHÕRPÝÜX]PÚXÚØÞ ][ÝÝÝ ][ÝËLK ÌÍÐ×ÔTÒRÑJBÕRPÝÙ]Û][ ÌÍØ]ÛK ][ÝÐÛÛÛÙÉ][ÝÊBÕRTYÚÝÙÊ ÌÍÕÓWÐÓÓSPS ][Ý×ÕÓWÐÓÓSPS ][ÝÊBÕRTÙ]Ý]J BÚ[HBTÛY L BÑ[[ÈÕÓWÐÓÓSPS ÌÍÚÛ ÌÍÓÙË ÌÍÝÔ[K ÌÍÛ[JBSØØ[ ÌÍÛÛÛÛH]S ÌÍÝÔ[KBSØØ[ ÌÍÛÝYHH]ÚY ÌÍÝÔ[KMBBTÝÚ]Ú ÌÍÛÛÛÛBPØÙH ÌÍØ]ÛBBBTÝÚ]Ú ÌÍÛÝYBBBBPØÙH ÌÍÐÐÓPÒÑQBBBBRY]S ÕRPÝXY ÌÍÛÛÛÛ K ÌÍÑÕRWÐÒPÒÑQ H[BBBBBIÌÍÔÝÜHBBBBQ[ÙBBBBBBIÌÍÔÝÜHBBBBBQ[YBBQ[ÝÚ]ÚQ[ÝÚ]ÚBT] ÌÍÑÕRWÔSQTÑÂ[[ÈÏOIÝ×ÕÓWÐÓÓSPS[ÈÝZSÙÊ BTÝÚ]ÚÕRWÐÝYBPØÙH ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]BPØÙH ÌÍÑÕRWÑUSÓRSSRVBBBQÕRTÙ]Ý]JÕ×ÓRSSRVJBQ[ÝÚ]Ú[[ÈÏOIÝÑÝZSÙÂ[ÈÛÛÛÙÊ BRY]S ÕRPÝXY ÕRWÐÝY K ÌÍÑÕRWÐÒPÒÑQ H[BQÕRPÝÙ]]JÕRWÐÝY ][ÝÌLLLLI][ÝÊBBWÝÝ BQ[ÙBBQÕRPÝÙ]]JÕRWÐÝY ][ÝÌ][ÝÊBQ[Y[[ÈÏOIÝÐÛÛÛÙÂ[ÈÝÝ BSØØ[ ÌÍÚHHBUÚ[HBBRY ÌÍÔÝÜHJHÜ ÌÍÚHHL H[^]ÛÜBIÌÍÚH ÏHBBQÕRPÝÙ]]J ÌÍØ]ÛK ÌÍÚJBBTÛY Ì BUÑ[BNÉÌÍÔÝÜH[[ÈÏOIÝ×ÝÝ Link to comment Share on other sites More sharing options...
sanhen Posted December 29, 2008 Author Share Posted December 29, 2008 Thank you all very much help. 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