在Vb下实现多线程

类别:VB语言 点击:0 评论:0 推荐:

新建一Module
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 Long

Sub main()
   Load Form1
   Form1.Show
End Sub
Public Sub c1()
    .......
End Sub

Public Sub c2()
   ...... 
End Sub

新建一窗体

Private hthread1 As Long
Private hthread2 As Long
Private ithread1 As Long
Private ithread2 As Long

Private Sub Command1_Click()

ithread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1)  --创建线程一
ithread2 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1)  --创建线程二

CloseHandle ithread1   --关闭线程一
CloseHandle ithread2   --关闭线程二

End Sub

Private Sub Form_Load()

End Sub

本文地址:http://com.8s8s.com/it/it6491.htm