我用这个创建了一个listview:
SIZE size;
LVTILEVIEWINFO tileViewInfo;
hDLGlistb =CreateWindow(WC_LISTVIEW,L"",WS_HSCROLL|WS_VISIBLE|WS_CHILD|
LVS_REPORT,5,80,450,130,ihDlg(HMENU)DLG_LIST_icons,0,0);
size.cx=50;
size.cy=50;
tileViewInfo.cbSize = sizeof(tileViewInfo);
tileViewInfo.dwFlags = LVTVIF_FIXEDSIZE;
tileViewInfo.dwMask = LVTVIM_COLUMNS | LVTVIM_TILESIZE;
tileViewInfo.cLines = 2;
tileViewInfo.sizeTile = size;
ListView_SetTileViewInfo(hDLGlistb, &tileViewInfo);
然后我调用此函数通过shell32.dll中的图标填充列表:
void iload_Icons(HWND hwndlist,LPTSTR pszfile)
{
LVITEM lvItem;
HIMAGELIST hSmall;
HICON ic_index;
HMODULE sh32 = LoadLibrary(pszfile);//TEXT("shell32.dll"));
lvItem.mask = LVIF_IMAGE | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
lvItem.iSubItem = 0;
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_MASK, 1, 1);
for (int i=0; i<20; i++)
{
ic_index = LoadIcon(sh32,MAKEINTRESOURCE(i));
lvItem.iItem=i;
lvItem.iImage=i;
lvItem.pszText=pszfile;//not imoprtant
lvItem.cchTextMax=100;
ListView_InsertItem(hwndlist, &lvItem);
ListView_SetItem(hwndlist,&lvItem);
ImageList_AddIcon(hSmall, ic_index);
}
ListView_SetImageList(hwndlist, hSmall, LVSIL_SMALL);
DestroyIcon(ic_index);
FreeLibrary(sh32);
}
但是当我运行应用程序时,列表视图已填充(因为vscroll栏已激活,但我看不到这些项目。
注意:listview是对话框的一部分,我在对话框的回调过程中调用iload_icons()
函数。我还没有添加代码来处理列表中的事件。