zxcvbnm Posted February 15, 2011 Share Posted February 15, 2011 Hi, this is the first part of code of my application that uses two timer, the first to count minuts and seconds and the second to flash color of label expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=tm506.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Timers.au3> Global $iMin = 1, $iSec = 32, $iFlash = 0, $neg = 0 Global Const $DW = @DesktopWidth Global Const $DH = @DesktopHeight $Form1 = GUICreate("Count Down", 250, 70, $DW-280, 125, BitOR($WS_DLGFRAME, $WS_POPUP), $WS_EX_TOPMOST) GUISetBkColor(0x66FF00) $Label = GUICtrlCreateLabel(StringFormat("%02d:%02d", $iMin, $iSec), 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 40, 800, 0, "verdana") ; At the top of your script add this line OnAutoItExitRegister("_Kill_Timers") GUISetState(@SW_SHOW) ; Set up the intercept of the WM_CLOSE message GUIRegisterMsg($WM_CLOSE, "WM_CLOSE") ;AutoItSetOption ( "TrayIconHide" ,1 ) ; Start a timer for the countdown $iTimerProgress = _Timer_SetTimer($Form1, 5, "_CountDown") ; Call once a sec ; Set a placeholder for the Flash timer $iFlash_Timer = 9999 ; Loop until you get to the correct value Do Sleep(10) Until $iMin = (-59) And $iSec = 59 ; Kill the Progress Timer _Timer_KillTimer($Form1, $iTimerProgress) ; Keep the scipt alive While 1 Sleep(10) Wend ; this runs when the message is intercepted Func WM_CLOSE() _Timer_KillAllTimers($Form1) MsgBox(0, "Success", "The handler has intercepted the 'Close' call from the other script") Exit EndFunc to close my application and timer I use this call, this is another .exe file WinClose("Count Down") so I'm sure that every timer (first and second) are turned off I put a message to verify if it stop -> MsgBox(0, "Success", "The handler has intercepted the 'Close' call from the other script") if I close my application with task manager is there a way to control timers stopping? Thank Link to comment Share on other sites More sharing options...
zxcvbnm Posted February 15, 2011 Author Share Posted February 15, 2011 If I have two istances of appliation runnig (it's difficult but it can), using winClose I close only one istance, to close the second I have to call winClose another time, is there a way to close all the windows? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 15, 2011 Moderators Share Posted February 15, 2011 (edited) Func _MyWinClose($s_title, $s_text = "") While WinExists($s_title, $s_text) WinClose($s_title, $s_text) Wend EndFunc ? Edit: Sometimes windows fight closing/automation, because of that, there's a possibility you could get stuck in that loop. I'd probably go with something like:expandcollapse popupGlobal $gi_wincloseval = _MyWinClose("SomeWindowThatIsVisible") If $gi_wincloseval Then ConsoleWrite($gi_wincloseval & " windows were closed out of " & @extended & " windows" & @CRLF) Else Switch @error Case 1 ConsoleWrite("Title was either blank or window does not exist." & @CRLF) Case 2 ConsoleWrite("WinList Failed" & @CRLF) Case 3 ConsoleWrite("Could not close open window" & @CRLF) EndSwitch EndIf Func _MyWinClose($s_title, $s_text = "", $f_visibleonly = True) ; Return error 1 and value 0 if no window exist If Not $s_title Or Not WinExists($s_title, $s_text) Then Return SetError(1, 0, 0) EndIf Local $a_winlist = WinList($s_title, $s_text) If Not IsArray($a_winlist) Then Return SetError(2, 0, 0) EndIf Local $i_closecount = 0, $i_wincount = 0 For $i = 1 To $a_winlist[0][0] If $f_visibleonly Then If BitAND(WinGetState($a_winlist[$i][1]), 2) Then $i_wincount += 1 $i_closecount += WinClose($a_winlist[$i][1]) EndIf Else $i_wincount += 1 $i_closecount += WinClose($a_winlist[$i][1]) EndIf Next If Not $i_closecount Then Return SetError(3, $i_wincount, 0) Return SetError(0, $i_wincount, $i_closecount) EndFunc The return value is the number of windows that actually closed. @extended is the number of windows there were. Edited February 15, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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