Article ID: 184645
Article Last Modified on 7/1/2004
184687 INFO: Lightweight Controls in Visual Basic 6.0
Control Default Name Property Setting
---------------------------------------------------------------------
Command Button Command1 Name cmdWndLess
Height 375
Left 120
Top 840
Width 2535
Command Button Command2 Name cmdWnd
Height 375
Left 3000
Top 840
Width 2535
TextBox Text1 Name txtNumofControls
Height 285
Left 1680
Top 120
Width 375
Label Label1 Name lblWndLessLoad
AutoSize True
Height 195
Left 120
Top 1320
Label Label2 Name lblWndLessUnload
AutoSize True
Height 195
Left 120
Top 1680
Label Label3 Name lblWndLoad
AutoSize True
Height 195
Left 3000
Top 1320
Label Label4 Name lblWndUnload
AutoSize True
Height 195
Left 3000
Top 1680
Width 480
Label Label5 Name lblStartTicks
Alignment Right Justify
AutoSize True
Caption Start Ticker
Height 195
Left 4680
Top 480
Width 810
Label Label6 Name lblEndTicks
Alignment Right Justify
AutoSize True
Caption End Ticks:
Height 195
Left 4680
Top 120
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim bLoadWnd As Boolean
Dim bLoadWndLess As Boolean
Dim lTickStart As Long
Dim lTickEnd As Long
Dim lResult As Long
Dim colCtrlWnd As Collection
Dim colCtrlWndLess As Collection
Private Sub cmdWnd_Click()
'This event loads and unloads regular controls.
Dim tmpCtrlWnd As Control
Dim lCounter As Long
If bLoadWnd = True Then
'Load Regular controls.
lblWndLoad.Caption = "Loading Regular Controls"
lTickStart = GetTickCount
lblStartTicks.Caption = "Start: " & CStr(lTickStart) & " ms"
For lCounter = 1 To Val(txtNumofControls.Text)
Set tmpCtrlWnd = Controls.Add("TestControls.ctrlWnd", _
"ctrlWnd" & lCounter)
colCtrlWnd.Add tmpCtrlWnd
Set tmpCtrlWnd = Nothing
DoEvents
Next
lTickEnd = GetTickCount
lblEndTicks.Caption = "End: " & CStr(lTickEnd) & " ms"
lblWndLoad.Caption = "Load Time: " & _
CStr(lTickEnd - lTickStart) & " ms"
bLoadWnd = False
cmdWnd.Caption = "Unload Regular Controls"
Else
'Unload regular controls.
lblWndUnload.Caption = "Unloading Regular Controls"
lTickStart = GetTickCount
lblStartTicks.Caption = "Start: " & CStr(lTickStart) & " ms"
' UnLoad controls.
For lCounter = colCtrlWnd.Count To 1 Step -1
Controls.Remove colCtrlWnd.Item(lCounter).Name
colCtrlWnd.Remove (lCounter)
Next
lTickEnd = GetTickCount
lblEndTicks.Caption = "End: " & CStr(lTickEnd) & " ms"
lblWndUnload.Caption = "Unload Time: " & _
CStr(lTickEnd - lTickStart) & " ms"
bLoadWnd = True
cmdWnd.Caption = "Load Regular Controls"
End If
End Sub
Private Sub cmdWndless_Click()
'This command button loads and unloads the lightweight controls.
Dim tmpCtrlWndLess As Control
Dim lCounter As Long
If bLoadWndLess = True Then
lblWndLessLoad.Caption = "Loading Lightweight Controls"
lTickStart = GetTickCount
lblStartTicks.Caption = "Start: " & CStr(lTickStart) & " ms"
' Load controls.
For lCounter = 1 To Val(txtNumofControls.Text)
Set tmpCtrlWndLess = _
Controls.Add("TestControls.ctrlWndLess", _
"ctrlWndLess" & lCounter)
colCtrlWndLess.Add tmpCtrlWndLess
Set tmpCtrlWndLess = Nothing
DoEvents
Next
lTickEnd = GetTickCount
lblEndTicks.Caption = "End: " & CStr(lTickEnd) & " ms"
lblWndLessLoad.Caption = "Load Time: " & _
CStr(lTickEnd - lTickStart) & " ms"
bLoadWndLess = False
cmdWndless.Caption = "Unload Windowless Controls"
Else
lblWndLessUnload.Caption = "Unloading Lightweight Controls"
lTickStart = GetTickCount
lblStartTicks.Caption = "Start: " & CStr(lTickStart) & " ms"
' UnLoad controls.
For lCounter = colCtrlWndLess.Count To 1 Step -1
Controls.Remove colCtrlWndLess.Item(lCounter).Name
colCtrlWndLess.Remove (lCounter)
Next
lTickEnd = GetTickCount
lblEndTicks.Caption = "End: " & CStr(lTickEnd) & " ms"
lblWndLessUnload.Caption = "Unload Time: " & _
CStr(lTickEnd - lTickStart) & " ms"
bLoadWndLess = True
cmdWndless.Caption = "Load Windowless Controls"
End If
End Sub
Private Sub Form_Load()
Set colCtrlWnd = New Collection
Set colCtrlWndLess = New Collection
cmdWndless.Caption = "Load Lightweight Controls"
bLoadWndLess = True
cmdWnd.Caption = "Load Regular Controls"
bLoadWnd = True
txtNumofControls.Text = "20"
End Sub
Additional query words: kbCtrl kbCtrlCreate kbVBp kbVBp600 kbVBp kbdsd kbDSupport
Keywords: kbhowto KB184645