GaryFrost Posted January 2, 2008 Share Posted January 2, 2008 (edited) Re-worked the functions and examples, all on this post to easily find. Timers using CallBack and WM_TIMER MSDN states that WM_TIMER is a slower method, so the CallBack method would be the preferred method. expandcollapse popup#include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <Timers.au3> Global $iMemo _Example_CallBack() _Example_Events() Func _Example_CallBack() Local $hGUI, $iTimer1, $iTimer2, $btn_change, $iWait = 5000 $hGUI = GUICreate("My Timers Using CallBack Function(s)", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") $btn_change = GUICtrlCreateButton("Change", 155, 275, 90, 20) GUISetState() $iTimer1 = _Timer_SetTimer($hGUI, 3000, "_TimerCallBackFunc1") ; create timer $iTimer2 = _Timer_SetTimer($hGUI, 3000, "_TimerCallBackFunc2") ; create timer While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn_change If $iWait = 5000 Then $iWait = 250 $iTimer1 = _Timer_SetTimer($hGUI, 250, "_TimerCallBackFunc1", $iTimer1) ; reuse timer with different interval $iTimer2 = _Timer_SetTimer($hGUI, 3000, "_TimerCallBackFunc2", $iTimer2) ; reuse timer with different interval Else $iWait = 5000 $iTimer1 = _Timer_SetTimer($hGUI, 3000, "_TimerCallBackFunc1", $iTimer1) ; reuse timer with different interval $iTimer2 = _Timer_SetTimer($hGUI, 250, "_TimerCallBackFunc2", $iTimer2) ; reuse timer with different interval EndIf EndSwitch WEnd ConsoleWrite("Killed Timer? " & _Timer_KillTimer($hGUI, $iTimer1) & @LF) ConsoleWrite("Killed Timer? " & _Timer_KillTimer($hGUI, $iTimer2) & @LF) GUIDelete() EndFunc ;==>_Example_CallBack Func _TimerCallBackFunc1($hWnd, $Msg, $iIDTimer, $dwTime) MemoWrite("_TimerCallBackFunc1 Timer " & $iIDTimer & " Fired") EndFunc ;==>_TimerCallBackFunc1 Func _TimerCallBackFunc2($hWnd, $Msg, $iIDTimer, $dwTime) MemoWrite("_TimerCallBackFunc2 Timer " & $iIDTimer & " Fired") EndFunc ;==>_TimerCallBackFunc2 Func _Example_Events() Local $hGUI, $iTimer1, $iTimer2, $btn_change, $iWait = 5000 $hGUI = GUICreate("My Timers Using WM_TIMER", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") $btn_change = GUICtrlCreateButton("Change", 155, 275, 90, 20) GUISetState() GUIRegisterMsg($WM_TIMER, "WM_TIMER") $iTimer1 = _Timer_SetTimer($hGUI, 5000) $iTimer2 = _Timer_SetTimer($hGUI, 3000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn_change If $iWait = 5000 Then $iWait = 250 $iTimer1 = _Timer_SetTimer($hGUI, 250, "", $iTimer1) ; reuse timer with different interval $iTimer2 = _Timer_SetTimer($hGUI, 3000, "", $iTimer2) ; reuse timer with different interval Else $iWait = 5000 $iTimer1 = _Timer_SetTimer($hGUI, 3000, "", $iTimer1) ; reuse timer with different interval $iTimer2 = _Timer_SetTimer($hGUI, 250, "", $iTimer2) ; reuse timer with different interval EndIf EndSwitch WEnd ConsoleWrite("Killed Timers? " & _Timer_KillAllTimers($hGUI) & @LF) EndFunc ;==>_Example_Events Func WM_TIMER($hWnd, $iMsg, $iwParam, $ilParam) If _Timer_IsTimerID($iwParam) Then MemoWrite("Timer " & $iwParam & " Fired") Return $GUI_RUNDEFMSG EndFunc ;==>WM_TIMER Func _Timer_IsTimerID(ByRef $iwParam) For $x = 1 To UBound($_Timers_aTimerIDs) - 1 Switch Dec(Hex($iwParam, 8)) Case $_Timers_aTimerIDs[$x][1] $iwParam = Dec(Hex($iwParam, 8)) Return True EndSwitch Next Return False EndFunc ;==>_Timer_IsTimerID ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWriteoÝ÷ Ù8¦z¸§Ö§uØ}ìZ^jëh×6#include <Timers.au3> _Main() Func _Main() HotKeySet("{ESC}", "_Quit") Local $starttime = _Timer_Init() While 1 ToolTip(_Timer_Diff($starttime)) WEnd EndFunc ;==>_Main Func _Quit() Exit EndFunc ;==>_Quit Gary Edited January 26, 2008 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
James Posted January 2, 2008 Share Posted January 2, 2008 What are they supposed to do? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted January 2, 2008 Share Posted January 2, 2008 Looks like they set timers in the Windows environment so your script is free to do other things while something is pending. Link to comment Share on other sites More sharing options...
James Posted January 2, 2008 Share Posted January 2, 2008 Oh so thats why you can drag it and it still updates. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted January 2, 2008 Share Posted January 2, 2008 Oh so thats why you can drag it and it still updates.Well you can always move the window regardless of it being stuck in a loop. Think of it more as a task scheduler that doesn't rely on the Task Scheduler service. Link to comment Share on other sites More sharing options...
Achilles Posted January 2, 2008 Share Posted January 2, 2008 Thanks for these! They'll prove useful... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Toady Posted January 2, 2008 Share Posted January 2, 2008 Wow, very nice example of Callback functionality. Very useful! www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
GaryFrost Posted January 2, 2008 Author Share Posted January 2, 2008 (edited) Edit: see 1st post Edited January 10, 2008 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted January 2, 2008 Author Share Posted January 2, 2008 (edited) Edit: see 1st post Edited January 10, 2008 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
martin Posted January 2, 2008 Share Posted January 2, 2008 ..Example using Callback Function(s)In the API SetTimer function iIDEvent is specified as UINT_PTR, and so is the reference passed by the callback function. Because of this when I have used the function in the past I have have stored a timer number in a struct, passed the address of the struct and used the return value as an address and used it to read the id of the timer.Looks like I got it wrong, although it works, but do you know why the id is specified as UINT_PTR? (I understand that it is the same type as UINT in practice.) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
GaryFrost Posted January 2, 2008 Author Share Posted January 2, 2008 In the API SetTimer function iIDEvent is specified as UINT_PTR, and so is the reference passed by the callback function. Because of this when I have used the function in the past I have have stored a timer number in a struct, passed the address of the struct and used the return value as an address and used it to read the id of the timer.Looks like I got it wrong, although it works, but do you know why the id is specified as UINT_PTR? (I understand that it is the same type as UINT in practice.)Not sure why it's UINT_PTR, I used what I thought it should be from experience with Menu IDs and Toolbars, and it worked as I expected. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Jex Posted January 3, 2008 Share Posted January 3, 2008 (edited) Very good examples for learn DllCall and GUIRegisterMsg, thanks. I'm created that example for learn : expandcollapse popup#include <WindowsConstants.au3> #include <GuiConstantsEx.au3> Global Enum $TIMERID1 = 1001, $TIMERID2, $TIMERID3 Global $iLabel, $iMemo, $Count, $Var = 1, $Var2 = 1, $hGUI, $iTimer1, $iTimer2, $hCallBack, $hCallBack2, $First = 1 $hGUI = GUICreate("My Timers", 600, 296) GUISetBkColor(0xFFFFFF) $iLabel = GUICtrlCreateLabel("0", 10, 10, 100, 25) $iLabel2 = GUICtrlCreateLabel("0", 150, 10, 300, 25) $iMemo = GUICtrlCreateEdit("", 2, 32, 596, 262, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetState($iMemo, $GUI_DISABLE) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() $hCallBack = DllCallbackRegister("_TimerCallBackFunc", "none", "hwnd;int;int;dword") $hCallBack2 = DllCallbackRegister("_TimerCallBackFunc", "none", "hwnd;int;int;dword") $hCallBack3 = DllCallbackRegister("_TimerCallBackFunc", "none", "hwnd;int;int;dword") $iTimer1 = _WinAPI_SetTimer($hGUI, $TIMERID1, 1000, DllCallbackGetPtr($hCallBack)) Sleep(100) $iTimer2 = _WinAPI_SetTimer($hGUI, $TIMERID2, 5000, DllCallbackGetPtr($hCallBack2)) $iTimer3 = _WinAPI_SetTimer($hGUI, $TIMERID3, 3000, DllCallbackGetPtr($hCallBack3)) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _WinAPI_KillTimer($hGUI, $iTimer1) _WinAPI_KillTimer($hGUI, $iTimer2) DllCallbackFree($hCallBack) DllCallbackFree($hCallBack2) Func _WinAPI_SetTimer($hWnd, $iIDEvent, $iElapse, $pTimerFunc = 0) Local $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iIDEvent, "int", $iElapse, "ptr", $pTimerFunc) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] EndFunc ;==>_WinAPI_SetTimer Func _WinAPI_KillTimer($hWnd, $iIDEvent) Local $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $iIDEvent) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] <> 0 EndFunc ;==>_WinAPI_KillTimer Func _TimerCallBackFunc($hWnd, $Msg, $iIDTimer, $dwTime) If $First = 1 And $iIDTimer = $TIMERID1 Then $First = 0 Global $FirstTime = $dwTime EndIf GUICtrlSetData($iMemo, "hWnd : " & $hWnd & " Msg : " & $Msg & " iIDTimer : " & $iIDTimer & " dwTime : " & $dwTime & @CRLF, 1) GUICtrlSetData($iLabel2, $dwTime - $FirstTime) If $iIDTimer = $TIMERID1 Then If $Var = 1 Then $Count += 1 Else $Count -= 1 EndIf GUICtrlSetData($iLabel, $Count) ElseIf $iIDTimer = $TIMERID2 Then If $Var = 1 Then $Var = 2 Else $Var = 1 EndIf Else If $Var2 = 1 Then GUISetBkColor(0x000000) GUICtrlSetColor($iLabel, 0xFFFFFF) GUICtrlSetColor($iLabel2, 0xFFFFFF) $Var2 = 2 Else GUISetBkColor(0xFFFFFF) GUICtrlSetColor($iLabel, 0x000000) GUICtrlSetColor($iLabel2, 0x000000) $Var2 = 1 EndIf EndIf EndFunc ;==>_TimerCallBackFunc Edited January 3, 2008 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
Linux Posted January 3, 2008 Share Posted January 3, 2008 Simply Great! Solves my problem! Thank you! You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!" Link to comment Share on other sites More sharing options...
ptrex Posted January 3, 2008 Share Posted January 3, 2008 @GaryFrost Very nice start for 2008 !! regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
therks Posted January 7, 2008 Share Posted January 7, 2008 Nice examples Gary. As soon as the callback functions showed up I knew this stuff would be handy. I was actually thinking of writing up a UDF to make creating, altering, and stopping timers as easy as possible. Something like a _TimerSet() and a _TimerClear() function. So you could do like the following: $iTimerID = _TimerSet('myFunc', 1000) ; Create/initialize timer Sleep(5000) _TimerSet('myFunc', 500, $iTimerID) ; Alter existing timer Sleep(5000) _TimerClear($iTimerID) ; Stop timer and clear any handles etc Func myFunc() ToolTip(@SEC) EndFunc Any suggestions? I wanted it to be as simple as possible (for the end user) but I'm caught on some ideas, like how to keep track of the timer ID's to callback handles, etc. Only way I can see it is with a global array. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 7, 2008 Share Posted January 7, 2008 (edited) Any suggestions? I wanted it to be as simple as possibleI did this a while ago: expandcollapse popup#include <GuiConstants.au3> $Gui = GuiCreate("Custom _AdlibEnable Demo", 300, 130) $Left = -200 $Label = GUICtrlCreateLabel("Drag the window, i am just a runing text ;)", $Left, 100) $RunCheckBox = GUICtrlCreateCheckbox("Run text", 20, 40) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 _AdlibDisable($Gui) Exit Case $RunCheckBox If GUICtrlRead($RunCheckBox) = 1 Then _AdlibEnable("_TimerFunc", 30, $Gui) Else _AdlibDisable($Gui) EndIf EndSwitch WEnd Func _AdlibEnable($sFunction, $iTime=250, $hWnd=0) Local Const $WM_TIMER = 0x0113 If Not IsHWnd($hWnd) Then $hWnd = GUICreate("hCallBack_AdlibEnable") GUIRegisterMsg($WM_TIMER, $sFunction) Local $aRet = DllCall("User32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", 50, "int", $iTime, "int", 0) Return $hWnd EndFunc Func _AdlibDisable($hWnd=0) Local Const $WM_TIMER = 0x0113 GUIRegisterMsg($WM_TIMER, "") Local $aRet = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int*", 50) Return Number(IsArray($aRet) And $aRet[0]) EndFunc Func _TimerFunc() $Left += 2 If $Left >= 300 Then $Left = -200 ControlMove($Gui, "", $Label, $Left, 100) EndFunc As you can see, i made it as Adlib style Edited January 7, 2008 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 7, 2008 Share Posted January 7, 2008 (edited) Here is _TimerStart Style (callback usage): expandcollapse popup#include <GuiConstants.au3> Global $ahTimer_1, $ahTimer_2, $ahTimer_3 $Gui = GuiCreate("_TimerStart/Stop Demo", 300, 130) $RunTextCheckBox = GUICtrlCreateCheckbox("Run text", 20, 10) $Left_1 = -100 $Left_2 = -100 $Left_3 = -100 $Label_1 = GUICtrlCreateLabel("I am a runing text ;)", $Left_1, 40) $Label_2 = GUICtrlCreateLabel("Hey, wait for me....)", $Left_2, 70) $Label_3 = GUICtrlCreateLabel("And for me too....)", $Left_3, 100) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE If GUICtrlRead($RunTextCheckBox) <> $GUI_CHECKED Then Exit _TimerStop($ahTimer_1[0], $ahTimer_1[1]) _TimerStop($ahTimer_2[0], $ahTimer_2[1]) _TimerStop($ahTimer_3[0], $ahTimer_3[1]) Exit Case $RunTextCheckBox If GUICtrlRead($RunTextCheckBox) = 1 Then $ahTimer_1 = _TimerStart("_MyTimerFunc_1", 30) $ahTimer_2 = _TimerStart("_MyTimerFunc_2", 40) $ahTimer_3 = _TimerStart("_MyTimerFunc_3", 50) Else _TimerStop($ahTimer_1[0], $ahTimer_1[1]) _TimerStop($ahTimer_2[0], $ahTimer_2[1]) _TimerStop($ahTimer_3[0], $ahTimer_3[1]) EndIf EndSwitch WEnd Func _TimerStart($sFunction, $iTime=250) Local $hCallBack = DllCallbackRegister($sFunction, "none", "hwnd;int;int;dword") Local $aDll = DllCall("user32.dll", "int", "SetTimer", _ "hwnd", 0, _ "int", TimerInit(), _ "int", $iTime, _ "ptr", DllCallbackGetPtr($hCallBack)) Local $aRet[2] = [$hCallBack, $aDll[0]] Return $aRet EndFunc Func _TimerStop($hCallBack, $hTimer) DllCallBackFree($hCallBack) Local $aRet = DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $hTimer) Return $aRet[0] EndFunc Func _MyTimerFunc_1($hWnd, $Msg, $iIDTimer, $dwTime) $Left_1 += 2 If $Left_1 >= 300 Then $Left_1 = -100 ControlMove($Gui, "", $Label_1, $Left_1, 40) EndFunc Func _MyTimerFunc_2($hWnd, $Msg, $iIDTimer, $dwTime) $Left_2 += 2 If $Left_2 >= 300 Then $Left_2 = -100 ControlMove($Gui, "", $Label_2, $Left_2, 70) EndFunc Func _MyTimerFunc_3($hWnd, $Msg, $iIDTimer, $dwTime) $Left_3 += 2 If $Left_3 >= 300 Then $Left_3 = -100 ControlMove($Gui, "", $Label_3, $Left_3, 100) EndFunc Edited January 9, 2008 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
therks Posted January 9, 2008 Share Posted January 9, 2008 That's great and all, but you still have to keep track of the timer ID's yourself (Global Enum $TIMERID1 = 1001, $TIMERID2, $TIMERID3) I wanted that part to be taken care of by the UDF. When I get some time I'll look into it some more. Is there an upper limit the timer ID value? My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 9, 2008 Share Posted January 9, 2008 (edited) but you still have to keep track of the timer ID's yourself (Global Enum $TIMERID1 = 1001, $TIMERID2, $TIMERID3) I wanted that part to be taken care of by the UDF Like this maybe: Func _TimerStart($sFunction, $iTime=250) Local $hCallBack = DllCallbackRegister($sFunction, "none", "hwnd;int;int;dword") Local $iTIMERID = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC Local $aDll = DllCall("user32.dll", "int", "SetTimer", _ "hwnd", 0, _ "int", $iTIMERID, _ "int", $iTime, _ "ptr", DllCallbackGetPtr($hCallBack)) Local $aRet[2] = [$hCallBack, $aDll[0]] Return $aRet EndFunc Or we can use TimerInit() as $iTIMERID. P.S I edited my previouse post. Edited January 9, 2008 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
GaryFrost Posted January 9, 2008 Author Share Posted January 9, 2008 (edited) Like this maybe: Func _TimerStart($sFunction, $iTime=250) Local $hCallBack = DllCallbackRegister($sFunction, "none", "hwnd;int;int;dword") Local $iTIMERID = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC Local $aDll = DllCall("user32.dll", "int", "SetTimer", _ "hwnd", 0, _ "int", $iTIMERID, _ "int", $iTime, _ "ptr", DllCallbackGetPtr($hCallBack)) Local $aRet[2] = [$hCallBack, $aDll[0]] Return $aRet EndFunc Or we can use TimerInit() as $iTIMERID. P.S I edited my previouse post. Only problem with this is it eliminates the ability to reuse a timer, therefore you would have to kill it. If I get time and the inkling I'll throw something together like maybe a 2D array, 1st timer starts at 1001, and stores the the id in the array also for matching up. Edited January 9, 2008 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. 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