Getting icons with TSysImageList

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Getting icons with TSysImageList

Postby m_b » December 10th, 2005, 2:45 pm

Hi guys, I've got kind of a begginer question about this component:

How can I get the icon of special folders like the desktop folder? I tried passing the component c:\...\Desktop, but I just get an ordinary folder icon, the same goes for My Documents.

I would also like to know how to get the icons of f.ex. My Computer, Recycle Bin and similar folders...

Any help greatly appreciated :)
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby m_b » December 11th, 2005, 6:38 pm

I solved it today :)

It seems the component did everything OK, but the wrong way, that's why I got a folder icon instead of the default desktop icon - the component asked for the icon of the desktop folder by it's path, not PIDL.
Here's how I got it to appear (in a demo application for a custom places bar):

Code: Select all
//k is a value of a CSIDL_ constant, for Desktop it's 0

function GetPlaceInfo(k: integer): RPlaceInfo;
var
 PIDL: PItemIDList;
 IDesktopFolder: IShellFolder;
 StrRet: TStrRet;
 Malloc: IMalloc;
 FileInfo: TShFileInfo;
begin
 if Succeeded(SHGetSpecialFolderLocation(0, k, PIDL)) then
  begin
   //returns the "path" of the special folder, something like "::{xxxx-xxxx-...}" (pardon my ignorance, I'm slowly getting to know the shell, I didn't bother with it much before)
   if Succeeded(SHGetDesktopFolder(IDesktopFolder)) and Succeeded(IDesktopFolder.GetDisplayNameOf(PIDL, SHGDN_NORMAL or SHGDN_FORPARSING, StrRet)) then
    Result.Path := StrRetToString(PIDL, StrRet)
   else
    Result.Path := '';
   //I'm not sure I need all 3 of the last parameters
   SHGetFileInfo(PChar(PIDL), 0, FileInfo, SizeOf(FileInfo), SHGFI_PIDL or SHGFI_DISPLAYNAME or SHGFI_ICONLOCATION or SHGFI_SYSICONINDEX or SHGFI_ICON);
   //Get's the name of the special folder
   Result.DisplayName := FileInfo.szDisplayName;
   //Here I get the ImageIndex and use it with the DELPHI AREA SystemImageList and it displays the correct icon :))
   Result.ImageIndex := FileInfo.iIcon;
   //I'm not sure I need these two lines, are they necessary, should they be here, please comment...
   ShGetMalloc(Malloc);
   Malloc.Free(PIDL);
  end;
end;


I still have to figure out how to get the description of the special folder, I found it in the registry under MUICache, which doesn't help at all, but I'm sure there's a way to get it.

Anyway, thanks for the great components (sysimagelist, printpreview, gradient, picshow), I haven't used all of them, but they're more than useful :) If you'd like to try some of mine feel free to, they're completely free and can be found at http://mxs.bergsoft.net
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » December 12th, 2005, 7:27 am

Hi,

I updated SysImageList, so that it returns the proper image index of the special folders. Of course, it doesn't work on Delphi 3.

Regarding to your comments in the above code:
  • You didn't use the value correspond to SHGFI_ICONLOCATION and SHGFI_ICON flags, so you can eliminate them from the code.
  • The last two lines of the code are necessary.
By the way, thanks for your freeware components.

Cheers
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby m_b » December 12th, 2005, 9:28 pm

I'll try it out as soon as I can. Though I got it to work in my project already it's good to have similar things in the same place :)

You're welcome, it's nice to be able to give back :)
Anyway, take a look at the forums for some known (recent) bugs, I would upload the newest version (with those bugs fixed), but I just can't find the time...
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron