我有一个简单的列表视图,其中添加了一个图像列表。显示图像项目很好,但是当我只想要一个文本,没有图标或图像,一个纯文本项目进入我的列表视图时,该东西会在我身上放下一个图像。我无法添加任何项目,而旁边没有图标/图片。
这是代码
case WM_CREATE:{
HBITMAP hbmp_o, hbmp;
COLORREF crMask;
// listview view is LVS_ICON by default
hWndListView = CreateWindowEx(0, WC_LISTVIEW, TEXT("ListView1"), WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, 0, 0, 400, 500, hwnd, NULL, GetModuleHandle(NULL), NULL);
hbmp_o = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP3), IMAGE_BITMAP, 0, 0, 0);
BITMAP bm_o = { 0 };
GetObject(hbmp_o, sizeof(bm_o), &bm_o);
HDC dc_o = CreateCompatibleDC(NULL), dc = CreateCompatibleDC(NULL);
HBITMAP old_o = (HBITMAP)SelectObject(dc_o, hbmp_o);
unsigned char *Data;
BITMAPINFO BitmapInfo;
memset(&BitmapInfo.bmiHeader, 0, sizeof(BitmapInfo.bmiHeader));
BitmapInfo.bmiHeader.biWidth = lv_bmp_width;
BitmapInfo.bmiHeader.biHeight = lv_bmp_height;
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 32;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
hbmp = CreateDIBSection(dc_o, &BitmapInfo, DIB_RGB_COLORS, (void **)&Data, 0, 0);
HBITMAP old = (HBITMAP)SelectObject(dc, hbmp);
SetStretchBltMode(dc, HALFTONE);
StretchBlt(dc, 0, 0, lv_bmp_width, lv_bmp_height, dc_o, 0, 0, bm_o.bmWidth, bm_o.bmHeight, SRCCOPY);
SelectObject(dc_o, old_o);
hbmp = (HBITMAP)SelectObject(dc, old);
BITMAP bm = { 0 };
GetObject(hbmp, sizeof(bm), &bm);
hImageList_small = ImageList_Create(lv_bmp_width, lv_bmp_height, ILC_COLOR32 | ILC_MASK, 3, 0);
ImageList_Add(hImageList_small, hbmp, (HBITMAP)NULL);
ListView_SetImageList(hWndListView, hImageList_small, LVSIL_NORMAL);
LVITEM lv;
lv = { LVIF_IMAGE, itm_count, 0, 0, 0, NULL, 0, img_count, 0, 0, 0, 0, 0 };
ListView_InsertItem(hWndListView, &lv); img_count++; itm_count++;
hwndNextViewer = SetClipboardViewer(hwnd);
break;
}
/*********************************************************************************************/
case WM_DRAWCLIPBOARD:{
static UINT auPriorityList[] = {
CF_OWNERDISPLAY,
CF_TEXT,
CF_OEMTEXT,
CF_UNICODETEXT,
CF_ENHMETAFILE,
CF_BITMAP,
CF_DIB
};
if (!OpenClipboard(hwnd)) lasterror(L"Clipboard not opening");
UINT uformat = GetPriorityClipboardFormat(auPriorityList, 7);
HGLOBAL hnd;
LPWSTR wstr = NULL;
LPWSTR str = NULL;
switch (uformat)
{
case CF_OEMTEXT:
case CF_TEXT:
case CF_UNICODETEXT:{
if((hnd = GetClipboardData(CF_UNICODETEXT)) == NULL) lasterror(L"hbmp_o is NULL");
wstr = (LPWSTR)GlobalLock(hnd);
str = (LPWSTR)malloc(wcslen(wstr) * sizeof(WCHAR) + sizeof(WCHAR));
wcscpy(str, wstr);
GlobalUnlock(hnd);//GlobalFree(hnd); fuck global free. makes crash
CloseClipboard();
LVITEM lv;
lv = { LVIF_TEXT, itm_count++, 0, 0, 0, str, 0, 0, 0, 0, 0, 0, 0 };
int a = ListView_InsertItem(hWndListView, &lv); itm_count++;
free(str);
break;
}
//etc..
除了删除图像列表和自定义绘制位图之外,我没有解决方案。