简体   繁体   English

将HICON转换为无符号的long

[英]Convert HICON to the unsigned long

I am trying to get the Icon from the system. 我正在尝试从系统获取图标。 by using SHGetFileInfo I got the HICON, 通过使用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,请提出建议(如果有人知道),如何将此Handle转换为unsigned long。

Thanks, Praveen Mamdge 谢谢,Praveen Mamdge

A resource id is an identifier to a resource you have within your executable. 资源ID是可执行文件中具有的资源的标识符。 You use this identifier with MAKEINTRESOURCE for functions requiring resource identifiers. 您将此标识符与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. :)

A HANDLE is not a resource ID. HANDLE不是资源ID。 Most functions that can take a file and resource ID also have a version that takes the HANDLE directly. 大多数可以采用文件和资源ID的功能也具有直接采用HANDLE的版本。

This link on CodeProject might be what you're looking for. 您在寻找CodeProject上的此链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM