Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

ImageList->AddIcon(TIcon) does not always add the icon returned by Ext

lenLasalalenLasala Member Posts: 5
Problem:

ImageList->AddIcon(TIcon) does not always add the icon returned by ExtractAssociatedIcon(HInstance, fileName.t_str(), &word)

//------------------------------------------------------------------------------------
What is known: All parameters are correct
//------------------------------------------------------------------------------------
HInstance Applications system Handle
fileName.t_str() is fully qualified file path and file name
&word recieves index of icon in file
//------------------------------------------------------------------------------------
What is not known is why.
//------------------------------------------------------------------------------------

TIcon *ico = new TIcon();
HICON hIco;
int imgIndex;
unsigned short word;

hIco = ExtractAssociatedIcon(HInstance, fileName.t_str(), &word);

if(hIco != NULL)
{
ico->Handle = hIco; //assign handle to icon
//add new item to list view
lv->Items->Add();
lv->Items->Item[lv->Items->Count-1]->ImageIndex = img->AddIcon(ico);
lv->Items->Item[lv->Items->Count-1]->Caption = ExtractFileName(fileName);
}

While this appears straight forward, does not always add the associated icon to the image list.

ALL files in path specified by fileName have associated icons so hIco should never be NULL
yet the icon added to the image list comes from shell32.dll not the file with the associated
icon, this is a random effect, most times it shows the correct icon other times it does not.

does anyone have an idea as to what is going on?

Sign In or Register to comment.