sdc7 发表于 2014-3-29 20:53:00

单线程··感觉实际意义不大··AdlibRegister 最大的好处是在执行别的程序的空闲时间 它可以见逢插针·但是主线程忙 的时候·AdlibRegister有只能等那扯淡了·

smooth 发表于 2014-3-30 07:25:17

回复 16# sdc7

那你看,这个是不是属于多线程?

$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 Then
                GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC)
        ElseIf $idEvent = $Timer2DLL Then
                $t2 += 1
                GUICtrlSetData($Label2, $t2)
        ElseIf $idEvent = $Timer3DLL Then
                $t3 *= 2
                GUICtrlSetData($Label3, $t3)
        EndIf
EndFunc   ;==>Timer

sdc7 发表于 2014-3-30 20:37:54

你的函数 用的API 这个你可以看下P版的书跟AdlibRegister是一样的 伪多线程·

anythinging 发表于 2019-8-18 21:21:16

这个好,应该有大用处,是不是可以理解为程序运行过程中,同时在后台运行一个功能?
页: 1 [2]
查看完整版本: [已解决]请教注册函数AdlibRegister阻止代码继续执行如何解决?