Code: Alles auswählen
;
; by Danilo, March 2012, PB4.60
;
; http://forums.purebasic.com/german/viewtopic.php?f=3&t=25336
;
EnableExplicit
Define EventID
Define i, font
font = LoadFont(#PB_Any, "Lucida Sans Unicode", 10)
Procedure WinCallback(hWnd, Msg, wParam, lParam)
Protected gadget
If Msg = #WM_DRAWITEM
Protected *di.DRAWITEMSTRUCT = lParam
If *di And *di\CtlType = #ODT_LISTVIEW
With *di
gadget = \CtlID
If IsGadget(gadget) And GadgetType(gadget)=#PB_GadgetType_ListIcon
Protected text.s = GetGadgetItemText(gadget,\itemID,0) ; text holen
Protected width0 = GetGadgetItemAttribute(gadget,0,#PB_ListIcon_ColumnWidth) ; breite von column 0 holen
Protected width1.f = GetGadgetItemAttribute(gadget,0,#PB_ListIcon_ColumnWidth,1) ; breite von column 1 holen
Protected brush = CreateSolidBrush_(RGB($00,$00,$FF)) ; pinsel mit farbe für die balken erstellen
Protected brushsel = CreateSolidBrush_(RGB($FF,$FF,$00)) ; pinsel mit farbe für selektierte items
Protected background= CreateSolidBrush_(RGB($C2,$D4,$EF)) ; hintergrundfarbe setzen
Protected percent.f = width1/100*ValF(text) ; balkenlaenge in prozent ausrechnen
Protected oldBrush,oldPen,bbrush
If GetGadgetItemState(gadget,\itemID)=#PB_ListIcon_Selected
bbrush = brushsel ; hintergrund fuer ausgewaehlte items
Else
bbrush = background ; hintergrund fuer normale items
EndIf
oldBrush = SelectObject_(\hDC,bbrush)
oldPen = SelectObject_(\hDC,GetStockObject_(#NULL_PEN))
Rectangle_(\hDC,0,\rcItem\top,\rcItem\right+1,\rcItem\bottom+1) ; hintergrund zeichnen
SelectObject_(\hDC,oldBrush)
SelectObject_(\hDC,oldPen)
; optional: den text umranden
;oldBrush = SelectObject_(\hdc,GetStockObject_(#HOLLOW_BRUSH)) ; innenfarbe durchsichtig
;oldPen = SelectObject_(\hdc,GetStockObject_(#BLACK_PEN)) ; umrandung schwarz
;Rectangle_(\hdc,\rcItem\left,\rcItem\top,\rcItem\left+width0,\rcItem\bottom+1) ; text umranden
;Rectangle_(\hdc,\rcItem\left+width0-1,\rcItem\top,\rcItem\left+width0+width1,\rcItem\bottom+1) ; balken umranden
;SelectObject_(\hDC,oldBrush)
;SelectObject_(\hDC,oldPen)
; text in column 0 zeichnen
SetTextColor_(\hdc,RGB($00,$00,$00)) ; textfarbe setzen
TextOut_(\hdc,\rcItem\left+5,\rcItem\top+1,@text,Len(text))
; balken mit dem pinsel in column 1 zeichen
oldBrush = SelectObject_(\hdc,brush)
oldPen = SelectObject_(\hdc,GetStockObject_(#NULL_PEN))
Rectangle_(\hdc,\rcItem\left+width0,\rcItem\top+1,\rcItem\left+width0+percent,\rcItem\bottom) ; normale balken
;RoundRect_(\hdc,\rcItem\left+width0,\rcItem\top+2,\rcItem\left+width0+percent,\rcItem\bottom,12,12) ; alternativ: abgerundete balken ohne AntiAliasing
SelectObject_(\hDC,oldBrush)
SelectObject_(\hDC,oldPen)
; pinsel loeschen
DeleteObject_(brush)
DeleteObject_(brushsel)
DeleteObject_(background)
EndIf
EndWith
EndIf
ProcedureReturn #True
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
RandomSeed(3)
If OpenWindow(0,0,0,650,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowCallback(@WinCallback())
ListIconGadget(2,10,10,WindowWidth(0)-20,WindowHeight(0)-20,"Zahl",50,#LVS_OWNERDRAWFIXED|#PB_ListIcon_MultiSelect) ; ListIconGadget mit Flag #LVS_OWNERDRAWFIXED
AddGadgetColumn(2,1,"Balken",550)
SetGadgetFont(2, FontID(font))
SetGadgetColor(2,#PB_Gadget_BackColor,RGB($C2,$D4,$EF))
For i=0 To 199
AddGadgetItem(2,-1,Str(Random(100)))
Next
Repeat
EventID=WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
End
EndIf
ForEver
EndIf