Icon colour formats and TreeViews

This is a discussion on Icon colour formats and TreeViews within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to get the icon for folders from SHELL32.DLL and using it in an image list for a ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262

    Exclamation Icon colour formats and TreeViews

    Hi,

    I'm trying to get the icon for folders from SHELL32.DLL and using it in an image list for a TreeView, like so:-
    Code:
    HICON icon;
    HIMAGELIST himl;
    
    ExtractIconEx("shell32.dll", -4, NULL, &icon, 1);
    himl = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 1, 1);
    ImageList_AddIcon(himl, icon);
    The thing is, the tree view subsequently displays the XP 32-bit colour icon for it drawn in 8-bit colour, which looks icky. I want the 8-bit colour version, dammit! I know it's in there...

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    Times up!

    I figured out the solution after reading an article on reading icons. You do it like so:-
    Code:
    //You need these... (not in standard Windows headers?)
    #pragma pack( push )
    #pragma pack( 2 )
    typedef struct {
    	BYTE	bWidth;               // Width of the image
    	BYTE	bHeight;              // Height of the image (times 2)
    	BYTE	bColorCount;          // Number of colors in image (0 if >=8bpp)
    	BYTE	bReserved;            // Reserved
    	WORD	wPlanes;              // Color Planes
    	WORD	wBitCount;            // Bits per pixel
    	DWORD	dwBytesInRes;         // how many bytes in this resource?
    	WORD	nID;                  // the ID
    } MEMICONDIRENTRY, *LPMEMICONDIRENTRY;
    
    typedef struct {
    	WORD			idReserved;   // Reserved
    	WORD			idType;       // resource type (1 for icons)
    	WORD			idCount;      // how many images?
    	MEMICONDIRENTRY	idEntries[1]; // the entries for each image
    } MEMICONDIR, *LPMEMICONDIR;
    
    HGLOBAL res;
    HICON icon = NULL;
    HMODULE module;
    HRSRC ressrc;
    int i;
    LPMEMICONDIR lpIconDir;
    LPBYTE lpIconImage;
    
    module = LoadLibraryEx("shell32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
    ressrc = FindResource(module, MAKEINTRESOURCE(4), RT_GROUP_ICON);
    res = LoadResource(module, ressrc);
    lpIconDir = LockResource(res);
    for (i=0;i<lpIconDir->idCount;i++)
    	if (lpIconDir->idEntries[i].wBitCount == 8 && lpIconDir->idEntries[i].bWidth == GetSystemMetrics(SM_CXSMICON))
    	{
    		ressrc = FindResource(module, MAKEINTRESOURCE(lpIconDir->idEntries[i].nID), RT_ICON);
    		res = LoadResource(module, ressrc);
    		lpIconImage = LockResource(res);
    		icon = CreateIconFromResourceEx(lpIconImage, SizeofResource(module, ressrc), TRUE, 0x00030000, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
    		break;
    	}
    
    himl = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 1, 1);
    ImageList_AddIcon(himl, icon);
    DestroyIcon(icon);
    Next step for me is getting a specific colour format of the icon the shell uses for folders (involves SHGetFileInfo)...

Popular pages Recent additions subscribe to a feed

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