Article View: borland.public.cppbuilder.nativeapi
Article #184Re: Assigning Icon from ExtractIconEx without leaks
From: Remy Lebeau (TeamB)
Date: Tue, 01 Jul 2008 16:33
Date: Tue, 01 Jul 2008 16:33
41 lines
2327 bytes
2327 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message
news:486a1911@newsgroups.borland.com...
> - however, as soon as i call DestroyIcon - the image is lost.
Don't call DestroyIcon(). The TIcon inside the TImage is taking ownership
of the HICON handle, but then you are destroying it behind the TIcon's back.
> So i tried using a temporary TIcon object and then using the
> Canvas Draw funciton i.e.:
That is not necessary. Simply remove the call to DestroyIcon(). The rest
of the code is fine:
HICON hIconSmall = NULL;
::ExtractIconEx(sObject.c_str(), 0, NULL, &hIconSmall, 1);
if( hIconSmall )
Image->Picture->Icon->Handle = hIconSmall;
> delete icoSmall;
> ::DestroyIcon(hIconSmall);
That is wrong for the same reason. The temporary TIcon owns the HICON, so
you don't need to call DestroyIcon(). The TIcon destructor will do that
automatically.
> this works and doesn't seem to have any resource leaks but
> the image is not painted transparent - i have a white background
> displayed.
That is because you are drawing on a TBitmap that has a white background.
> I've tried setting the Transparent property of the TImage but it
> doesn't make any difference.
That only applies to TGraphic objects that the TImage itself displays. It
does not apply when drawing onto the TImage manually.
Gambit
Technical Details
Message-ID:
<486a5c9e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!news.albasani.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<486a1911@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dea519f40adb32bd X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <486a1911@newsgroups.borland.com> Subject: Re: Assigning Icon from ExtractIconEx without leaks Date: Tue, 1 Jul 2008 09:33:21 -0700 Lines: 43 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <486a5c9e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214930078 207.178.157.90 (1 Jul 2008 09:34:38 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!news.albasani.net!news.isoc.lu!newsgroups.borland.com!not-for-mail