Article View: borland.public.cppbuilder.nativeapi
Article #3437Re: System Icons
From: Remy Lebeau (TeamB)
Date: Thu, 08 Jun 2006 17:20
Date: Thu, 08 Jun 2006 17:20
49 lines
3451 bytes
3451 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message
news:4487f50f@newsgroups.borland.com...
> Hi Remy, very strange this - I tried exactly the same code that you
> posted above and I only get 5 icons returned.... Using BCB 6
> enterprise on Win2k3.
Interesting. The latest OS I have access to is XP SP2. Sure enough, it
does only return 5 icons.
Further investigation reveils that each process gets its own copy of the
system image list, not the original. Once created, newer OS versions lazily
add icons to the list on an as-needed basis. It would appear that the image
list is initialized with a few icons by default. If you don't request a
specific icon afterwards, it is not added to the list. So, as a test, using
the code I showed earlier, I added a second call to SHGetFileInfo() to get
the icon for a specific file type after the TImageList Handle was
initialized:
SHFILEINFO fi = {0};
DWORD flags = SHGFI_SYSICONINDEX | SHGFI_SMALLICON;
ImageList1->Handle = SHGetFileInfo("", 0, &fi, sizeof(fi), flags);
ImageList1->ShareImages = true;
SHGetFileInfo("test.xml", 0, &fi, sizeof(fi), flags |
SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME);
Sure enough, the ImageList::Count property grew to 6 to include the icon for
.xml files. So the solution is to request specific icons in order to
populate the system image list with them.
Which, when you thik about it, makes sense. If you are populating a
TListBox or TListView or any other icon-enabled component, you should know
the type of items that you are adding to the list. In order to set the
ImageIndex for each item, you have to call SHGetFileInfo() to get each
item's index in the image list. Different item types may be sharing common
icons. So, when you call SHGetFileInfo() for each item to get its proper
index, SHGetFileInfo() will ensure that the icon actually exists in the
image list before returning its index.
> Just out of interest, is the positioning of each icons in the image
> list constant or may it change from version to version, machine
> to machine?
It is not constant. That is why the SHFILEINFO structure has an iIcon
member, so that you can retreive the current index of an item.
Gambit
Technical Details
Message-ID:
<44885ccb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<448716d6$1@newsgroups.borland.com> <448720b8$1@newsgroups.borland.com> <44872e9b$1@newsgroups.borland.com> <44872fa9@newsgroups.borland.com> <44874af9$1@newsgroups.borland.com> <44875092$1@newsgroups.borland.com> <44875268$1@newsgroups.borland.com> <4487589c$1@newsgroups.borland.com> <44875ef3$1@newsgroups.borland.com> <44876da8@newsgroups.borland.com> <4487f50f@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,de14f1cb04eef46a X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <448716d6$1@newsgroups.borland.com> <448720b8$1@newsgroups.borland.com> <44872e9b$1@newsgroups.borland.com> <44872fa9@newsgroups.borland.com> <44874af9$1@newsgroups.borland.com> <44875092$1@newsgroups.borland.com> <44875268$1@newsgroups.borland.com> <4487589c$1@newsgroups.borland.com> <44875ef3$1@newsgroups.borland.com> <44876da8@newsgroups.borland.com> <4487f50f@newsgroups.borland.com> Subject: Re: System Icons Date: Thu, 8 Jun 2006 10:20:25 -0700 Lines: 52 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <44885ccb$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1149787339 68.69.17.41 (8 Jun 2006 10:22:19 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail