找回密码
 加入
搜索
查看: 63849|回复: 116

[原创] AU3多线程实例 GUI+MsgBox

 火... [复制链接]
发表于 2009-2-4 09:51:15 | 显示全部楼层 |阅读模式
MsgBox版本:
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 5000, "ptr", DllCallbackGetPtr($Timer))
$Timer2 = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$Timer2DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 8000, "ptr", DllCallbackGetPtr($Timer2))
$Timer3 = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$Timer3DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10000, "ptr", DllCallbackGetPtr($Timer3))
While 1
        GUIGetMsg()
WEnd
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $TimerDLL[0] Then
                MsgBox(0,"","线程1")
        ElseIf $idEvent = $Timer2DLL[0] Then
                MsgBox(0,"","线程2")
        ElseIf $idEvent = $Timer3DLL[0] Then
                MsgBox(0,"","线程3")
        EndIf
EndFunc


GUI版本(较强大):
$Form1 = GUICreate("多线程实例", 272, 139, -1, -1)
$Label1 = GUICtrlCreateLabel("00:00:00:00", 8, 8, 146, 17)
$Label2 = GUICtrlCreateLabel("0", 8, 56, 150, 17)
$Label3 = GUICtrlCreateLabel("", 8, 104, 148, 17)
$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)
Global $t2, $t3 = 1
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
$Timer2 = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$Timer2DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 200, "ptr", DllCallbackGetPtr($Timer2))
$Timer3 = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$Timer3DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 500, "ptr", DllCallbackGetPtr($Timer3))
While 1
        Switch GUIGetMsg()
                Case - 3
                        Exit
                Case $Button1
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL)
                        DllCallbackFree($Timer)
                Case $Button2
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer2DLL)
                        DllCallbackFree($Timer2)
                Case $Button3
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer3DLL)
                        DllCallbackFree($Timer3)
        EndSwitch
WEnd
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $TimerDLL[0] Then
                GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC)
        ElseIf $idEvent = $Timer2DLL[0] Then
                $t2 += 1
                GUICtrlSetData($Label2, $t2)
        ElseIf $idEvent = $Timer3DLL[0] Then
                $t3 *= 2
                GUICtrlSetData($Label3, $t3)
        EndIf
EndFunc


3.3.0.0版本正常运行

评分

参与人数 1金钱 +10 贡献 +5 收起 理由
116154801 + 10 + 5

查看全部评分

发表于 2009-2-4 18:07:49 | 显示全部楼层
学习。。。。。。
发表于 2009-2-4 21:27:43 | 显示全部楼层
Thanks
发表于 2009-2-5 00:11:35 | 显示全部楼层
收下學習...
感謝您的分享 ^_^
发表于 2009-2-5 08:51:30 | 显示全部楼层
收藏了
发表于 2009-2-8 09:00:50 | 显示全部楼层
学习了!非常感谢!
发表于 2009-2-8 09:38:29 | 显示全部楼层
拿下
发表于 2009-2-8 14:16:45 | 显示全部楼层
能不能讲解一下?
发表于 2009-2-8 14:42:20 | 显示全部楼层
厉害,学习下
 楼主| 发表于 2009-2-8 19:22:55 | 显示全部楼层

回复 8# 298311657 的帖子

汗,我觉得我的代码已经很简单了。。。实在不会就照抄算了。。。
发表于 2009-2-9 13:17:55 | 显示全部楼层
代码确实很简单,一看就懂,但是是如何实现多线程的,却理解不了,所有希望能把原理讲解一下~
发表于 2009-2-10 21:24:57 | 显示全部楼层
看来看去我只看到3个通过settimer()函数set出来的3个计时器, 第一个例程set了还没kill呢....
这和多线程有什么关系呢?

初学au3,不知道有没象CreateThread() / _beginthread()之类的创建多线程方法.
发表于 2009-2-11 11:05:03 | 显示全部楼层
多进程模拟多线程
 楼主| 发表于 2009-2-11 12:42:51 | 显示全部楼层

回复 12# lambochan 的帖子

AU3本身不支持多线程,但是如果是单线程你认为可以实现这些嘛?
 楼主| 发表于 2009-2-11 12:43:45 | 显示全部楼层

回复 11# 298311657 的帖子

详情查看Windows API手册
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-24 13:17 , Processed in 0.197465 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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