VB icon

CHAMELEON BUTTON 2.0.6 Memory Leak FIX

Email
Submitted on: 2/18/2015 11:09:00 PM
By: Cody Rutkowski (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 6.0
Views: 2018
 
     When using the chameleon button user control I noticed that eventually the application will begin to run out of resources. I was extremely curious to what was causing it, and decided to identify the problem. Using the vbAccelerator GUI Resource Tracer (www.vbaccelerator.com), I was able to find the cause of the problem. In the procedure DrawFrame(...) the memory leak occurs. I implemented DeleteObject calls for the hPen and hObject. Originally the code would only call DeleteObject on the value of hObject and not hPen. Hope anyone that uses the chameleon button user control finds this helpful. This user control is hosted on this website incase you are unfamiliar with it.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :CHAMELEON BUTTON 2.0.6 Memory Leak FIX
'**************************************
' Replace the existing procedure with the procedure provided below.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: CHAMELEON BUTTON 2.0.6 Memory Leak FIX
' Description:When using the chameleon button user control I noticed that eventually the application will begin to run out of resources. I was extremely curious to what was causing it, and decided to identify the problem. Using the vbAccelerator GUI Resource Tracer (www.vbaccelerator.com), I was able to find the cause of the problem. In the procedure DrawFrame(...) the memory leak occurs. I implemented DeleteObject calls for the hPen and hObject. Originally the code would only call DeleteObject on the value of hObject and not hPen. Hope anyone that uses the chameleon button user control finds this helpful. This user control is hosted on this website incase you are unfamiliar with it.
' By: Cody Rutkowski (from psc cd)
'**************************************

Private Sub DrawFrame(ByVal ColHigh As Long, ByVal ColDark As Long, ByVal ColLight As Long, ByVal ColShadow As Long, ByVal ExtraOffset As Boolean, Optional ByVal Flat As Boolean = False)
 
'a very fast way to draw windows-like frames
Dim pt As POINTAPI
Dim frHe As Long, frWi As Long, frXtra As Long
frHe = He - 1 + ExtraOffset: frWi = Wi - 1 + ExtraOffset: frXtra = Abs(ExtraOffset)
With UserControl
Dim hObject As Long
Dim hPen As Long
'=============================
hPen = CreatePen(PS_SOLID, 1, ColHigh)
hObject = SelectObject(.hDC, hPen)
MoveToEx .hDC, frXtra, frHe, pt
LineTo .hDC, frXtra, frXtra
LineTo .hDC, frWi, frXtra
Call DeleteObject(hObject)
Call DeleteObject(hPen)
 
'=============================
hPen = CreatePen(PS_SOLID, 1, ColDark)
hObject = SelectObject(.hDC, hPen)
LineTo .hDC, frWi, frHe
LineTo .hDC, frXtra - 1, frHe
MoveToEx .hDC, frXtra + 1, frHe - 1, pt
Call DeleteObject(hObject)
Call DeleteObject(hPen)
If Flat Then Exit Sub
'=============================
hPen = CreatePen(PS_SOLID, 1, ColLight)
hObject = SelectObject(.hDC, hPen)
LineTo .hDC, frXtra + 1, frXtra + 1
LineTo .hDC, frWi - 1, frXtra + 1
Call DeleteObject(hObject)
Call DeleteObject(hPen)
'=============================
hPen = CreatePen(PS_SOLID, 1, ColShadow)
hObject = SelectObject(.hDC, hPen)
LineTo .hDC, frWi - 1, frHe - 1
LineTo .hDC, frXtra, frHe - 1
Call DeleteObject(hObject)
Call DeleteObject(hPen)
End With
End Sub


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.