源代碼如下:
窗體中的代碼:
Option Explicit
’開(kāi)始
Private Sub Command1_Click()
On Error Resume Next
With myThreadleft
.Initialize AddressOf Fillleft ’傳遞過(guò)程地址給線(xiàn)程
.ThreadEnabled = True
End With
With myThreadright
.Initialize AddressOf Fillright
.ThreadEnabled = True
End With
With myThreadbottom
.Initialize AddressOf Fillbottom
.ThreadEnabled = True
End With
MsgBox "多線(xiàn)程正在運(yùn)行...,看看圖片框控件的變色效果!", 64, "信息"
’終止線(xiàn)程運(yùn)行
Set myThreadleft = Nothing
Set myThreadright = Nothing
Set myThreadbottom = Nothing
End Sub
’結(jié)束
Private Sub Command2_Click()
Unload Me
End Sub
模塊中的代碼:
Option Explicit
’時(shí)間計(jì)數(shù)API
Private Declare Function GetTickCount Lib "kernel32" () As Long
’聲明cls_thread類(lèi)的對(duì)象變量
Public myThreadleft As New cls_thread, myThreadright As New cls_thread, myThreadbottom As New cls_thread
Sub Main()
Load Form1
Form1.Show
End Sub
Public Sub Fillleft()
Static Bkgcolor As Long
Dim LongTick As Long, Longcounter As Long
On Error Resume Next
For Longcounter = 0 To 3000
DoEvents
Bkgcolor = Longcounter Mod 256
Form1.Picture1.BackColor = RGB(Bkgcolor, 0, 0)
LongTick = GetTickCount
While GetTickCount - LongTick < 10 ’延時(shí)10毫秒,下同
Wend
Next
Set myThreadleft = Nothing ’如果循環(huán)結(jié)束則終止當(dāng)前線(xiàn)程運(yùn)行,下同
End Sub
Public Sub Fillright()
Static Bkgcolor As Long
Dim LongTickValue As Long, Longcounter As Long
On Error Resume Next
For Longcounter = 0 To 3000
DoEvents
Bkgcolor = Longcounter Mod 256
Form1.Picture2.BackColor = RGB(0, Bkgcolor, 0)
窗體中的代碼:
Option Explicit
’開(kāi)始
Private Sub Command1_Click()
On Error Resume Next
With myThreadleft
.Initialize AddressOf Fillleft ’傳遞過(guò)程地址給線(xiàn)程
.ThreadEnabled = True
End With
With myThreadright
.Initialize AddressOf Fillright
.ThreadEnabled = True
End With
With myThreadbottom
.Initialize AddressOf Fillbottom
.ThreadEnabled = True
End With
MsgBox "多線(xiàn)程正在運(yùn)行...,看看圖片框控件的變色效果!", 64, "信息"
’終止線(xiàn)程運(yùn)行
Set myThreadleft = Nothing
Set myThreadright = Nothing
Set myThreadbottom = Nothing
End Sub
’結(jié)束
Private Sub Command2_Click()
Unload Me
End Sub
模塊中的代碼:
Option Explicit
’時(shí)間計(jì)數(shù)API
Private Declare Function GetTickCount Lib "kernel32" () As Long
’聲明cls_thread類(lèi)的對(duì)象變量
Public myThreadleft As New cls_thread, myThreadright As New cls_thread, myThreadbottom As New cls_thread
Sub Main()
Load Form1
Form1.Show
End Sub
Public Sub Fillleft()
Static Bkgcolor As Long
Dim LongTick As Long, Longcounter As Long
On Error Resume Next
For Longcounter = 0 To 3000
DoEvents
Bkgcolor = Longcounter Mod 256
Form1.Picture1.BackColor = RGB(Bkgcolor, 0, 0)
LongTick = GetTickCount
While GetTickCount - LongTick < 10 ’延時(shí)10毫秒,下同
Wend
Next
Set myThreadleft = Nothing ’如果循環(huán)結(jié)束則終止當(dāng)前線(xiàn)程運(yùn)行,下同
End Sub
Public Sub Fillright()
Static Bkgcolor As Long
Dim LongTickValue As Long, Longcounter As Long
On Error Resume Next
For Longcounter = 0 To 3000
DoEvents
Bkgcolor = Longcounter Mod 256
Form1.Picture2.BackColor = RGB(0, Bkgcolor, 0)

