将HICON转换为unsigned long

时间:2020-12-23 16:44:32

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

我想从系统中获取Icon。通过使用SHGetFileInfo我得到了HICON,

I tested this HICON with the following code:

我用以下代码测试了这个HICON:

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.

在屏幕上的位置(300,200)它显示我的图标,我想将此图标设置为树视图,因为我需要资源ID,请建议是否有人知道,如何将此句柄转换为无符号长。

Thanks, Praveen Mamdge

谢谢,Praveen Mamdge

2 个解决方案

#1


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.

资源ID是可执行文件中的资源的标识符。您可以将此标识符与MAKEINTRESOURCE一起用于需要资源标识符的函数。

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

对于树视图,使用TreeView_SetImageList,然后每个项获取相对于此列表的索引。

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.

要创建操作图像列表,可以使用ImageList_Create和ImageList_AddIcon等。

It's sooo 1990. :)

这是1990年的。:)

#2


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.

HANDLE不是资源ID。大多数可以获取文件和资源ID的函数也有一个直接接受HANDLE的版本。

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

CodeProject上的这个链接可能就是你要找的东西。

#1


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.

资源ID是可执行文件中的资源的标识符。您可以将此标识符与MAKEINTRESOURCE一起用于需要资源标识符的函数。

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

对于树视图,使用TreeView_SetImageList,然后每个项获取相对于此列表的索引。

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.

要创建操作图像列表,可以使用ImageList_Create和ImageList_AddIcon等。

It's sooo 1990. :)

这是1990年的。:)

#2


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.

HANDLE不是资源ID。大多数可以获取文件和资源ID的函数也有一个直接接受HANDLE的版本。

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

CodeProject上的这个链接可能就是你要找的东西。