The list view control is not designed to do this. However, if you are
willing to do your own rendering, you can use the Custom Draw feature
of the list view control which will allow you to display graphics,
formatted text, or anything else you please. To do so, you will need
version 4.70 or later of Comctl32.dll... odds are, you have this
already. To use the Custom Draw functionality, you will need to
process the NM_CUSTOMDRAW notification message.
The following source code sample is from the MSDN and shows a simple
example of custom rendering. To draw the _entire_ control yourself,
return CDRF_SKIPDEFAULT instead and draw the desired contents into the
given hDC.
LRESULT DoNotify(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
switch (pnm->hdr.code)
{
case NM_CUSTOMDRAW:
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
/*
CDDS_PREPAINT is at the beginning of the paint cycle.
You
implement custom draw by returning the proper value.
In this
case, we're requesting item-specific notifications.
*/
if(lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
// Request prepaint notifications for each item.
return CDRF_NOTIFYITEMDRAW;
/*
Because we returned CDRF_NOTIFYITEMDRAW in response to
CDDS_PREPAINT, CDDS_ITEMPREPAINT is sent when the
control is
about to paint an item.
*/
if(lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT){
/*
To change the font, select the desired font into
the
provided HDC. We're changing the font for every
third item
in the control, starting with item zero.
*/
if(!(lplvcd->nmcd.dwItemSpec % 3))
SelectObject(lplvcd->nmcd.hdc, g_hNewFont);
else
return(CDRF_DODEFAULT);
/*
To change the text and background colors in a list
view
control, set the clrText and clrTextBk members of
the
NMLVCUSTOMDRAW structure to the desired color.
This differs from most other controls that support
CustomDraw. To change the text and background
colors for
the others, call SetTextColor and SetBkColor on
the provided HDC.
*/
lplvcd->clrText = RGB(150, 75, 150);
lplvcd->clrTextBk = RGB(255,255,255);
/*
We changed the font, so we're returning
CDRF_NEWFONT. This
tells the control to recalculate the extent of the
text.
*/
return CDRF_NEWFONT;
}
}
default:
break;
}
return 0;
}
Hope this helps!
Custom Draw Reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/custdraw/refs.asp
"Custom Draw", MSDN Library, Microsoft Corporation, (1997) |