【发布时间】:2011-08-01 00:55:02
【问题描述】:
这是我的程序的图片:
如您所见,图标不是透明的,只是白色的。这是有问题的,因为我已经将列表视图编码为交替颜色,而白色在灰色上看起来非常难看。
现在,我使用bitmap with a pink background 作为图标,并使用粉红色作为蒙版。这是我的 HIMAGELIST 的代码:
hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, ICON_COUNT, 0);
if (hImageList != NULL)
{
HBITMAP hBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_ICONS));
if (hBitmap != NULL)
{
ImageList_AddMasked(hImageList, hBitmap, RGB(0xFF, 0, 0xFF)); // pink mask
DeleteObject(hBitmap);
}
ImageList_SetBkColor(hImageList, CLR_NONE);
}
ListView_SetImageList(hWnd, hImageList, LVSIL_SMALL);
这是列表视图的自定义绘图(交替颜色)的代码
LRESULT WhiteFlagUI::PaintListView(__in HWND hwndListView, __in LPARAM lParam)
{
LPNMLVCUSTOMDRAW lpListDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(lParam);
switch (lpListDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYSUBITEMDRAW);
break;
case (CDDS_PREPAINT | CDDS_ITEM):
{
RECT rect;
if (ListView_GetSubItemRect(hwndListView, lpListDraw->nmcd.dwItemSpec, lpListDraw->iSubItem, LVIR_BOUNDS, &rect))
{
COLORREF color;
// determine color
if (lpListDraw->nmcd.uItemState & CDIS_SELECTED)
color = RGB(157, 173, 215);
else if (lpListDraw->nmcd.dwItemSpec % 2)
color = RGB(240, 240, 240);
else
color = RGB(255, 255, 255);
// paint
HBRUSH hBrush = CreateSolidBrush(color);
if (hBrush != NULL)
{
FillRect(lpListDraw->nmcd.hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// return color info
lpListDraw->clrTextBk = color;
return CDRF_NEWFONT;
}
}
break;
}
return CDRF_DODEFAULT;
}
坦率地说,我完全不知道如何处理这个问题。有人有什么想法吗?
【问题讨论】:
-
您的应用程序是否请求通用控件版本 6(通过清单)?如果我没记错的话,如果没有启用视觉样式,则不支持 32 位图像列表。
-
我确实启用了视觉样式。无论哪种方式,无论我使用哪个(ILC_COLOR/16/24/32),同样的问题仍然存在。位图未透明加载。
-
只是浏览相关问题,这看起来像你的确切问题:stackoverflow.com/questions/632622/…
-
不幸的是,我也看到了,但对我没有帮助。注意到自定义抽奖是问题,但从未达成解决方案。
-
这就是我发布自定义绘图处理代码的原因,希望它能帮助有人回答我的问题。
标签: c++ winapi listview transparency imagelist