🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #178

Assigning Icon from ExtractIconEx without leaks

#178
From: Mike Collins
Date: Tue, 01 Jul 2008 12:58
44 lines
2252 bytes
Hay guys, sorry for posting twice in a row, just having a bit of a nightmare 
with this code.  My last posts still stands, i.e. can't work out how to load 
48x48 icons.

However, I've got another problem which was over looked by a type.  I want 
to load an icon with ExtractIconEx and assign it to TImage for display 
purposes.  I'm doing somehting like this:

HICON hIconSmall;
ExtractIconEx(sObject.c_str(), 0, NULL, &hIconSmall, 1);
if (hIconSmall)
{
   Image->Picture->Icon->Handle = hIconSmall;
   ::DestroyIcon(hIconSmall);
}

- however, as soon as i call DestroyIcon - the image is lost.

So i tried using a temporary TIcon object and then using the Canvas Draw 
funciton i.e.:

HICON hIconSmall;
ExtractIconEx(sObject.c_str(), 0, NULL, &hIconSmall, 1);
if (hIconSmall)
{
       TIcon *icoSmall = new TIcon;
       icoSmall->Handle = hIconSmall;
       Image->Height = 16;
       Image->Width = 16;
       Image->Canvas->Draw(0, 0, icoSmall);
       delete icoSmall;
       ::DestroyIcon(hIconSmall);
}

- this works and doesn't seem to have any resource leaks but the image is 
not painted transparent - i have a white background displayed.  I've tried 
setting the Transparent property of the TImage but it doesn't make any 
difference.

Can any one suggest a better course of action?

Many thanks, again and again and again :-)

Mike C 
Technical Details
Message-ID: <486a1911@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeeder.dynfx.net!weretis.net!news.isoc.lu!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dea519f40adb32bd,start
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mike Collins" <its@TheBottomOfThePost>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Assigning Icon from ExtractIconEx without leaks
Date: Tue, 1 Jul 2008 12:58:06 -0000
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 84.13.93.69
Message-ID: <486a1911@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1214912785 84.13.93.69 (1 Jul 2008 04:46:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeeder.dynfx.net!weretis.net!news.isoc.lu!newsgroups.borland.com!not-for-mail