找回密码
 加入
搜索
楼主: happytc

[AU3基础] [已解决] 请问,为什么AdlibRegister不执行?

 火.. [复制链接]
发表于 2010-12-16 22:02:24 | 显示全部楼层
回复 14# happytc


    至于HotKeySet函数,那是需要用户介入的,而Adlib函数则是在设定的间隔时间中不断的执行
 楼主| 发表于 2010-12-16 22:11:44 | 显示全部楼层
回复 15# 飘云

呵,是我没有说明白,前面之所以说Adlib只执行了一次,只因为主程序没有挂起,而不象AHK里的SubTimer,其本身就有这让主程序挂起的功能,所以迷惑了。
发表于 2010-12-17 12:36:55 | 显示全部楼层
回复 17# happytc


    Adlib出现的原因就是想在不让程序挂起的状态下,并发的执行某些命令,这在某些情况下是很需要的。。。一时半会想不起具体实例,记得以前碰上过一个必须要同步处理几个状况的时候,用这函数就很合适,类似于多线程吧~
 楼主| 发表于 2010-12-18 20:38:00 | 显示全部楼层
谢谢飘云的热情帮助
发表于 2010-12-19 21:27:14 | 显示全部楼层
帮助里说的很清楚了哦。。。
发表于 2010-12-19 21:41:33 | 显示全部楼层
AdlibRegister
就是给自定义函数注册添加一个定时执行功能,从应用上来说完全是等同于settimer的。LZ你的问题就是因为没有保持脚本处于运行状态,注册定时器之后,脚本就退出了,自然就不能达到效果
AU3中使用settimer来添加定时器,也是一样需要保持脚本处于运行状态才可以的
发表于 2010-12-19 21:44:25 | 显示全部楼层
发一段settimer的实例


Global $t2, $t3 = 1
$Form1 = GUICreate("API定时器实例", 272, 139)
$Label1 = GUICtrlCreateLabel("00:00:00:00", 8, 8, 146, 17);时间
$Label2 = GUICtrlCreateLabel("0", 8, 56, 150, 17);+1
$Label3 = GUICtrlCreateLabel("", 8, 104, 148, 17);2的自乘
$Button1 = GUICtrlCreateButton("关闭定时器1", 168, 8, 89, 25, 0)
$Button2 = GUICtrlCreateButton("关闭定时器2", 168, 48, 89, 25, 0)
$Button3 = GUICtrlCreateButton("关闭定时器3", 168, 96, 89, 25, 0)
GUISetState(@SW_SHOW)

$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword");创建自定义函数Timer的回调,API定时器函数SetTimer需要
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer));1000毫秒执行一次
$Timer2DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 200, "ptr", DllCallbackGetPtr($Timer));200毫秒执行一次
$Timer3DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 2000, "ptr", DllCallbackGetPtr($Timer));2000毫秒执行一次

While 1
        Switch GUIGetMsg()
                Case - 3
                        ExitLoop
                Case $Button1
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0]);关闭定时器
                Case $Button2
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer2DLL[0])
                Case $Button3
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer3DLL[0])
        EndSwitch
WEnd
GUIDelete()
DllCallbackFree($Timer);关闭回调

Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        Switch $idEvent;根据定时器ID来进行操作
                Case $TimerDLL[0]
                        GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC);更新时间
                Case $Timer2DLL[0]
                        $t2 += 1
                        GUICtrlSetData($Label2, $t2);更新+1
                Case $Timer3DLL[0]
                        $t3 *= 2
                        GUICtrlSetData($Label3, $t3);更新2的自乘
                EndSwitch
EndFunc
发表于 2010-12-19 21:46:40 | 显示全部楼层
AdlibRegister的实例


#include <GUIConstantsEx.au3>
Local $n1, $n2, $msg

GUICreate("内置定时器", 250, 250)
$n1 = GUICtrlCreateIcon("shell32.dll", 7, 20, 15, 32, 32);icon控件
$n2 = GUICtrlCreateIcon("shell32.dll", 7, 20, 55, 32, 32)
GUISetState()

AdlibRegister("n1",1000);设置定时器1,函数n1,时间1000毫秒
AdlibRegister("n2",300);定时器2,函数n2,时间300毫秒

While 1
    $msg = GUIGetMsg()    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
AdlibUnRegister("n1");卸载关联在n1函数的定时器
AdlibUnRegister("n2")

Func n1()
        GUICtrlSetImage($n1, "shell32.dll", Random(1,10,1)) 
;在这里利用GUICtrlSetImage实现更换图标的功能,具体参数看帮助
EndFunc

Func n2()
        GUICtrlSetImage($n2, "shell32.dll", Random(1,30,1))
EndFunc
 楼主| 发表于 2010-12-20 22:27:39 | 显示全部楼层
298311657果然是高手,实例更容易叫人了解学习
发表于 2011-2-7 05:32:38 | 显示全部楼层
问题是AdlibRegister跟settimer有何不同?
发表于 2012-1-11 17:14:49 | 显示全部楼层
谢谢楼上兄弟们的回帖,收益良多!!!
发表于 2012-6-22 20:38:09 | 显示全部楼层
好贴,收藏了!
发表于 2012-6-22 22:57:53 | 显示全部楼层
好贴,收藏了!
发表于 2012-6-23 00:04:43 | 显示全部楼层
其实我想知道AdlibRegister的BUG修正没有....
发表于 2014-8-22 17:12:13 | 显示全部楼层
本帖最后由 yuko4632 于 2014-8-22 20:29 编辑

发错了

#include <Date.au3>
AdlibRegister("_A",100)
AdlibRegister("_B",300)
;...

While 1
        
WEnd

Func _A()
        ConsoleWrite("输出A" &@LF)
    MsgBox(48, "A!", "A错误。", 15)
EndFunc 

Func _B()

$sNewDate2 = _DateAdd('s', 5, _NowCalc()) ;定义运行周期
        While 1
                Sleep(1000)
                $nowdate = _NowCalc() ;获取当前时间
                If $nowdate = $sNewDate2 Then
                          ConsoleWrite("输出B" &@LF)
              MsgBox(48, "B!", "B错误。", 15)
                        $sNewDate2 = _DateAdd('s', 5, _NowCalc()) ;重新定义运行周期,以进行下次任务
                EndIf
        WEnd
EndFunc 

上面会出现阻断,调用多个AdlibRegister,发现A一定不能执行下去。B能正常执行。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-21 16:42 , Processed in 0.070241 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表