
comctl32.ocx resource leakage!
Check the following code, when running it and resizing it, watch the resource-meter...
I had the same problem when using an ImageList to contain a bunch of icons that I needed. I
solved that by replacing them with an Image control array, but this is harder to work
around...
Please press 'Reply to sender and newsgroup' or whatever your button is called when replying.
The code is for VB 4.0 32-bit version.
'***** This file is Explorer.cls
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "CExplorer"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
' Constants that only apply to vbTwips mapping mode!
Const expTVWLVWSpacing = 45
Const expLabelHeight = 270
Const expStatusBarHeight = 280
Const expFormDiffWidth = 165
Const expFormDiffHeight = 1260
Const expTVWLVWTop = 285
Const expMinTVWWidth = 1000
Const expMinLVWWidth = 1000
Private m_bResizingTVW As Boolean
Private m_nSavedTVWSize As Integer
Private m_frm As Form
Private m_tvw As TreeView
Private m_lvw As ListView
Private m_lbl1 As Label
Private m_lbl2 As Label
Private m_img As Image
' Call at Form_Load to attach the controls to the explorer
Public Sub AttachControls(frm As Form, tvw As TreeView, lvw As ListView, _
lbl1 As Label, lbl2 As Label, img As Image)
Set m_frm = frm
Set m_tvw = tvw
Set m_lvw = lvw
Set m_lbl1 = lbl1
Set m_lbl2 = lbl2
Set m_img = img
End Sub
' Call if you want to unload the form without exiting the application
' to conserve memory
Public Sub DetachControls()
Set m_frm = Nothing
Set m_tvw = Nothing
Set m_lvw = Nothing
Set m_lbl1 = Nothing
Set m_lbl2 = Nothing
Set m_img = Nothing
End Sub
' Call at Form_Resize
Public Sub Resize()
Dim TVWHeight As Integer
Dim TVWWidth As Integer
Dim LVWWidth As Integer
' We keep this flag to emulate the behavior of the
' 'real' explorer, e.g. that when resizing the width of
' the window, the ListView can disappear completely, but
' when increasing the size again, the TreeView retains the
' width that it was before it was resized
If Not m_bResizingTVW Then
' If the ListView has 'disappeared' then
If m_frm.Width - expFormDiffWidth <= m_tvw.Width Then
' we start resizing the TreeView
m_bResizingTVW = True
' save its original width
m_nSavedTVWSize = m_tvw.Width
TVWWidth = m_frm.Width - expFormDiffWidth
Else
' nothing...
TVWWidth = m_tvw.Width
End If
Else
' If we're resizing and the TreeView is still
' smaller than the saved size, just widen it
If m_frm.Width - expFormDiffWidth <= m_nSavedTVWSize Then
TVWWidth = m_frm.Width - expFormDiffWidth
Else
' otherwise just quit resizing the TreeView
TVWWidth = m_nSavedTVWSize
m_bResizingTVW = False
End If
End If
TVWHeight = m_frm.Height - expFormDiffHeight
LVWWidth = m_frm.Width - TVWWidth - expFormDiffWidth
m_tvw.Move 0, _
expTVWLVWTop, _
TVWWidth, _
TVWHeight
m_lvw.Move TVWWidth + expTVWLVWSpacing, _
expTVWLVWTop, _
LVWWidth, _
TVWHeight
m_lbl1.Move 0, _
0, _
TVWWidth, _
expLabelHeight
m_lbl2.Move TVWWidth + expTVWLVWSpacing, _
0, _
LVWWidth, _
expLabelHeight
m_img.Move TVWWidth, _
expTVWLVWTop, _
expTVWLVWSpacing, _
TVWHeight
End Sub
' Call at image_MouseMove and Button = vbLeftButton
Public Sub TrackPanes(ByVal X As Single, ByVal Y As Single)
' The TreeView and ListViews cannot be too small
' or the application will DIE!
If (m_img.Left + X > expMinTVWWidth) And _
(m_img.Left + X < m_frm.Width - expMinLVWWidth) Then
' redim the width of the TreeView and let
' Resize handle the rest
m_tvw.Width = m_img.Left + X
Resize
End If
End Sub
'********** End of Explorer.cls
'********** This file explorer.frm
VERSION 4.00
Begin VB.Form Form1
Caption = "Explorer Form"
ClientHeight = 4680
ClientLeft = 1140
ClientTop = 1800
ClientWidth = 7425
Height = 5370
Left = 1080
LinkTopic = "Form1"
ScaleHeight = 4680
ScaleWidth = 7425
Top = 1170
Width = 7545
Begin VB.Image Image1
Height = 4335
Left = 3360
MousePointer = 2 'Cross
Top = 0
Width = 135
End
Begin ComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 285
Left = 0
TabIndex = 4
Top = 4395
Width = 7425
_Version = 65536
_ExtentX = 13097
_ExtentY = 503
_StockProps = 68
AlignSet = -1 'True
MousePointer = 1
SimpleText = ""
NumPanels = 2
i1 = "Explorer.frx":0000
i2 = "Explorer.frx":00CD
End
Begin VB.Label Label2
BorderStyle = 1 'Fixed Single
Caption = " Files"
Height = 270
Left = 3720
TabIndex = 3
Top = 240
Width = 3135
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Caption = " All Folders"
Height = 270
Left = 120
TabIndex = 2
Top = 240
Width = 2895
End
Begin ComctlLib.ListView ListView1
Height = 2655
Left = 3720
TabIndex = 1
Top = 600
Width = 3135
_Version = 65536
_ExtentX = 5530
_ExtentY = 4683
_StockProps = 205
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
Icons = ""
SmallIcons = ""
End
Begin ComctlLib.TreeView TreeView1
Height = 2775
Left = 120
TabIndex = 0
Top = 600
Width = 2895
_Version = 65536
_ExtentX = 5106
_ExtentY = 4895
_StockProps = 196
Appearance = 1
ImageList = ""
Indentation = 527
PathSeparator = "\"
Style = 7
End
Begin VB.Menu mnuFile
Caption = "&File"
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private m_bResizingTVW As Boolean
Private m_nSavedTVWSize As Integer
Dim m_explorer As CExplorer
Private Sub Form_Load()
Dim explorer As New CExplorer
Set m_explorer = explorer
m_explorer.AttachControls Me, TreeView1, ListView1, Label1, Label2, Image1
End Sub
Private Sub Form_Resize()
m_explorer.Resize
End Sub
Private Sub Form_Unload(Cancel As Integer)
m_explorer.DetachControls
Set m_explorer = Nothing
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
m_explorer.TrackPanes X, Y
End If
End Sub
'******* End of explorer.frm
I have attached explorer.frx, but it should not be needed.
[
Explorer.frx 1K ]