窗体中的代码:
Option Explicit
’开始
Private Sub Command1_Click()
On Error Resume Next
With myThreadleft
.Initialize AddressOf Fillleft ’传递过程地址给线程
.ThreadEnabled = True
End With
With myThreadright
.Initialize AddressOf Fillright
.ThreadEnabled = True
End With
With myThreadbottom
.Initialize AddressOf Fillbottom
.ThreadEnabled = True
End With
MsgBox "多线程正在运行...,看看图片框控件的变色效果!", 64, "信息"
’终止线程运行
Set myThreadleft = Nothing
Set myThreadright = Nothing
Set myThreadbottom = Nothing
End Sub
’结束
Private Sub Command2_Click()
Unload Me
End Sub
模块中的代码:
Option Explicit
’时间计数API
Private Declare Function GetTickCount Lib "kernel32" () As Long
’声明cls_thread类的对象变量
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 ’延时10毫秒,下同
Wend
Next
Set myThreadleft = Nothing ’如果循环结束则终止当前线程运行,下同
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)
本文来自 280文秘网(https://www.it280.com),转载请保留网址和出处
【VB创建多线程应用程序(二)】相关文章:
Vb中控件的自动排列03-23
2018国家电网新大纲财会类市场模拟卷多选题(二)03-23
儿童舞蹈教程:国标新手上路03-23
生态护坡技术创新措施论文03-23
2018湖南省农村信用社联合社招聘科技专业人才拟聘公告03-23
at(the)least和not(in)the least用法区别 相似词语辨析(17)03-23
5月11日开始报名!2023年内蒙古鄂尔多斯市乌审旗秋季幼升小入学条件和流程公布03-23
普通中学生入团志愿书500字通用范文03-23
计算机应用技术英语简历范文大全03-23
初中学校德育课程整合实施探究03-23
难忘的一件事初二作文700字03-23
