15,978
社区成员
发帖
与我相关
我的任务
分享
WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_NOCOLUMNHEADER|LVS_OWNERDATA|LVS_OWNERDRAWFIXED|WS_BORDER|LVS_ALIGNTOP
ListView_SetExtendedListViewStyle(g_hListView, ListView_GetExtendedListViewStyle(g_hListView) | LVS_EX_FULLROWSELECT);
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpdis;
lpdis = (LPDRAWITEMSTRUCT)lParam;
TCHAR szDrawText[MAX_PATH];
SecureZeroMemory(szDrawText, sizeof(szDrawText));
wsprintf(szDrawText, L"%d: Ownerdraw ListView", lpdis->itemID);
OwnerDraw(lpdis, hdc, hWnd, szDrawText);
}
break;
void OwnerDraw(LPDRAWITEMSTRUCT lpdis, HDC hdc, HWND hWnd,TCHAR* szDraw)
{
RECT rect;
GetClientRect(hWnd, &rect);
lpdis->rcItem.left = rect.left;
lpdis->rcItem.right = rect.right;
int iTaskIndex;
if (lpdis->CtlType == ODT_LISTVIEW)
{
LPCTSTR lpszText = (LPCTSTR) lpdis->itemData;
hdc = lpdis->hDC;
HBRUSH hbrBkColor = CreateSolidBrush (RGB(255,255,255));
HBRUSH hbrSEL = CreateSolidBrush (RGB(155,197,255));
if ((lpdis->itemAction | ODA_SELECT) && (lpdis->itemState & ODS_SELECTED))
{
SetTextColor(hdc, RGB(0,255,0));
SetTextColor(hMemDC, RGB(0,255,0));
FillRect(hdc, &lpdis->rcItem,hbrSEL);
FillRect(hMemDC, &lpdis->rcItem,hbrSEL);
}
else
{
SetTextColor(hdc, RGB(0,0,255));
SetTextColor(hMemDC, RGB(0,0,255));
FillRect(hdc, &lpdis->rcItem,hbrBkColor);
FillRect(hMemDC, &lpdis->rcItem,hbrBkColor);
}
DeleteObject (hbrSEL);
DeleteObject (hbrBkColor);
lpdis->rcItem.top+=10;
DrawText(hdc, szDraw, lstrlen(szDraw), &lpdis->rcItem, DT_LEFT|DT_SINGLELINE|DT_TOP);
DrawText(hMemDC, szDraw, lstrlen(szDraw), &lpdis->rcItem, DT_LEFT|DT_SINGLELINE|DT_TOP);
}
}