DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting icons with TSysImageList

 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 10/12/05 14:45    Post subject: Getting icons with TSysImageList Reply with quote

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 Smile
Back to top
View user's profile Send private message
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 11/12/05 18:38    Post subject: Reply with quote

I solved it today Smile

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:
//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 Smile 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
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 12/12/05 07:27    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 12/12/05 21:28    Post subject: Reply with quote

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 Smile

You're welcome, it's nice to be able to give back Smile
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...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group