一个多线程的例子 公共模块: Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongSub main() Load Form1 Form1.Show End Sub Public Sub c1() ....... End SubPublic Sub c2() ...... End Sub Private hthread1 As Long Private hthread2 As Long Private ithread1 As Long Private ithread2 As LongPrivate Sub Command1_Click()ithread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1) ithread2 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c2, ByVal 0&, ByVal 0&, hthread1) CloseHandle ithread1 CloseHandle ithread2 End Sub
这种资料网上很多。
不过,VB.NET做多线程很爽。
公共模块:
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongSub main()
Load Form1
Form1.Show
End Sub
Public Sub c1()
.......
End SubPublic Sub c2()
......
End Sub
Private hthread1 As Long
Private hthread2 As Long
Private ithread1 As Long
Private ithread2 As LongPrivate Sub Command1_Click()ithread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1)
ithread2 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c2, ByVal 0&, ByVal 0&, hthread1)
CloseHandle ithread1
CloseHandle ithread2 End Sub