Important alert: (current site time 7/16/2013 2:19:53 AM EDT)
 

VB icon

CHAMELEON BUTTON 2.0.6 Memory Leak FIX

Email
Submitted on: 5/8/2008 12:44:50 PM
By: Cody Rutkowski 
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 6.0
Views: 19117
author picture
(About the author)
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=70509&lngWId=1'for details.'**************************************

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 4 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
5/9/2008 4:03:37 AMDriss HANIB

Thanks for sharing
i've noticed this leak but i wasn't enough good in VB to change anything..
It's a "second life" for this control in big prog..
I'll try the new version..

(If this comment was disrespectful, please report it.)

 
5/9/2008 11:25:31 AMSkilpad

Thanks for this, I was wondering why my apps were getting messed up ^^
(If this comment was disrespectful, please report it.)

 
5/13/2008 1:12:37 AMJakeBullet

good work! Thanks for sharing.
(If this comment was disrespectful, please report it.)

 
7/12/2009 2:54:23 AMtonyn

how about resubmitting the enitre project with the fix???
(If this comment was disrespectful, please report it.)

 
10/2/2009 2:27:18 PMjim sie

i just know what the differ beetwen the original with your add in .. truthfully thanks.. now cham but working great with framing init comon..original not deal with frame.. really thanks
(If this comment was disrespectful, please report it.)

 

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.