Jump to content

Execute function without wait.


psynegy
 Share

Recommended Posts

Hey, I'm writing a light control app, and I'm trying to work out the best way to run a function, such as a fade, which will happen over a period of time, without affecting the GUI of my application.

I suppose (I could be wrong) but I am asking for multi-threading capabilities, or forking or whatever. I'd be interested to know whether it's possible, and if someone could give me an example of executing a function with parameters, which allows the script to continue without waiting for the function to complete it's execution.

Hope that's not too jumbled up! Cheers!

Link to comment
Share on other sites

Interestingly enough, I found what I was looking for. It's not multi-threading as such, but it does exactly what I need it to do.

#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

(Example courtesy of MrCreatoR, many thanks!)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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