【ithub 源码】【php追溯源码】【魔龙诀源码】vb6程序源码_vb6.0编程代码大全

2024-12-29 06:10:29 来源:代币程序源码 分类:综合

1.用vb6可不可以设计多线程序的应用程序,如何实现

vb6程序源码_vb6.0编程代码大全

用vb6可不可以设计多线程序的应用程序,如何实现

       å¤šçº¿ç¨‹æ˜¯å¯ä»¥å•Šï¼Œåªæ˜¯ä¸å¤ªå®‰å…¨ï¼Œå®¹æ˜“非法操作,

        源代码如下:

       çª—体中的代码:

       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 "多线程正在运行...,看看图片框控件的变色效果!",程序ithub 源码 , "信息"

       '终止线程运行

        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 "kernel" () 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

        DoEvents

        Bkgcolor = Longcounter Mod

        Form1.Picture1.BackColor = RGB(Bkgcolor, 0, 0)

        LongTick = GetTickCount

        While GetTickCount - LongTick < '延时毫秒,下同

        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

        DoEvents

        Bkgcolor = Longcounter Mod

        Form1.Picture2.BackColor = RGB(0, Bkgcolor, 0)

        LongTickValue = GetTickCount

        While GetTickCount - LongTickValue <

        Wend

        Next

       Set myThreadright = Nothing

       End Sub

       Public Sub Fillbottom()

        Static Bkgcolor As Long

        Dim LongTick As Long, Longcounter As Long

        On Error Resume Next

        For Longcounter = 0 To

        DoEvents

        Bkgcolor = Longcounter Mod

        Form1.Picture3.BackColor = RGB(0, 0, Bkgcolor)

        LongTick = GetTickCount

        While GetTickCount - LongTick <

        Wend

        Next

        Set myThreadright = Nothing

       End Sub

       ç±»æ¨¡å—中的代码:

       '功能:创建多线程类,用于初始化线程。 类名:cls_Thread

       '参数:LongPointFunction 用于接收主调过程传递过来的函数地址值

       '调用方法:1.声明线程类对象变量 Dim mythread as cls_Thread

       ' 2.调用形式:With mythread

       ' .Initialize AddressOf 自定义过程或函数名 '(初始化线程) .

       ' .ThreadEnabled = True '(设置线程是否激活)

       ' End With

       ' 3.终止调用: Set mythread = Nothing

       ' Crate By : 陈宇 On .5. Copyright(C).Ldt By CY-soft --

       ' Email:4y4ycoco@.com

       ' Test On: VB6.0+Win AND VB6.0+WinXP It's Pass !

       Option Explicit

       '创建线程API

       'æ­¤API经过改造,lpThreadAttributes改为Any型,lpStartAddress改为传值引用:

       '因为函数的入口地址由形参变量传递,如果用传址那将传递形参变量的地址而不是函数的入口地址

       Private Declare Function CreateThread Lib "kernel" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, LpthreadId As Long) As Long

       '终止线程API

       Private Declare Function TerminateThread Lib "kernel" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long

       '激活线程API

       Private Declare Function ResumeThread Lib "kernel" (ByVal hThread As Long) As Long

       '挂起线程API

       Private Declare Function SuspendThread Lib "kernel" (ByVal hThread As Long) As Long

       Private Const CREATE_SUSPENDED = &H4 '线程挂起常量

       '自定义线程结构类型

       Private Type udtThread

        Handle As Long

        Enabled As Boolean

       End Type

       Private meTheard As udtThread

       '初始化线程

       Public Sub Initialize(ByVal LongPointFunction As Long)

        Dim LongStackSize As Long, LongCreationFlags As Long, LpthreadId As Long, LongNull As Long

        On Error Resume Next

        LongNull = 0

        LongStackSize = 0

        LongCreationFlags = CREATE_SUSPENDED '创建线程后先挂起,由程序激活线程

       '创建线程并返线程句柄

        meTheard.Handle = CreateThread(LongNull, LongStackSize, ByVal LongPointFunction, LongNull, LongCreationFlags, LpthreadId)

       If meTheard.Handle = LongNull Then

        MsgBox "线程创建失败!", , "错误"

        End If

       End Sub

       '获取线程是否激活属性

       Public Property Get ThreadEnabled() As Boolean

        On Error Resume Next

        Enabled = meTheard.Enabled

       End Property

       '设置线程是否激活属性

       Public Property Let ThreadEnabled(ByVal Newvalue As Boolean)

        On Error Resume Next

        '若激活线程(Newvalue为真)设为TRUE且此线程原来没有激活时激活此线程

        If Newvalue And (Not meTheard.Enabled) Then

        ResumeThread meTheard.Handle

        meTheard.Enabled = True

        Else '若激活线程(Newvalue为真)且此线程原来已激活则挂起此线程

        If meTheard.Enabled Then

        SuspendThread meTheard.Handle

        meTheard.Enabled = False

        End If

        End If

       End Property

       '终止线程事件

       Private Sub Class_Terminate()

        On Error Resume Next

        Call TerminateThread(meTheard.Handle, 0)

       End Sub

更多资讯请点击:综合

推荐资讯

77位諾獎得主聯名 反對特朗普提名的衞生部長

香港文匯報訊 美國媒體當地時間9日報道,77位諾貝爾獎得主當天簽署公開信,敦促國會參議院不要批准小羅伯特·肯尼迪出任美國衞生與公眾服務部HHS)部長。這77位來自醫學、化學、物理學和經濟學等不同領域的

冰雪传奇手游源码库_冰雪传奇 源码

1.H5游戏架设经验分享H5游戏架设经验分享 首先,我不是专业做游戏的,只是在一些机缘巧合下,发现可以自己架设游戏做GM,后台免费发送游戏中的各种充值和道具,然后在游戏里为所欲为,各种榜一秒杀,简

宁波桶装水防伪溯源码好处_桶装水二维码防伪

1.苗西南矿泉水怎么样_云南理工好还是西南林大好苗西南矿泉水怎么样_云南理工好还是西南林大好 苗西南矿泉水怎么样? 贵州苗西南饮品有限公司是一家从事瓶桶)装饮用矿泉水生产的企业,有着得天独厚的