nadigo Posted December 22, 2010 Share Posted December 22, 2010 HI, I have a GUI script that needs to: 1. run as tray item and preform a task once in X hours 2. respond to GUI clicks 3. respond to Tray clicks what is the best way to do it ? when I use the below code, It the script freezes from time to time so that GUI and Tray clicks are not run. is there a different way to do so ? Thanks Nadav current code expandcollapse popupGlobal $iTimer = _NowCalc() While 1 $msg = TrayGetMsg() TrayItemSetState($msg, $TRAY_UNCHECKED) Select Case $msg = $updateitem Update() Case $msg = $ShowSearchSlider Set_Show() Case $msg = $aboutitem Msgbox(64, "About", "AboutMe.com") Case $msg = $exititem Exit EndSelect ;timer cheking - 1st tomer run once in 6 hours If SecTimeDiff ($iTimer) >= 60 then ;3 hours = 10800 sec ; check if last run is > 6 hours and func_do $iTimer = _NowCalc() $ini = IniRead("\Config.ini", "App" ,"LastChnage_1", "1900/01/01 00:00:00") If SecTimeDiff ($ini) >= 21600 then $hdl = func_do_1 () EndIf ;timer cheking - 2st once in 24 hours $ini = IniRead("\Config.ini", "App" ,"LastChnage_2", "1900/01/01 00:00:00") If SecTimeDiff ($ini) >= 86400 then $hdl = func_do_2 () EndIf EndIf ; If mouse is on top of GUI do action Chng_GUI If MouseGetPos(0) < $Hposition AND MouseGetPos(1) > $Vposition Then Chng_GUI() ElseIf IsVisible($hwnd2) then If ( MouseGetPos(0) > 250 OR MouseGetPos(1) < $Vposition - 50) Then Chng_GUI_2() EndIf EndIf ;sleep (10) WEnd Func SecTimeDiff ($sTime) ; s seconds h hours m mintuts (??) $Diff = _DateDiff("s", $sTime, _NowCalc()) return $Diff EndFunc Func IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 nadigo,This is how I would do the waiting loops - look for the <<<<<<<<< lines: expandcollapse popup#include <GUIConstantsEx.au3> #Include <Date.au3> Opt("TrayMenuMode", 3) ; This is the best way to prevent ticks appearing on the tray menu <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $updateitem = TrayCreateItem("Update") $ShowSearchSlider = TrayCreateItem("Show") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") $hGUI = GUICreate("Test", 500, 500) GUISetState(@SW_HIDE, $hGUI) ; Get DTG of last updates $sUpdate_1 = IniRead("\Config.ini", "App", "LastChnage_1", "1900/01/01 00:00:00") $sUpdate_2 = IniRead("\Config.ini", "App", "LastChnage_2", "1900/01/01 00:00:00") ; Start short term timer Global $iBegin = TimerInit() While 1 Switch TrayGetMsg() ; I think Switch is clearer in a loop like this <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $updateitem MsgBox(0, "Running", "Update") Case $ShowSearchSlider MsgBox(0, "Running", "Set_Show") GUISetState(@SW_SHOW, $hGUI) Case $aboutitem MsgBox(64, "About", "AboutMe.com") Case $exititem Exit EndSwitch Switch GUIGetMsg() ; We do need to check the GUI Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $hGUI) ; We hide it if we click the [X} EndSwitch ; Let us check the timers every minute If TimerDiff($iBegin) > 1000 Then ; For 1 minute use 60000 here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Now check and see if we need to do something $iTimer = _NowCalc() ; We are looking to run here every 6 hours If _DateDiff("s", $sUpdate_1, $iTimer) > 6 Then ; at least 6 hours have elapsed ; reset to "h" <<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("06" & " - " & @SEC & @CRLF) ; Delete <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;MsgBox(0, "Running" , "func_do_1") ; Uncomment <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Reset $sUpdate_1 $sUpdate_1 = $iTimer ; Here you need to rewrite the ini file ; IniWrite("\Config.ini", "App", "LastChnage_1", $iTimer) ; Uncomment <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf ; We are looking to run here every 24 hours If _DateDiff("s", $sUpdate_2, $iTimer) > 24 Then ; at least 24 hours have elapsed ; reset to "h" <<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("24" & " - " & @SEC & @CRLF) ; Delete <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;MsgBox(0, "Running" , "func_do_2") ; Uncomment <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Reset $sUpdate_2 $sUpdate_2 = $iTimer ; Here you need to rewrite the ini file and reset $sUpdate_2 ; IniWrite("\Config.ini", "App", "LastChnage_2", $iTimer) ; Uncomment <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf ; Reset the short term timer to wait for another minute $iBegin = TimerInit() EndIf ; Mouse over GUI code WEndI have set it up to run every 6 and 24 seconds - the comments show where to change it back. At the moment it seems to run every 7/25 secs because it is running so quickly - if you use hours it should run to the accuracy to which you set the short term timer (I have suggested 1 minute).I am unsure what you want to achieve with the mouse over GUI code so it is a bit hard to suggest anything. You obviously want different things to happen if the GUI is visible or not. What is the relationship between the GUI, $Hposition and $Vposition? 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...
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