Board index » cppbuilder » Assigning Icon from ExtractIconEx without leaks
Mike Collins
![]() CBuilder Developer |
Assigning Icon from ExtractIconEx without leaks2008-07-01 08:58:06 PM cppbuilder79 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 |