ListView Item komplett selber zeichnen ?
-
moin meisters ...
Nachdem ich nun weiter unten erfahren habe wie ich einzelne Items farbig darstellen kann, interessiert mich nun wie ich ein Item komplett selber zeichne.
Grund ist, ich möchte nicht bei einem selektierten Item den blauen Hintergrund und den gepunkteten Rand haben.
Ich verwende wieder das Beispiel aus der MSDN: (etwas abgewandelt)
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.lItemlParam==0)) return(CDRF_DODEFAULT); // nicht selber zeichnen // selber zeichnen /* 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. */ TextOut(lplvcd->nmcd.hdc, lplvcd->nmcd.rc.left, lplvcd->nmcd.rc.top, TEXT("test"), lstrlen(TEXT("test")) ); /* We changed the font, so we're returning CDRF_NEWFONT. This tells the control to recalculate the extent of the text. */ return CDRF_SKIPDEFAULT; } } default: break; } return 0; }
Im Prinzip funktioniert es, aber der Text beginnt nicht am linken Rand der LV sondern etwas eingerückt.
Zudem ist es egal ob ich das 0. oder das 10. Item selektiere, der Text erscheint immer an der gleichen Stelle in der LV !Ich muß wohl die Itemhöhe*ItemNr nehmen und diese zu rc.top addieren ?
Nur wie sieht das aus beim ermitteln der Itemhöhe ? Wenn unterschiedliche Items
unterschiedliche Fonts haben ?Selbst wenn ich die Höhe aller bisherigen Items habe ist immer noch nicht klar
wieso der Text nicht exakt am rechten Rand erscheint.Oder anders, auf was bezieht sich rc überhaupt ?
Stimmt also was mit rc.left nicht ?
Besten Dank im Voraus
mfg
RB
-
moin meisters ...
hat sich erledigt ListView_GetItemRect() !!!
mfg
RB