Article View: borland.public.cppbuilder.nativeapi
Article #16715SHGetFileInfo and system image list
From: Dmitry Mikhilov
Date: Thu, 01 May 2003 06:24
Date: Thu, 01 May 2003 06:24
66 lines
3065 bytes
3065 bytes
Hello,
I got weird problem when trying to show icons representing file types in an
"explorer-like" list view (style is vsReport so small images are used, file
icons are shown as StateImages). I added TImageList to the form:
TImageList FileIcons;
And in the form constructor the following lines are added:
//--------------------------------------------------------------------------
-
__fastcall TMyForm::TMyForm(TComponent* Owner) : TForm(Owner)
{
SHFILEINFO Si;
FileIcons->Handle = SHGetFileInfo("C:\\",SFGAO_SHARE,&Si,sizeof
(SHFILEINFO),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SYSICONINDEX);
FileIcons->ShareImages = true;
}
//--------------------------------------------------------------------------
-
Here is some class which holds fully qualified file path as a member:
class Filer
{
private:
String FileName;
public:
void __fastcall MakeImage(const TListItem *li) const;
};
//--------------------------------------------------------------------------
-
Here's the body of it's member function which gets TListItem as a parameter
and sets appropriate state image representing file type for it:
void __fastcall Filer::MakeImage(const TListItem *li) const
{
SHFILEINFO Si;
memset(&Si,0,sizeof(SHFILEINFO));
SHGetFileInfo(FileName.c_str(),FILE_ATTRIBUTE_NORMAL,&Si,sizeof(SHFILEINFO),
SHGFI_USEFILEATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SYSICONINDEX);
li->StateIndex = Si.iIcon;
}
Very simple, isn't it? 70% of the time everything is OK, but the problem is
that sometimes Si.Icon contains absolutely wrong index. I may call this
function twice for the same FileName (for example, .jpg or .doc file) and
Si.Icon will contain different values after both calls, so random icons will
be selected from the image list!!! I event tried to strcpy FileName to
char[] buffer, but nothing changed... I tried to pass only file extension to
SHGetFileInfo, but again - all the same...
I can't figure out any pattern in SHGetFileInfo behaviour, though I lost
several hours trying to find out what is wrong...
I use Win'2000 SP3. Any help (Remy!!!! SOS!!!) is welcome!
Dmitry
Technical Details
Message-ID:
<3eb0bdcd@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,577f7a686a96c6b6,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-30 23:31:09 PST From: "Dmitry Mikhilov" <dm1@fromru.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: SHGetFileInfo and system image list Date: Thu, 1 May 2003 10:24:39 +0400 Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 195.131.110.226 Message-ID: <3eb0bdcd@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1051770317 195.131.110.226 (30 Apr 2003 23:25:17 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail