tags:

views:

97

answers:

2

Hi, All

I am trying to get the Icon from the system. by using SHGetFileInfo I got the HICON,

I tested this HICON with the following code:

SHFILEINFO info;    //For getting information about the file
if (::SHGetFileInfo(ucPath.GrabTString(), 0,&info, sizeof(info), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SHELLICONSIZE) != NULL) 
{
//Control view of the 
  if (iconView != NULL){
        HDC hDC = GetDC(NULL);  //Get the screen DC
    DrawIconEx(hDC, 300, 200, info.hIcon, 0, 0, 0, NULL, DI_NORMAL);  //Draw icon on 300, 200 location
    ReleaseDC(NULL, hDC);
    //following line is not working
    iconView->SetRsrcID((unsigned long) info.hIcon);
  }
  ::DestroyIcon(info.hIcon);
}

on the screen at location (300, 200) it shows me icon, I want to set this icon to the tree view, for that I require the resource id, Please suggest if any one knows, How to convert this Handle to unsigned long.

Thanks, Praveen Mamdge

+1  A: 

A HANDLE is not a resource ID. Most functions that can take a file and resource ID also have a version that takes the HANDLE directly.

This link on CodeProject might be what you're looking for.

Brad Bruce
Thanks, BradBut the link that you sent processed on hardcoded resource files, and I want to refer the icons from the OS. Ok, Thanks again for your guideline.
+1  A: 

A resource id is an identifier to a resource you have within your executable. You use this identifier with MAKEINTRESOURCE for functions requiring resource identifiers.

As for tree view, you use the TreeView_SetImageList, and then each items gets an index relative to this list.

You therefore need to build an image list with the icons you want to use, pass it to the tree view and then use the appropriate index for each item.

To create an manipulate an imagelist, you can use ImageList_Create & ImageList_AddIcon, etc.

It's sooo 1990. :)

Edouard A.
oooppssss.....Sorry, for the incomplete information, I am a third party developer and developing for Adobe InDesign, I dont think ImageList_Create is needed for InDesign lists, If I used the hardcoded resources then it works fine, no need to create any list.I think, just the problem is how following line can be achiveed using other way,iconView->SetRsrcID((unsigned long) info.hIcon);
You are in a world of pain. You'll have to put the icon into a resource and then load it. Looks like the API doesn't accept HICON directly. HICON is not a resource id.
Edouard A.
Thanks a lot Edouard, I think this is the only option that I have, thanks again for a guideline.