简体   繁体   English

Win32-ListView中的图像列表

[英]Win32 - Image Lists in ListView

I am trying to add images to a listview. 我正在尝试将图像添加到列表视图。 I have saved an image that is 32x16 and attempting to use ImageList_Add() to split it into 2 images ( since it should be able to infer the number of images from the width ). 我保存了一个32x16的图像,并尝试使用ImageList_Add()将其拆分为2个图像(因为它应该能够从width推断图像的数量)。 The items are being added but without images. 正在添加项目,但没有图像。 There appears to be something there when I click but not the images nor the sizes I expect. 当我单击时似乎有东西,但没有图像或期望的尺寸。

I am using the following code: 我正在使用以下代码:

LVCOLUMN lvc = {0};
lvc.mask     = LVCF_TEXT | LVCF_WIDTH;
lvc.pszText  = _T("Some column header");
lvc.cx       = 150;

HWND hwndListView = GetDlgItem( hwndDlg, IDC_LISTVIEW );
ListView_InsertColumn( hwndListView, 0, &lvc );

HIMAGELIST hImageList = ImageList_Create( 16, 16, ILC_COLOR, 2, 0 );
HBITMAP    hbmBlobs   = ( HBITMAP )LoadImage( ( HINSTANCE )lParam,
  MAKEINTRESOURCE( IDB_BLOBS ), IMAGE_BITMAP, 0, 0, 0 );

ImageList_Add( hImageList, hbmBlobs, NULL );
DeleteObject( hbmBlobs );
ListView_SetImageList( hwndListView, hImageList, LVSIL_SMALL );
ImageList_Destroy( hImageList );

LVITEM lvi = {0};
lvi.mask   = LVIF_IMAGE;
lvi.iImage = 0;
ListView_InsertItem( hwndListView, &lvi );

lvi.iImage = 1;
ListView_InsertItem( hwndListView, &lvi );

I have uploaded skeleton code that does the bare minimum to create the ListView and my attempt at making the images display. 我已经上传了骨架代码,该代码几乎没有创建ListView,也没有尝试显示图像。 Thank you for your time. 感谢您的时间。

http://localhostr.com/file/adUSZvF/Skeleton.rar http://localhostr.com/file/adUSZvF/Skeleton.rar

You cannot call ImageList_Destroy on the imagelist! 您不能在图像列表上调用ImageList_Destroy! A listview without the LVS_SHAREIMAGELISTS style will destroy the imagelist for you... 没有LVS_SHAREIMAGELISTS样式的列表视图将为您破坏图像列表...

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

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