主窗体.frm

来自「VB多线程源代码」· FRM 代码 · 共 120 行

FRM
120
字号
VERSION 5.00
Begin VB.Form 主窗体 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "多线程示例"
   ClientHeight    =   1950
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5115
   Icon            =   "主窗体.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   1950
   ScaleWidth      =   5115
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton 结束线程按钮 
      Caption         =   "结束线程"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   840
      Width           =   1335
   End
   Begin VB.CommandButton 创建线程按钮 
      Caption         =   "创建线程"
      Height          =   375
      Left            =   3600
      TabIndex        =   2
      Top             =   240
      Width           =   1335
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "共同:"
      Height          =   180
      Left            =   240
      TabIndex        =   6
      Top             =   1440
      Width           =   540
   End
   Begin VB.Label tr 
      BackColor       =   &H00E0E0E0&
      Caption         =   "0"
      Height          =   180
      Left            =   960
      TabIndex        =   5
      Top             =   1440
      Width           =   2370
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "线程2:"
      Height          =   180
      Left            =   240
      TabIndex        =   4
      Top             =   720
      Width           =   630
   End
   Begin VB.Label tr2 
      BackColor       =   &H00E0E0E0&
      Height          =   180
      Left            =   960
      TabIndex        =   3
      Top             =   720
      Width           =   2370
   End
   Begin VB.Label tr1 
      BackColor       =   &H00E0E0E0&
      Height          =   180
      Left            =   960
      TabIndex        =   1
      Top             =   315
      Width           =   2370
   End
   Begin VB.Label l 
      AutoSize        =   -1  'True
      Caption         =   "线程1:"
      Height          =   180
      Left            =   240
      TabIndex        =   0
      Top             =   315
      Width           =   630
   End
End
Attribute VB_Name = "主窗体"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Form_Load()
    Call InitializeCriticalSection(g_cs)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    结束线程
    Call DeleteCriticalSection(g_cs)
End Sub

Public Sub 显示结束标语()
    tr = tr & ":线程结束"
End Sub

Private Sub 创建线程按钮_Click()
    创建线程
    启动线程
    按钮切换 False
End Sub

Private Sub 结束线程按钮_Click()
    结束线程
    按钮切换 True
End Sub

Private Sub 按钮切换(Enabled As Boolean)
    创建线程按钮.Enabled = Enabled
    结束线程按钮.Enabled = Not Enabled
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?