Getting at system Icon resources

This is a discussion on Getting at system Icon resources within the Windows Programming forums, part of the Platform Specific Boards category; Im writing a quick program that displays files as icons and I am wondering where these icons are stored? For ...

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    Getting at system Icon resources

    Im writing a quick program that displays files as icons and I am wondering where these icons are stored? For example, the icon for .BMP is not external so it must be stored somewhere either in a system directory or as a resource in a DLL somewhere.

    How does one get at these icons?
    Founder and avid member of the Internationsl Typo Associateion

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    SHGetFileInfo
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    The icons/images are stored in what is called a System Image List.
    Depending on what you need it for, I'd say you're going to be in store for a lot of frustration. There is no constant ordering system for system images, so #5 in the list on system X might give you the BMP icon, whereas #5 on system Y might give you something else. I've yet to find a standard way of getting/using Windows standard images.

  4. #4
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Thats not a problem for me because I will build a map of my own descriptors to those indexes. For some reason when I use SHGetFileInfo, what I get back is an index but no location. For example, what if an exe or shortcut has its own ICO file embedded inside the EXE. I would want to get at that icon so that I could draw it in my program.

    here is the first way I tried to get at the Index and Path:
    Code:
    	SHFILEINFO *FileInfo = new SHFILEINFO(); 
    
    	// Get a list of files specified by Path
    	SHGetFileInfo(FileName, 
     				  0, 
    				  FileInfo,
    				  sizeof(SHFILEINFO),
    				  SHGFI_ICONLOCATION);
    According the MSDN docs, this way should have returned an index in FileInfo->iIcon (Which it does, correctly) and also the path to the file that contains this resource inside FileIno->szDisplayName. The display name always ends up being a NULL string.

    So instead I tried another approach that somewhat works but its still broken:
    Code:
    	LPITEMIDLIST  Pidl;
    	LPSHELLFOLDER DesktopFolder;
    	LPSHELLFOLDER Folder;
    	OLECHAR       OlePath[MAX_PATH];
    	ULONG         Attributes;
    	HRESULT       hr;
    	IExtractIcon* Extract;
    	TCHAR		  Path[MAX_PATH];
    	LPENUMIDLIST  EnumIDL;
    	unsigned Flags;
    	int Index;
    
    	if (SUCCEEDED(SHGetDesktopFolder(&DesktopFolder)))
    	{
    		// Convert to Unicode
    		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, FileName, -1, OlePath, MAX_PATH);
    
    		// Convert the path to an ITEMIDLIST.
    		hr = DesktopFolder->ParseDisplayName(NULL, NULL, OlePath, NULL, (LPITEMIDLIST *) &Pidl, &Attributes);
    
    		if (SUCCEEDED(hr))
    		{
    			// Populate the Icon Extract Interface
    			hr = DesktopFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST *) &Pidl, IID_IExtractIcon, 0, (void **) &Extract);
    
    			if (SUCCEEDED(hr))
    			{
    				// retrieve the Icon Path and Index
    				if (SUCCEEDED(Extract->GetIconLocation(GIL_OPENICON, Path, _MAX_PATH, &Index, &Flags)))
    				{
    					if (!(Flags & GIL_NOTFILENAME))
    					{
    						if (Index == -1)
    						{
    							// Special case for Control Panel Apps
    							Index = 0;
    						}
    					}
    				}				
    
    				Extract->Release();
    			}
    		}
    
    
    		//release the desktop folder object
    		DesktopFolder->Release();
    	}	
    
    	return NULL;
    The Index seems to be right but the Path variable ends up pointing to C:\Windows\Explorer.exe. This is obviously false.

    Any help on this matter would be greatly appreciated!!
    Founder and avid member of the Internationsl Typo Associateion

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Depending on which icon you are trying to retrieve it may very well be true. I checked explorer.exe, it contains about 16 icons (browseicon, infoicon, mycomp, error, showdesktop, etc).

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    As discussed in this thread on SHGFI_ICONLOCATION, you can use SHGFI_ICON or SHGFI_SYSICONINDEX rather than SHGFI_ICONLOCATION.

  7. #7
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Thanks all for the help, I am currently polling a directory and getting the corresponding icons, but it it possible to get the position of the icons in a given folder, such as the desktop??
    Founder and avid member of the Internationsl Typo Associateion

  8. #8
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Also, while im polling the folders, is it possible to only grab files that are not hidden or system folders/files?
    Founder and avid member of the Internationsl Typo Associateion

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Also, while im polling the folders, is it possible to only grab files that are not hidden or system folders/files? <<

    Use GetFileAttributes.

    >> Thanks all for the help, I am currently polling a directory and getting the corresponding icons, but it it possible to get the position of the icons in a given folder, such as the desktop?? <<

    There is no documented method. However, the desktop is a list-view, so you can probably hack it.

  10. #10
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Good stuff, I found a decent example by Jeroen-bart Engelen which is available here. Unfortunately its very limiting but atleast it gives a decent explanation of how to do it alternatively there is an example by J. Richter and it gives a bit more control over what goes on. The program is called DIPS and available here.

    Thanks for the help so far. my program is coming along nicely, but I have just one more question. Is it possible to grab the system icons for virtual folders such as "my computer" or "network neighborhood", etc???
    Founder and avid member of the Internationsl Typo Associateion

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Is it possible to grab the system icons for virtual folders such as "my computer" or "network neighborhood", etc???
    Like in runtime, so that if the user customises the icon for My Computer, that's the icon you'll get? Or do you just want to take the icon that's currently being used in My Computer and bundle that with your program?

    Note that you might run into copyright issues. I'm not sure that Microsoft would like you using their My Computer icon.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Yes at runtime. Well the icons are already sitting in memory. Its just a matter of getting them. I just dont know how to get them because they do not have a physical file on disk associated with it.
    Founder and avid member of the Internationsl Typo Associateion

  13. #13
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can probably still use SHGetFileInfo. Something like this:
    Code:
    LPITEMIDLIST pidl = NULL;
    
    /* Get the pidl for My Computer. See function documentation for other CSIDLs. */
    SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidl);
    
    /* Use pidl in call to SHGetFileInfo. Note use of SHGFI_PIDL flag. */
    SHGetFileInfo((LPCTSTR) pidl, 0, &fileinfo, sizeof(fileinfo), SHGFI_ICON | SHGFI_PIDL);
    
    /* Free pidl memory. */
    CoTaskMemFree(pidl);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Icon Changer
    By Tughack in forum C Programming
    Replies: 0
    Last Post: 04-27-2008, 08:49 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  4. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 05:15 AM
  5. resources with dev-c++
    By lambs4 in forum Windows Programming
    Replies: 0
    Last Post: 04-13-2003, 07:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21