Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Controls
  New Posts New Posts RSS Feed - CXTButton SetIcon GDI Leak
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTButton SetIcon GDI Leak

 Post Reply Post Reply
Author
Message
KSUScott View Drop Down
Newbie
Newbie


Joined: 08 May 2007
Location: United States
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote KSUScott Quote  Post ReplyReply Direct Link To This Post Topic: CXTButton SetIcon GDI Leak
    Posted: 08 October 2009 at 10:53pm
I believe I've uncovered a GDI leak in the SetIcon method of CXTButton.  The method calls LoadImage and the icon handle is passed to another overloaded version of SetIcon.  That method makes a copy of the given handle, and the original handle is never destroyed (i.e. via DestroyIcon).  I'm using Xtreme Toolkit Pro Version 9.70.  Has this been addressed in subsequent releases?
Thanks!
Scott 
 
 
BOOL CXTButton::SetIcon(CSize size, LPCTSTR lpszID, LPCTSTR lpszHotID/*=NULL*/, BOOL bRedraw/*=TRUE*/)
{
 HICON hIcon = NULL;
 HICON hIconHot = NULL;
 // Free previous resources (if any).
 CleanUpGDI();
 // Find the resource for the normal icon and load the image.
 HINSTANCE hInst = AfxFindResourceHandle(lpszID, RT_GROUP_ICON);
 hIcon = (HICON)::LoadImage(hInst, lpszID,
  IMAGE_ICON, size.cx, size.cy, LR_DEFAULTCOLOR);
 // Return false if the icon handle is NULL.
 if (!hIcon)
 {
  TRACE1( "Failed to load Icon resource %s.\n", lpszID );
  return FALSE;
 }
 // If we are using a pushed image as well...
 if (lpszHotID)
 {
  // Find the resource for the pushed icon and load the image.
  hInst = AfxFindResourceHandle(lpszHotID, RT_GROUP_ICON);
  hIconHot = (HICON)::LoadImage(hInst, lpszHotID,
   IMAGE_ICON, size.cx, size.cy, LR_DEFAULTCOLOR);
  // Return false if the icon handle is NULL.
  if (!hIconHot)
  {
   TRACE0( "Failed to load Icon resource.\n" );
   return FALSE;
  }
 }
 return CXTButton::SetIcon(size, hIcon, hIconHot, bRedraw);
}
 
Product: Xtreme Toolkit Pro Version 9.70
Platform: Windows (32bit)
Language: Visual C++ 6.0
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.