从文件中取出的图标,如何能将它显示在TListView中(TListView中的条目数量很多!)

bfq 2000-09-13 02:13:00
由于需要在TListView中显示带图标的内容,而TListView中的内容又不固定,因此想动态的中文件中取出图标然后显示到TListView上,请高手指点方法!
...全文
222 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaozi 2001-10-24
  • 打赏
  • 举报
回复

楼上的说得都很有道理,但这样做的话速度太慢了。

要想达到像资源管理器的速度我建议你用 Windows 提供的 Image List.

一个简单的例子.
// AddIconsToImageList - creates a masked image list and adds some
// icons to it.
// Returns the handle to the new image list.
// hinst - handle to the application instance.
//
// Global variables and constants
// g_nBird and g_nTree - indexes of the images.
// cx_icon and cy_icon - width and height of the icon.
// num_icons - number of icons to add to the image list.
extern int g_nBird, g_nTree;

#define CX_ICON 32
#define CY_ICON 32
#define NUM_ICONS 3

HIMAGELIST AddIconsToImageList(HINSTANCE hinst)
{
HIMAGELIST himlIcons; // handle to new image list
HICON hicon; // handle to icon

// Ensure that the common control DLL is loaded.
InitCommonControls();

// Create a masked image list large enough to hold the icons.
himlIcons = ImageList_Create(CX_ICON, CY_ICON, ILC_MASK, NUM_ICONS, 0);

// Load the icon resources, and add the icons to the image list.
hicon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_BIRD));
g_nBird = ImageList_AddIcon(himlIcons, hicon);

hicon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_TREE));
g_nTree = ImageList_AddIcon(himlIcons, hicon);

return himlIcons;
}


在MSDN 中找 Image list 会有更详细的用法!

CPerlAsm_Lx 2001-09-09
  • 打赏
  • 举报
回复
en
CPerlAsm_Lx 2001-09-06
  • 打赏
  • 举报
回复
up
xiaozi 2001-09-06
  • 打赏
  • 举报
回复

void __fastcall TForm1::FDrawIcon( AnsiString sFileName )
{
ListView1->Items->Clear(); //清空原来的图标
ImageList1->Clear();

TListItem *listitem;
HICON hIcon;
TIcon *Icon=new TIcon();
//文件中包含的图标总数
int iCount = (int)ExtractIcon( Handle,sFileName.c_str(), -1);
//循环提取所有图标
for ( int i=0; i<iCount; i++)
{
hIcon = ExtractIcon( Handle,sFileName.c_str(), i);
Icon->Handle = hIcon;
ImageList1->AddIcon( Icon );
listitem = ListView1->Items->Add();
listitem->ImageIndex = ImageList->Count + i;

listitem->Caption = "Icon " + AnsiString( listitem->ImageIndex );

}
delete Icon;

}
bfq 2000-09-15
  • 打赏
  • 举报
回复
谢谢各位,问题已解决,代码如下
AnsiString Fname;//文件名
int i;//图标索引
HIcon=new TIcon();
HIcon->Handle=ExtractIcon(HInstance,Fname.c_str(),i);
ImageList1->AddIcon(HIcon));
但问题是取出的图标在ListView中比较难看,而且又不能以大图标方式显示,有人能帮我想想办法吗?
  • 打赏
  • 举报
回复
TO:gx_sunny
怎么下载你的例程?
  • 打赏
  • 举报
回复
关注!
bfq 2000-09-13
  • 打赏
  • 举报
回复
用ExtractIcon取到HICON后,如何放到TImageList中,我试了几次,总是出错,请指点!!能给出代码例子最好。
early 2000-09-13
  • 打赏
  • 举报
回复
你好:
你可以用ExtractIcon这个API函数取到HICON句柄

SCUM 2000-09-13
  • 打赏
  • 举报
回复
借助 TImageList 的属性和方法,动态装入图标。
注意对 TVItem 的识别和调整,比较烦人。
不过我很喜欢这样做,看起来多美啊。
gx_sunny 2000-09-13
  • 打赏
  • 举报
回复
我问了同样的问题,在CB中有例程,在Examples\VirtualListView下!很完整!去看看!
early 2000-09-13
  • 打赏
  • 举报
回复
写过的代码丢在爪哇国了
请把你的代码帖出来,让大家帮你看看
Putao 2000-09-13
  • 打赏
  • 举报
回复
关注

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧