Jump to content

Recommended Posts

Posted

Greetings,

I designed this set of UDFs because I wanted to use multiple functions for Adlib'ing. I also added an enhancement that will allow you to pass arguments to your adlib'ed functions. Granted, it is limited to whatever the built-in Call() function can handle, but I still think it is useful none the less. The _Adlib_Handler() function is not extremely time accurate, but it is pretty close on my machine. It will vary from computer to computer. If there are any bugs, let me know and I'll fix them.

AdlibHandler.au3

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         CodeMaster Rapture

 Script Function:
    Provides extra functionality to built-in AdlibEnable/AdlibDisable functions.

#ce ----------------------------------------------------------------------------
#include <Array.au3>

Global $Adlib_Counters[1] = [0]
Global $Adlib_Func_Names[1] = [0]
Global $Adlib_Func_Params[1] = [0]
Global $Adlib_Func_Timers[1] = [0]

;===============================================================================
;
; Function Name:  _Adlib_Handler()
;
; Parameter(s):     None
; Requirement(s):   Place AdlibEnable("_Adlib_Handler",XXX) at the begining of your script.
;                   Replace XXX with a time in milliseconds you want this function polled.
;                   Alternatively you can place _Adlib_Handler() in your main loop, but I recommend a Sleep(50) or higher in that same loop.
; Return Value(s):  None
; Author(s):        CodeMaster Rapture
; Notes(s):
;       This Adlib Enhancement can be inaccurate depending on your system and/or proccessor. Not recommended if you need accurate timing.
;       You can disable this function at anytime via AdlibDisable("_Adlib_Handler") or by your own mechanics if you use the alternate method.
;
;=====================================================================
Func _Adlib_Handler()
    If ($Adlib_Counters[0] == 0) Then Return
    Local $iter, $bDoesNotExist = False
    
    For $iter = 1 To $Adlib_Counters[0]
        If (TimerDiff($Adlib_Counters[$iter]) >= $Adlib_Func_Timers[$iter]) Then
            Local $a_Params = StringSplit($Adlib_Func_Params[$iter],"|")
            If (@error) Then
                If ($a_Params[1] == "") Then
                    Call($Adlib_Func_Names[$iter])
                    If (@error) Then
                        MsgBox(16,"Adlib Handler Error","Function '" & $Adlib_Func_Names[$iter] & "' does not exist." & @CRLF & "Deleting bad function.")
                        _Adlib_DeleteFunction($Adlib_Func_Names[$iter])
                        Return
                    EndIf
                Else
                    Call($Adlib_Func_Names[$iter],$a_Params[1])
                    If (@error) Then
                        MsgBox(16,"Adlib Handler Error","Function '" & $Adlib_Func_Names[$iter] & "' does not exist." & @CRLF & "Deleting bad function.")
                        _Adlib_DeleteFunction($Adlib_Func_Names[$iter])
                        Return
                    EndIf
                EndIf
            Else
                $a_Params[0] = "CallArgArray"
                Call($Adlib_Func_Names[$iter],$a_Params)
                If (@error) Then
                    MsgBox(16,"Adlib Handler Error","Function '" & $Adlib_Func_Names[$iter] & "' does not exist." & @CRLF & "Deleting bad function.")
                    _Adlib_DeleteFunction($Adlib_Func_Names[$iter])
                    Return
                EndIf
            EndIf
            $Adlib_Counters[$iter] = TimerInit()
        EndIf
    Next
EndFunc

;===============================================================================
;
; Function Name:  _Adlib_AddFunction()
;
; Parameter(s):     $sFunctionName  - Name of the function to be called without the trailing () or parameters.
;                   $sParams        - [optional] Any parameters you want to pass to the function seperated by "|".
;                   $iTime          - [optional]  (default = 100) The amount of time (in milliseconds) to wait between function calls.
;                                       Must be higher than 10ms. If not, it will be set to 100ms anyways.
; Requirement(s):   None
; Return Value(s):  On Success -  Returns True
;                   On Failure -  Returns False
;                       @error=1    Invalid function name (as in, it wasn't a string or was left blank)
;                       @error=2    Invalid time format. Cannot be a string or float.
;                       @error=3    For some reason, your function could not be added to the queue (internal Au3 problem)
; Author(s):        CodeMaster Rapture
; Notes(s):
;       Usage Example:
;       _Adlib_AddFunction("myAddNumbers","123|569",1000)
;
;       Limitations:
;       You cannot use variables ByRef as parameters.
;       You cannot pass an array as a parameter unless you want to use _ArrayToString() on it.
;       All parameters will be passed as strings.
;
;=====================================================================
Func _Adlib_AddFunction($sFunctionName,$sParams = "",$iTime = 100)
    If (Not IsString($sFunctionName) Or ($sFunctionName == "")) Then
        SetError(1)
        Return False
    EndIf
    
    If (Not IsInt($iTime)) Then
        SetError(2)
        Return False
    EndIf
    
    If ($iTime < 10) Then $iTime = 10
    
    _ArrayAdd($Adlib_Counters,TimerInit())
    If (@error) Then
        SetError(3)
        Return False
    EndIf
    
    _ArrayAdd($Adlib_Func_Names,$sFunctionName)
    If (@error) Then
        _ArrayPop($Adlib_Counters)
        SetError(3)
        Return False
    EndIf
    _ArrayAdd($Adlib_Func_Params,$sParams)
    If (@error) Then
        _ArrayPop($Adlib_Func_Names)        ;Pop the function name in order to keep Adlib_Func_X arrays in sync
        SetError(3)
        Return False
    EndIf
    _ArrayAdd($Adlib_Func_Timers,$iTime)
    If (@error) Then
        _ArrayPop($Adlib_Func_Names)        ;Pop the function name in order to keep Adlib_Func_X arrays in sync
        _ArrayPop($Adlib_Func_Params)       ;Pop the function params in order to keep Adlib_Func_X arrays in sync
        SetError(3)
        Return False
    EndIf
    $Adlib_Counters[0] += 1
    $Adlib_Func_Names[0] += 1
    $Adlib_Func_Params[0] += 1
    $Adlib_Func_Timers[0] += 1
    Return True
EndFunc

;===============================================================================
;
; Function Name:  _Adlib_DeleteFunction()
;
; Parameter(s):     $sFunctionName  - Name of the function to be deleted from the Adlib Handler.
; Requirement(s):   None
; Return Value(s):  On Success -  Returns True
;                   On Failure -  Returns False
;                       @error=1    Invalid function name (as in, it wasn't a string or was left blank)
;                       @error=2    $sFunctionName not found.
; Author(s):        CodeMaster Rapture
; Notes(s):
;       Usage Example:
;       _Adlib_DeleteFunction("myAddNumbers")
;
;       This function will delete the first occurence of the function name.
;       Keep this in mind if you add the same function more than once (but with different parameters for example).
;
;=====================================================================
Func _Adlib_DeleteFunction($sFunctionName)
    If ((Not IsString($sFunctionName)) Or ($sFunctionName == "")) Then
        SetError(1)
        Return False
    EndIf
    
    Local $iElement
    $iElement = _ArraySearch($Adlib_Func_Names,$sFunctionName,1,$Adlib_Func_Names[0],1)
    If ($iElement > 0) Then
        _ArrayDelete($Adlib_Counters,$iElement)
        _ArrayDelete($Adlib_Func_Names,$iElement)
        _ArrayDelete($Adlib_Func_Params,$iElement)
        _ArrayDelete($Adlib_Func_Timers,$iElement)
        $Adlib_Counters[0] -= 1
        $Adlib_Func_Names[0] -= 1
        $Adlib_Func_Params[0] -= 1
        $Adlib_Func_Timers[0] -= 1  
        Return True
    EndIf
    SetError(2)
    Return False
EndFunc
Posted

I like the idea, only one thing; i would use CallBack's to execute the handler, because of multiple loops limit...

Or other idea: our custom Adlib function will return identfier (CallBack handle), and when you want to disable it, you just use that identifier (with DllCallBackFree).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

There are already UDFs which use the Windows Timer with CallBack :D You just have to make an Array based on the TimerIDs for the Parameters. The UDF is included in the latest BETA

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

I'm not sure what you mean by CallBack IDs, can you give me an example?

Something like this:

#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", $hWnd, "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", $hWnd)
    Return Number(IsArray($aRet) And $aRet[0])
EndFunc

Func _TimerFunc($hWndGUI, $MsgID, $WParam, $LParam)
    $Left += 2
    If $Left >= 300 Then $Left = -200
    ControlMove($Gui, "", $Label, $Left, 100)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • 2 months later...
Posted

I have used the AdlibHandler.au3 and it works perfectly. The only issue Im having is that I have a hotkey set to pause everything and that doesnt work. Basicly what it does is call a func just like your _quit func but I have deleted the exit and renamed it _pause. When the _pause function is called a msg box will come up (put that in there to make sure the func is called) but the AdlibHandler keeps running and calling the other func. Any Ideas on how to pause this?

Posted (edited)

Mice MrCreatoR...

but, shouldn't this return an error

If Not IsHWnd($hWnd) Then $hWnd = GUICreate("hCallBack_AdlibEnable")

rather than create a gui ????

8)

EDIT:... Nice job too!!! CodeMaster

Edited by Valuater

NEWHeader1.png

Posted (edited)

I do not have the Timers Management directory. So I looked and Im running an old version of Autoit. I see the newest version is v3.2.12.1 released (12th June, 2008). Mine is Version v3.2.10.0 Nov 25 2007. I will upgrade later and check for the function then.

Edit: fixed my version number

Edited by Smiley357
Posted

I do not have the Timers Management directory. So I looked and Im running an old version of Autoit. I see the newest version is v3.2.12.1 released (12th June, 2008). Mine is Version 1.71 Nov 25 2007. I will upgrade later and check for the function then.

Whoa... Where have you been?? Lol just joking...
code
Posted

Ok I now have the new version. I well have to check out all the new functions. While I was looking for the _Timer_SetTimer(0,500,"Function") I found AdlibEnable. This seems to be a more simpler version of _timer_setTimer and you dont have to use a #include file. There is also an AdlibDisable. That is nice b/c I will use this to pause. Exactly what I was looking for. Thanks for all the help.

Posted

Kip you just like to rain on my sunshine dont you! LOL humm guess I will be using the setTimer func. I have more then one function I will be using.

  • 5 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...