As the title says, I'm trying to write a simple window program, but when I try to change the icon of my TreeView, it goes wrong. I'm pretty sure my icon was loaded because I did this:
HICON hIcon;
//hinst is my global variable
hIcon = LoadIcon(hinst,(char*)IDI_ICON_MAIN);
if (hIcon == NULL)
{
MessageBox(NULL, "LoadIcon failed", "error", MB_OK);
}
It works fine then I use ImageList_ReplaceIcon()
:
if (ImageList_ReplaceIcon(iml, 3, hIcon) == -1)
{
MessageBox(NULL, "replace icon failed", "error", MB_OK);
}
TreeView_SetImageList(hwndTV, iml, TVSIL_STATE);
First, I thought, maybe it's because I gave the wrong ILC_COLOR
in ImageList_Create()
, then I rechecked the bit of my icon then reset the parameter, but it's still not working.
Can anyone give me some clue of what is wrong? I already checked with Google and read the docs mutiple times, perhaps I missed something?
UPDATE [2022/05/31]
Here is my TreeView:
I'm tring to change my icon to the red circle.
CodePudding user response:
I can see my icon now, thanks. I appreciate those who gave me advice.
ReplaceIcon() can only be used when I have already added an icon into it. If there's no icon in it then the only condition I can use is to set the index to -1, so that the ReplaceIcon() can add the icon for me.