Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I use SHGetfileinfo to get icon of a file, this is my code

HIMAGELIST	hILSmall;  // handle of image list small
HIMAGELIST	hILLarge;  // handle of image list large

// create Image list.
hILSmall = ImageList_Create(CX_ICON_SMALL, CY_ICON_SMALL, FALSE, NUM_ICONS, 0);
hILLarge = ImageList_Create(CX_ICON_LARGE, CY_ICON_LARGE, FALSE, NUM_ICONS, 0);


::SHGetFileInfo(_T("E:\\v.doc"),0, &shfi, sizeof(shfi),SHGFI_SYSICONINDEX|SHGFI_SMALLICON);

HICON hIcon = LoadIcon(hInstance,shfi.iIcon);

ImageList_AddIcon(hILSmall, hIcon);
ImageList_AddIcon(hILLarge, hIcon);

int t = ImageList_GetImageCount(hILSmall);
int b = t;


But when i debug in line b = t, result is t = 0. :(( who can help me?
Posted
Updated 17-Apr-10 19:31pm
v2

1 solution

SHGetFileInfo return the handle to the icon so there is no need to LoadIcon explicitly.

C++
HICON hIcon = ::SHGetFileInfo(_T("E:\\v.doc"),0, &shfi, sizeof(shfi),SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
ImageList_AddIcon(hILSmall, hIcon);
int t = ImageList_GetImageCount(hILSmall);


-Saurabh
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900