abiteric Posted November 12, 2007 Share Posted November 12, 2007 we know the trayicon can pause the scripthow do it make the func on my gui button ?#include <GuiConstants.au3>GuiCreate("MyGUI", 257, 251,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))$Button_1 = GuiCtrlCreateButton("RUN", 50, 200, 70, 30)$Button_2 = GuiCtrlCreateButton("STOP", 140, 200, 70, 30)$Edit_3 = GuiCtrlCreateEdit("1", 30, 30, 90, 160,BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN) )GuiSetState()While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $s = 0 iii() Case $Button_2 $s = 1 MsgBox (0,"1","") Case Else ;;; EndSelectWEndExitfunc iii() for $i = 1 to 99999 Step 1 sleep (200) $s = stop($s) If stop($s) = 0 Then GUICtrlSetData (5,$i&@LF,$i) Else ExitLoop EndIf Next Return GUICtrlSetData (5,"STOP",$i)EndFuncfunc stop(Byref $s) if $s = 1 Then return 1 Else Return 0 EndIfEndFunc My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909 Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 12, 2007 Share Posted November 12, 2007 One method: #include <GuiConstants.au3> GUICreate("MyGUI", 257, 251, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Button_1 = GUICtrlCreateButton("RUN", 50, 200, 70, 30) $Edit_1 = GUICtrlCreateEdit("1", 30, 30, 90, 160, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 _ButtonHit() EndSwitch WEnd Func _ButtonHit() If GUICtrlRead($Button_1) = "Run" Then AdlibEnable("_Increment", 500) GUICtrlSetData($Button_1, "Stop") Else AdlibDisable() GUICtrlSetData($Button_1, "Run") EndIf EndFunc ;==>_ButtonHit Func _Increment() GUICtrlSetData($Edit_1, Number(GUICtrlRead($Edit_1)) + 1) EndFunc ;==>_Increment Another is to have a global flag, like $fRun. Your Start/Stop button only needs to toggle the run flag, and your function monitors the flag. The problem there is that you are using a message loop for the GUI. If you want your GUI to respond to button hits and also to be executing some other function, then you need to change over to Event Mode. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
abiteric Posted November 12, 2007 Author Share Posted November 12, 2007 (edited) very thanks for ur reply, but i need to stop a func(), and its a loopexpandcollapse popup#include < GuiConstants.au3 > GUICreate("MyGUI", 257, 251, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Button_1 = GUICtrlCreateButton("RUN", 50, 200, 70, 30) $Button_2 = GUICtrlCreateButton("STOP", 140, 200, 70, 30) $Edit_3 = GUICtrlCreateEdit("1", 30, 30, 90, 160, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $s = 0 iii() Case $Button_2 $s = 1 Case Else EndSelect WEnd Exit Func iii() For $i = 1 To 99999 Step 1 Sleep(200) $s = stop($s) If stop($s) = 0 Then GUICtrlSetData($Edit_3, $i & @LF, $i) Else ExitLoop EndIf Next Return GUICtrlSetData($Edit_3, "STOP") EndFunc ;==>iii Func stop(ByRef $s) If $s = 1 Then Return 1 Else Return 0 EndIf EndFunc ;==>stopthe func $iii() in my case, is a function to download by a list , and to do some analyzeex :1. check how many News on CNN website ( maybe 1,143 News what i want)2. download the page when i found the keyword. 3. analyze something ( check the News words and write log, show message on my Edit object )4. analyze finished , exit For.....Next Loop. and Endfunc.if i need to pause or exit while running on step 2 or 3 and it`s loop, there is a only way to use the trayicon to pause or exit ( or Ctrl + Alt + Del ...... ).... Edited November 12, 2007 by abiteric My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909 Link to comment Share on other sites More sharing options...
Valuater Posted November 12, 2007 Share Posted November 12, 2007 Maybe... #include <GuiConstants.au3> #Include <GuiEdit.au3> Dim $s = 0, $count = 0 GUICreate("MyGUI", 257, 251, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Button_1 = GUICtrlCreateButton("RUN", 50, 200, 70, 30) $Button_2 = GUICtrlCreateButton("STOP", 140, 200, 70, 30) $Edit_3 = GUICtrlCreateEdit("STOP", 30, 30, 90, 160, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 If $s = 1 Then ContinueLoop GUICtrlSetData($Edit_3, "") $s = 1 $count = 0 Case $msg = $Button_2 If $s = 0 Then ContinueLoop $s = 0 ;GUICtrlSetData($Edit_3, "") _GUICtrlEdit_AppendText ($Edit_3, "STOP" & @CRLF) EndSelect If $s = 1 Then $count = $count + 1 If $count = 99999 Then $count = 1 Sleep(100) _GUICtrlEdit_AppendText ($Edit_3, $count & @CRLF) EndIf WEnd 8) Link to comment Share on other sites More sharing options...
Valuater Posted November 12, 2007 Share Posted November 12, 2007 Another approach expandcollapse popup#include <GuiConstants.au3> #Include <GuiEdit.au3> Dim $s = 0, $count = 0 GUICreate("MyGUI", 257, 251, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Button_1 = GUICtrlCreateButton("RUN", 50, 200, 70, 30) $Button_2 = GUICtrlCreateButton("STOP", 140, 200, 70, 30) $Edit_3 = GUICtrlCreateEdit("STOP", 30, 30, 90, 160, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 If $s = 1 Then ContinueLoop GUICtrlSetData($Edit_3, "") $count = 0 $s = 1 AdlibEnable("Counter", 200) Case $msg = $Button_2 If $s = 0 Then ContinueLoop $s = 0 AdlibDisable() ;GUICtrlSetData($Edit_3, "") _GUICtrlEdit_AppendText ($Edit_3, "STOP" & @CRLF) EndSelect WEnd Func Counter() $count = $count + 1 If $count = 99999 Then $count = 1 _GUICtrlEdit_AppendText ($Edit_3, $count & @CRLF) EndFunc 8) Link to comment Share on other sites More sharing options...
abiteric Posted November 12, 2007 Author Share Posted November 12, 2007 (edited) Thanks for all reply ~i change some code to match what i wantexpandcollapse popup#include <GuiConstants.au3> Global $s = 0, $count = 0, $v = 0 GUICreate("MyGUI", 257, 251, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Button_1 = GUICtrlCreateButton("RUN", 20, 200, 50, 30) $Button_2 = GUICtrlCreateButton("STOP", 80, 200, 50, 30) $Button_3 = GUICtrlCreateButton("Pause", 130, 200, 50, 30) $Button_4 = GUICtrlCreateButton("Continue", 180, 200, 50, 30) $Edit_3 = GUICtrlCreateEdit("STOP", 30, 30, 90, 160, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Button_1 $count = 0 $s = 1 AdlibEnable("Counter", 100) Case $Button_2 $s = 0 AdlibDisable() GUICtrlSetData($Edit_3, "STOP") Case $Button_3 _s2() Case $Button_4 _s3() EndSwitch WEnd Func _s2() Global $s = 2 EndFunc ;==>_s2 record $count Func _s3() Global $s = 1 Global $count = $v EndFunc ;==>_s3 begin form $v to target 99999 Func Counter() If $s = 1 Then $count = $count + 1 EndIf If $s = 2 Then Global $v = $count EndIf ;main process build here If $count = 99999 Then $s = 0 GUICtrlSetData($Edit_3, $count & @CRLF) EndFunc ;==>Counter Main processbut i still have some confusing...how to use those on my main process ..... =.=? to build a lot of func _s1() _s2() _s3() ......... _sN() ?????because i have 6 For..... Next layer ..... hmmmm , my English not good.i thnk i need to think how to convey before my troble happen .... @@" Edited November 12, 2007 by abiteric My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909 Link to comment Share on other sites More sharing options...
Valuater Posted November 13, 2007 Share Posted November 13, 2007 This creates multiple timers expandcollapse popup#include <GUIConstants.au3> #include <Date.au3> Dim $Header_1 = "Machine" Dim $Header_2 = "Line" Dim $Header_3 = "Office" Dim $Name, $TotalTime, $Unit, $count Dim $TimerActive_[50], $Label_[50], $TButton_[50], $SButton_[50], $Input_[50], $Label_[50] Dim $Time_[50], $Timer_[50], $sTime_[50], $xk, $ck, $tk, $pk, $Left = 0, $Top = 20, $X, $Radx, $Rad_[11] $Today_File = @MON & "-" & @MDAY & "-" & @YEAR & ".txt" $Log = FileOpen($Today_File, 1) FileWriteLine($Log, "Logfile started: " & _DateTimeFormat( _NowCalc(), 0) & @CRLF & @CRLF) FileClose($Log) $Toy_Logo = @TempDir & "\Toy2-logo.jpg" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box2-jpg.jpg", $Toy_Logo) $Toy_Banner = @TempDir & "\Toy-banr.jpg" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-jpg.jpg", $Toy_Banner) $Logo_icon = @TempDir & "\Toy-Icon.ico" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-Icon.ico", $Logo_icon) Setup() AdlibEnable("AllTimers", 500) GUICreate(" Toy BOX - Multi-Station-Timer", (110 * $pk), 470) GUISetIcon($Logo_icon) ;Top computer label GUICtrlCreateLabel($Header_1 & "s", 0, 0, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE) GUICtrlSetFont(-1, 12, 700) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x876B53) ;Middle phones label GUICtrlCreateLabel($Header_2 & "s", 0, 220, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE) GUICtrlSetFont(-1, 12, 700) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x876B53) ;Bottom PC label GUICtrlCreateLabel($Header_3 & "s", 0, 340, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE) GUICtrlSetFont(-1, 12, 700) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x876B53) For $X = 1 To $pk ; row 1 GUICtrlCreateLabel($Header_1 & " " & $X, $Left, $Top, 100, 20, $SS_CENTER) $Label_[$X] = GUICtrlCreateLabel("", $Left, $Top + 20, 100, 30, 0x1000) GUICtrlSetFont($Label_[$X], 16) GUICtrlSetData($Label_[$X], "00:00:00") $TButton_[$X] = GUICtrlCreateButton("Start", $Left, $Top + 50, 50, 20) $SButton_[$X] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 50, 50, 20) $Input_[$X] = GUICtrlCreateInput("", $Left, $Top + 70, 100, 20, 0x1000) ;MsgBox(0,$pk, $Radx & @CRLF & $count) ; row 2 GUICtrlCreateLabel($Header_1 & " " & ($X + (($count +1)* .25)), $Left, $Top + 100, 100, 20, $SS_CENTER) $Label_[($X + (($count +1)* .25))] = GUICtrlCreateLabel("", $Left, $Top + 120, 100, 30, 0x1000) GUICtrlSetFont($Label_[($X + (($count +1)* .25))], 16) GUICtrlSetData($Label_[($X + (($count +1)* .25))], "00:00:00") $TButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Start", $Left, $Top + 150, 50, 20) $SButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 150, 50, 20) $Input_[($X + (($count +1)* .25))] = GUICtrlCreateInput("", $Left, $Top + 170, 100, 20, 0x1000) ; row 3 GUICtrlCreateLabel($Header_2 & " " & $X, $Left, $Top + 220, 100, 20, $SS_CENTER) $Label_[($X + (($count +1)* .5))] = GUICtrlCreateLabel("", $Left, $Top + 240, 100, 30, 0x1000) GUICtrlSetFont($Label_[($X + (($count +1)* .5))], 16) GUICtrlSetData($Label_[($X + (($count +1)* .5))], "00:00:00") $TButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Start", $Left, $Top + 270, 50, 20) $SButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 270, 50, 20) $Input_[($X + (($count +1)* .5))] = GUICtrlCreateInput("", $Left, $Top + 290, 100, 20, 0x1000) ; row 4 If ($X + (($count +1)* .75)) = ($count + 1) Then $Icon_1 = GUICtrlCreatePic($Toy_Banner, $Left, $Top + 360, 100, 50) GUICtrlSetState(-1, $GUI_DISABLE) ExitLoop EndIf GUICtrlCreateLabel($Header_3 & " " & $X, $Left, $Top + 340, 100, 20, $SS_CENTER) $Label_[($X + (($count +1)* .75))] = GUICtrlCreateLabel("", $Left, $Top + 360, 100, 30, 0x1000) GUICtrlSetFont($Label_[($X + (($count +1)* .75))], 16) GUICtrlSetData($Label_[($X + (($count +1)* .75))], "00:00:00") $TButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Start", $Left, $Top + 390, 50, 20) $SButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 390, 50, 20) $Input_[($X + (($count +1)* .75))] = GUICtrlCreateInput("", $Left, $Top + 410, 100, 20, 0x1000) $Left = $Left + 110 Next GUISetState() While 1 $msg = GUIGetMsg() For $xk = 1 To $count If $msg = $TButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" Then GUICtrlSetState($TButton_[$xk], $GUI_DISABLE) GUICtrlSetState($Input_[$xk], $GUI_DISABLE) $TimerActive_[$xk] = 1 $Timer_[$xk] = TimerInit() ElseIf $msg = $TButton_[$xk] Then MsgBox(64, "User Error: " & $xk, "Please Type in a User Name ", 3) EndIf If $msg = $SButton_[$xk] And GUICtrlRead($SButton_[$xk]) = "Reset" Then GUICtrlSetData($Label_[$xk], "00:00:00") GUICtrlSetData($Input_[$xk], "") GUICtrlSetData($SButton_[$xk], "Stop") GUICtrlSetState($TButton_[$xk], $GUI_ENABLE) GUICtrlSetState($Input_[$xk], $GUI_ENABLE) EndIf If $msg = $SButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" And GUICtrlRead($SButton_[$xk]) = "Stop" Then $TimerActive_[$xk] = 0 GUICtrlSetData($SButton_[$xk], "Reset") ; GUICtrlSetColor($Label_[$xk], 0x000000) $Name = GUICtrlRead($Input_[$xk]) ; If $xk <= (($count +1)* .5) Then $Unit = $Header_1 & " " & $xk EndIf If $xk > (($count +1)* .5) And $xk <= (($count +1)* .75) Then $Unit = $Header_2 & " " & ($xk - (($count +1)* .5)) EndIf If $xk > (($count +1)* .75) Then $Unit = $Header_3 & " " & ($xk - (($count +1)* .75)) EndIf RecordStuff() EndIf Next If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func AllTimers() Local $Secs, $Mins, $Hour For $ck = 1 To $count If $TimerActive_[$ck] Then _TicksToTime(Int(TimerDiff($Timer_[$ck])), $Hour, $Mins, $Secs) $Time_[$ck] = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) If $sTime_[$ck] <> $Time_[$ck] Then GUICtrlSetData($Label_[$ck], $Time_[$ck]) If $Mins > 29 Then GUICtrlSetColor($Label_[$ck], 0xff0000) EndIf Next EndFunc ;==>AllTimers Func RecordStuff() $LogStuff = FileOpen($Today_File, 1) FileWriteLine($LogStuff, "Station: " & $Unit & @CRLF) FileWriteLine($LogStuff, "User name: " & (GUICtrlRead($Input_[$xk])) & @CRLF) FileWriteLine($LogStuff, "Total time: " & (GUICtrlRead($Label_[$xk])) & @CRLF & @CRLF) FileClose($LogStuff) EndFunc ;==>RecordStuff Func Setup() $Set_win = GUICreate(" Toy BOX - Multi-Station-Timer", 350, 310) GUISetIcon($Logo_icon) $Icon_1 = GUICtrlCreatePic($Toy_Logo, 240, 10, 100, 250) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("3 Group Names", 10, 10, 220, 135) $Head_1 = GUICtrlCreateInput($Header_1, 30, 40, 150, 20) $Head_2 = GUICtrlCreateInput($Header_2, 30, 75, 150, 20) $Head_3 = GUICtrlCreateInput($Header_3, 30, 110, 150, 20) GUICtrlCreateGroup("Number of Timers", 10, 155, 220, 150) $Note = GUICtrlCreateLabel("19 Total Timers", 30, 175, 150, 20, $SS_SUNKEN + $SS_CENTER ) $Rad_[1] = GUICtrlCreateRadio("3", 40, 200, 30, 20) $Rad_[2] = GUICtrlCreateRadio("7", 40, 220, 30, 20) $Rad_[3] = GUICtrlCreateRadio("11", 40, 240, 30, 20) $Rad_[4] = GUICtrlCreateRadio("15", 40, 260, 30, 20) $Rad_[5] = GUICtrlCreateRadio("19", 40, 280, 30, 20) GUICtrlSetState( -1, $GUI_CHECKED ) $Rad_[6] = GUICtrlCreateRadio("23", 140, 200, 30, 20) $Rad_[7] = GUICtrlCreateRadio("27", 140, 220, 30, 20) $Rad_[8] = GUICtrlCreateRadio("31", 140, 240, 30, 20) $Rad_[9] = GUICtrlCreateRadio("35", 140, 260, 30, 20) $Rad_[10] = GUICtrlCreateRadio("39", 140, 280, 30, 20) $Create = GUICtrlCreateButton("Create", 250, 270, 80, 30) GUISetState() While 1 $msg2 = GUIGetMsg() If $msg2 = $Create Then $Header_1 = GUICtrlRead($Head_1) $Header_2 = GUICtrlRead($Head_2) $Header_3 = GUICtrlRead($Head_3) For $tk = 1 to 10 If GUICtrlRead($Rad_[$tk]) = $GUI_CHECKED Then $pk = $tk $Radx = $tk * 2 $count = (($tk * 4)-1) ExitLoop EndIf Next ExitLoop EndIf For $t = 1 to 10 If GUICtrlRead($Rad_[$t]) = $GUI_CHECKED Then GUICtrlSetData( $Note, (($t * 4)-1) & " Total Timers") ExitLoop EndIf Next If $msg2 = $GUI_EVENT_CLOSE Then ExitLoop Sleep(70) WEnd GUIDelete($Set_win) EndFunc 8) 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