home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vbthread / frmmulti.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-06-20  |  14.6 KB  |  463 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMultiThread 
  3.    Caption         =   "VBThread Demo"
  4.    ClientHeight    =   4245
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6990
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4245
  10.    ScaleWidth      =   6990
  11.    StartUpPosition =   2  'CenterScreen
  12.    Begin VB.TextBox txtParam 
  13.       Height          =   315
  14.       Index           =   2
  15.       Left            =   2640
  16.       Locked          =   -1  'True
  17.       TabIndex        =   29
  18.       Text            =   "0"
  19.       Top             =   1440
  20.       Width           =   615
  21.    End
  22.    Begin VB.TextBox txtParam 
  23.       Height          =   315
  24.       Index           =   1
  25.       Left            =   2640
  26.       Locked          =   -1  'True
  27.       TabIndex        =   28
  28.       Text            =   "0"
  29.       Top             =   1020
  30.       Width           =   615
  31.    End
  32.    Begin VB.TextBox txtParam 
  33.       Height          =   315
  34.       Index           =   0
  35.       Left            =   2640
  36.       Locked          =   -1  'True
  37.       TabIndex        =   27
  38.       Text            =   "0"
  39.       Top             =   600
  40.       Width           =   615
  41.    End
  42.    Begin VB.TextBox txtStarted 
  43.       Height          =   315
  44.       Index           =   2
  45.       Left            =   4200
  46.       Locked          =   -1  'True
  47.       TabIndex        =   22
  48.       Text            =   "False"
  49.       Top             =   1440
  50.       Width           =   615
  51.    End
  52.    Begin VB.TextBox txtStarted 
  53.       Height          =   315
  54.       Index           =   1
  55.       Left            =   4200
  56.       Locked          =   -1  'True
  57.       TabIndex        =   21
  58.       Text            =   "False"
  59.       Top             =   1020
  60.       Width           =   615
  61.    End
  62.    Begin VB.TextBox txtStarted 
  63.       Height          =   315
  64.       Index           =   0
  65.       Left            =   4200
  66.       Locked          =   -1  'True
  67.       TabIndex        =   20
  68.       Text            =   "False"
  69.       Top             =   600
  70.       Width           =   615
  71.    End
  72.    Begin VB.TextBox txtLoaded 
  73.       Height          =   315
  74.       Index           =   2
  75.       Left            =   3420
  76.       Locked          =   -1  'True
  77.       TabIndex        =   19
  78.       Text            =   "False"
  79.       Top             =   1440
  80.       Width           =   615
  81.    End
  82.    Begin VB.TextBox txtLoaded 
  83.       Height          =   315
  84.       Index           =   1
  85.       Left            =   3420
  86.       Locked          =   -1  'True
  87.       TabIndex        =   18
  88.       Text            =   "False"
  89.       Top             =   1020
  90.       Width           =   615
  91.    End
  92.    Begin VB.TextBox txtLoaded 
  93.       Height          =   315
  94.       Index           =   0
  95.       Left            =   3420
  96.       Locked          =   -1  'True
  97.       TabIndex        =   17
  98.       Text            =   "False"
  99.       Top             =   600
  100.       Width           =   615
  101.    End
  102.    Begin VB.ComboBox cboPriority2 
  103.       Enabled         =   0   'False
  104.       Height          =   315
  105.       ItemData        =   "frmMultiThread.frx":0000
  106.       Left            =   4980
  107.       List            =   "frmMultiThread.frx":001E
  108.       Style           =   2  'Dropdown List
  109.       TabIndex        =   10
  110.       Top             =   1440
  111.       Width           =   1695
  112.    End
  113.    Begin VB.ComboBox cboPriority1 
  114.       Enabled         =   0   'False
  115.       Height          =   315
  116.       ItemData        =   "frmMultiThread.frx":0069
  117.       Left            =   4980
  118.       List            =   "frmMultiThread.frx":0087
  119.       Style           =   2  'Dropdown List
  120.       TabIndex        =   9
  121.       Top             =   1020
  122.       Width           =   1695
  123.    End
  124.    Begin VB.ComboBox cboPriority0 
  125.       Enabled         =   0   'False
  126.       Height          =   315
  127.       ItemData        =   "frmMultiThread.frx":00D2
  128.       Left            =   4980
  129.       List            =   "frmMultiThread.frx":00F0
  130.       Style           =   2  'Dropdown List
  131.       TabIndex        =   8
  132.       Top             =   600
  133.       Width           =   1695
  134.    End
  135.    Begin VB.TextBox txtText 
  136.       Height          =   315
  137.       Index           =   2
  138.       Left            =   1275
  139.       Locked          =   -1  'True
  140.       TabIndex        =   7
  141.       Text            =   "0"
  142.       Top             =   1440
  143.       Width           =   1215
  144.    End
  145.    Begin VB.TextBox txtText 
  146.       Height          =   315
  147.       Index           =   1
  148.       Left            =   1275
  149.       Locked          =   -1  'True
  150.       TabIndex        =   6
  151.       Text            =   "0"
  152.       Top             =   1020
  153.       Width           =   1215
  154.    End
  155.    Begin VB.TextBox txtText 
  156.       Height          =   315
  157.       Index           =   0
  158.       Left            =   1275
  159.       Locked          =   -1  'True
  160.       TabIndex        =   5
  161.       Text            =   "0"
  162.       Top             =   600
  163.       Width           =   1215
  164.    End
  165.    Begin VB.CommandButton Command1 
  166.       Caption         =   "Show Thread Status"
  167.       Enabled         =   0   'False
  168.       Height          =   375
  169.       Left            =   2520
  170.       TabIndex        =   4
  171.       Top             =   3720
  172.       Width           =   1995
  173.    End
  174.    Begin VB.CommandButton Command5 
  175.       Caption         =   "Pause"
  176.       Enabled         =   0   'False
  177.       Height          =   375
  178.       Left            =   3525
  179.       TabIndex        =   3
  180.       Top             =   3240
  181.       Width           =   975
  182.    End
  183.    Begin VB.CommandButton Command4 
  184.       Caption         =   "Start"
  185.       Enabled         =   0   'False
  186.       Height          =   375
  187.       Left            =   2505
  188.       TabIndex        =   2
  189.       Top             =   3240
  190.       Width           =   975
  191.    End
  192.    Begin VB.CommandButton Command3 
  193.       Caption         =   "Load"
  194.       Height          =   375
  195.       Left            =   1478
  196.       TabIndex        =   1
  197.       Top             =   3240
  198.       Width           =   975
  199.    End
  200.    Begin VB.CommandButton Command2 
  201.       Caption         =   "Unload"
  202.       Enabled         =   0   'False
  203.       Height          =   375
  204.       Left            =   4538
  205.       TabIndex        =   0
  206.       Top             =   3240
  207.       Width           =   975
  208.    End
  209.    Begin VB.Label Label3 
  210.       AutoSize        =   -1  'True
  211.       Caption         =   "Param"
  212.       Height          =   195
  213.       Index           =   3
  214.       Left            =   2640
  215.       TabIndex        =   30
  216.       Top             =   240
  217.       Width           =   450
  218.    End
  219.    Begin VB.Label Label6 
  220.       AutoSize        =   -1  'True
  221.       Caption         =   "Status are monitored with Thread's events !!!"
  222.       Height          =   195
  223.       Left            =   1890
  224.       TabIndex        =   26
  225.       Top             =   2400
  226.       Width           =   3150
  227.    End
  228.    Begin VB.Label Label5 
  229.       AutoSize        =   -1  'True
  230.       Caption         =   "Refer to the code to see how it was implemented with VBThread."
  231.       Height          =   195
  232.       Left            =   1200
  233.       TabIndex        =   25
  234.       Top             =   2700
  235.       Width           =   4590
  236.    End
  237.    Begin VB.Label Label3 
  238.       AutoSize        =   -1  'True
  239.       Caption         =   "Started"
  240.       Height          =   195
  241.       Index           =   2
  242.       Left            =   4200
  243.       TabIndex        =   24
  244.       Top             =   240
  245.       Width           =   510
  246.    End
  247.    Begin VB.Label Label3 
  248.       AutoSize        =   -1  'True
  249.       Caption         =   "Loaded"
  250.       Height          =   195
  251.       Index           =   1
  252.       Left            =   3420
  253.       TabIndex        =   23
  254.       Top             =   240
  255.       Width           =   540
  256.    End
  257.    Begin VB.Label Label4 
  258.       AutoSize        =   -1  'True
  259.       Caption         =   "All of the loops is done in its own thread, without 'DoEvents' or another interupt ."
  260.       Height          =   195
  261.       Left            =   683
  262.       TabIndex        =   16
  263.       Top             =   2100
  264.       Width           =   5625
  265.    End
  266.    Begin VB.Label Label3 
  267.       AutoSize        =   -1  'True
  268.       Caption         =   "Loop"
  269.       Height          =   195
  270.       Index           =   0
  271.       Left            =   1275
  272.       TabIndex        =   15
  273.       Top             =   240
  274.       Width           =   360
  275.    End
  276.    Begin VB.Label Label2 
  277.       AutoSize        =   -1  'True
  278.       Caption         =   "Priority"
  279.       Height          =   195
  280.       Left            =   4980
  281.       TabIndex        =   14
  282.       Top             =   240
  283.       Width           =   465
  284.    End
  285.    Begin VB.Label Label1 
  286.       AutoSize        =   -1  'True
  287.       Caption         =   "Function 3"
  288.       Height          =   195
  289.       Index           =   2
  290.       Left            =   315
  291.       TabIndex        =   13
  292.       Top             =   1500
  293.       Width           =   750
  294.    End
  295.    Begin VB.Label Label1 
  296.       AutoSize        =   -1  'True
  297.       Caption         =   "Function 2"
  298.       Height          =   195
  299.       Index           =   1
  300.       Left            =   315
  301.       TabIndex        =   12
  302.       Top             =   1080
  303.       Width           =   750
  304.    End
  305.    Begin VB.Label Label1 
  306.       AutoSize        =   -1  'True
  307.       Caption         =   "Function 1"
  308.       Height          =   195
  309.       Index           =   0
  310.       Left            =   315
  311.       TabIndex        =   11
  312.       Top             =   660
  313.       Width           =   750
  314.    End
  315. Attribute VB_Name = "frmMultiThread"
  316. Attribute VB_GlobalNameSpace = False
  317. Attribute VB_Creatable = False
  318. Attribute VB_PredeclaredId = True
  319. Attribute VB_Exposed = False
  320. Dim WithEvents myThread0 As ThreadVB
  321. Attribute myThread0.VB_VarHelpID = -1
  322. Dim WithEvents myThread1 As ThreadVB
  323. Attribute myThread1.VB_VarHelpID = -1
  324. Dim WithEvents myThread2 As ThreadVB
  325. Attribute myThread2.VB_VarHelpID = -1
  326. Private Sub cboPriority0_Click()
  327.   On Error Resume Next
  328.   myThread0.fnPriority = cboPriority0.ItemData(cboPriority0.ListIndex)
  329. End Sub
  330. Private Sub cboPriority1_Click()
  331.   On Error Resume Next
  332.   myThread1.fnPriority = cboPriority1.ItemData(cboPriority1.ListIndex)
  333. End Sub
  334. Private Sub cboPriority2_Click()
  335.   On Error Resume Next
  336.   myThread2.fnPriority = cboPriority2.ItemData(cboPriority2.ListIndex)
  337. End Sub
  338. Private Sub Command1_Click()
  339.   Dim strValue As String
  340.   strValue = "FunctionNo;fnAddress;fnParam;fnLoaded;fnStarted;hdlThread;Tag;ThreadID;Priority" & vbCrLf
  341.   strValue = strValue & "1" & ";" & myThread0.fnAddress & ";" & myThread0.fnParam & ";" & myThread0.fnLoaded & ";" & myThread0.fnStarted & ";" & myThread0.hdlThread & ";" & myThread0.Tag & ";" & myThread0.ThreadID & ";" & myThread0.fnPriority & vbCrLf
  342.   strValue = strValue & "2" & ";" & myThread1.fnAddress & ";" & myThread1.fnParam & ";" & myThread1.fnLoaded & ";" & myThread1.fnStarted & ";" & myThread1.hdlThread & ";" & myThread1.Tag & ";" & myThread1.ThreadID & ";" & myThread1.fnPriority & vbCrLf
  343.   strValue = strValue & "3" & ";" & myThread2.fnAddress & ";" & myThread2.fnParam & ";" & myThread2.fnLoaded & ";" & myThread2.fnStarted & ";" & myThread2.hdlThread & ";" & myThread2.Tag & ";" & myThread2.ThreadID & ";" & myThread2.fnPriority & vbCrLf
  344.   MsgBox strValue, vbOKOnly + vbInformation, "Thread Info"
  345. End Sub
  346. Private Sub Command2_Click()
  347.   Command1.Enabled = False
  348.   Command2.Enabled = False
  349.   Command3.Enabled = True
  350.   Command4.Enabled = False
  351.   Command5.Enabled = False
  352.   cboPriority0.Enabled = False
  353.   cboPriority1.Enabled = False
  354.   cboPriority2.Enabled = False
  355.   cboPriority0.ListIndex = 3
  356.   cboPriority1.ListIndex = 3
  357.   cboPriority2.ListIndex = 3
  358.   myThread0.UnloadFunction
  359.   myThread1.UnloadFunction
  360.   myThread2.UnloadFunction
  361.   Set myThread0 = Nothing
  362.   Set myThread1 = Nothing
  363.   Set myThread2 = Nothing
  364. End Sub
  365. Private Sub Command3_Click()
  366.   Set myThread0 = New ThreadVB
  367.   Set myThread1 = New ThreadVB
  368.   Set myThread2 = New ThreadVB
  369.   Command3.Enabled = False
  370.   Command1.Enabled = True
  371.   Command2.Enabled = True
  372.   Command4.Enabled = True
  373.   cboPriority0.Enabled = True
  374.   cboPriority1.Enabled = True
  375.   cboPriority2.Enabled = True
  376.   myThread0.LoadFunction AddressOf modMultiThread.DoSomething0
  377.   myThread1.LoadFunction AddressOf modMultiThread.DoSomething1, 200&
  378.   myThread2.LoadFunction AddressOf modMultiThread.DoSomething2, 300&
  379. End Sub
  380. Private Sub Command4_Click()
  381.   Command4.Enabled = False
  382.   Command5.Enabled = True
  383.   myThread0.StartFunction
  384.   myThread1.StartFunction
  385.   myThread2.StartFunction
  386. End Sub
  387. Private Sub Command5_Click()
  388.   Command5.Enabled = False
  389.   Command4.Enabled = True
  390.   myThread0.PauseFunction
  391.   myThread1.PauseFunction
  392.   myThread2.PauseFunction
  393. End Sub
  394. Public Sub DoSomething0(ByVal lParam As Long)
  395.   Static i As Double
  396.   txtParam(0).Text = lParam
  397.     txtText(0).Text = i
  398.     txtText(0).Refresh
  399.     i = i + 1
  400.   Loop
  401.   Form1.Show
  402. End Sub
  403. Public Sub DoSomething1(ByVal lParam As Long)
  404.   Static i As Double
  405.   txtParam(1).Text = lParam
  406.     txtText(1).Text = i
  407.     txtText(1).Refresh
  408.     i = i + 1
  409.   Loop
  410. End Sub
  411. Public Sub DoSomething2(ByVal lParam As Long)
  412.   Static i As Double
  413.   txtParam(2).Text = lParam
  414.     txtText(2).Text = i
  415.     txtText(2).Refresh
  416.     i = i + 1
  417.   Loop
  418. End Sub
  419. Private Sub Form_Load()
  420.   cboPriority0.ListIndex = 3
  421.   cboPriority1.ListIndex = 3
  422.   cboPriority2.ListIndex = 3
  423. End Sub
  424. Private Sub myThread0_FunctionLoaded(lpThreadID As Long)
  425.   txtLoaded(0).Text = "True"
  426. End Sub
  427. Private Sub myThread0_FunctionPaused(dwPausedCount As Long)
  428.   txtStarted(0).Text = "False"
  429. End Sub
  430. Private Sub myThread0_FunctionStarted(dwPausedCount As Long)
  431.   txtStarted(0).Text = "True"
  432. End Sub
  433. Private Sub myThread0_FunctionUnloaded(dwExitStatus As Long)
  434.   txtStarted(0).Text = "False"
  435.   txtLoaded(0).Text = "False"
  436. End Sub
  437. Private Sub myThread1_FunctionLoaded(lpThreadID As Long)
  438.   txtLoaded(1).Text = "True"
  439. End Sub
  440. Private Sub myThread1_FunctionPaused(dwPausedCount As Long)
  441.   txtStarted(1).Text = "False"
  442. End Sub
  443. Private Sub myThread1_FunctionStarted(dwPausedCount As Long)
  444.   txtStarted(1).Text = "True"
  445. End Sub
  446. Private Sub myThread1_FunctionUnloaded(dwExitStatus As Long)
  447.   txtStarted(1).Text = "False"
  448.   txtLoaded(1).Text = "False"
  449. End Sub
  450. Private Sub myThread2_FunctionLoaded(lpThreadID As Long)
  451.   txtLoaded(2).Text = "True"
  452. End Sub
  453. Private Sub myThread2_FunctionPaused(dwPausedCount As Long)
  454.   txtStarted(2).Text = "False"
  455. End Sub
  456. Private Sub myThread2_FunctionStarted(dwPausedCount As Long)
  457.   txtStarted(2).Text = "True"
  458. End Sub
  459. Private Sub myThread2_FunctionUnloaded(dwExitStatus As Long)
  460.   txtStarted(2).Text = "False"
  461.   txtLoaded(2).Text = "False"
  462. End Sub
  463.