Hier mal ein kleines Beispiel für Balken direkt zeichnen, prozentual abhängig von der Breite des GadgetColumn.
Code: Alles auswählen
;
; by Danilo, March 2012, PB4.60
;
; http://forums.purebasic.com/german/viewtopic.php?f=3&t=25336
;
; does not work on XP
;
EnableExplicit
Define EventID
Define i, font
font = LoadFont(#PB_Any, "Lucida Sans Unicode", 10)
Procedure WinCallback(hWnd, Msg, wParam, lParam)
If Msg = #WM_NOTIFY
Protected *lvcd.NMLVCUSTOMDRAW = lParam
If *lvcd And *lvcd\nmcd\hdr\code = #NM_CUSTOMDRAW
Protected gadget = GetWindowLongPtr_(*lvcd\nmcd\hdr\hwndFrom,#GWLP_ID)
Select *lvcd\nmcd\dwDrawStage
Case #CDDS_PREPAINT
; optional: hintergrund loeschen -> auskommentieren für standard-hintergrund
Protected background = CreateSolidBrush_(RGB($C2,$D4,$EF)) ; hintergrundfarbe setzen
If IsGadget(gadget) And GadgetType(gadget)=#PB_GadgetType_ListIcon
SelectObject_(*lvcd\nmcd\hdc,background)
SelectObject_(*lvcd\nmcd\hdc,GetStockObject_(#NULL_PEN))
Rectangle_( *lvcd\nmcd\hdc,0,0,GadgetWidth(gadget),GadgetHeight(gadget))
DeleteObject_(background)
EndIf
ProcedureReturn #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
If *lvcd\iSubItem
ProcedureReturn #CDRF_DODEFAULT
Else
With *lvcd\nmcd
If IsGadget(gadget) And GadgetType(gadget)=#PB_GadgetType_ListIcon
Protected text.s = GetGadgetItemText(gadget,\dwItemSpec,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 percent.f = width1/100*ValF(text) ; balkenlaenge in prozent ausrechnen
; XP fix
;
; http://msdn.microsoft.com/en-us/library/windows/desktop/bb774778(v=vs.85).aspx
;
; Bug on earlier versions of Windows
;
; Handling subitem pre-paint messages on Windows XP (perhaps all pre-Vista systems?)
; the handler receives incorrect top And bottom values in NMLVCUSTOMDRAW::nmcd.rc,
; sometimes they are zero, sometimes are Not updated since previous handler call
; (so basically the idea is that they are left uninitialized by comctl32 caller).
; In order To get correct subitem position the handler has To explicitly obtain
; rectangle using a separate message/call:
;
; RECT Position;
; ListView.GetSubItemRect((INT) pHeader->nmcd.dwItemSpec, pHeader->iSubItem, LVIR_BOUNDS, &Position);
;
\rc\left = 0
SendMessage_(GadgetID(gadget),#LVM_GETITEMRECT,\dwItemSpec,@\rc)
If GetGadgetItemState(gadget,\dwItemSpec)=#PB_ListIcon_Selected
SelectObject_(\hdc,brushsel)
SelectObject_(\hdc,GetStockObject_(#NULL_PEN))
Rectangle_(\hdc,0,\rc\top+1,\rc\right,\rc\bottom+1) ; hintergrund für ausgewaehlte items
EndIf
; optional: den text umranden
;SelectObject_(\hdc,GetStockObject_(#HOLLOW_BRUSH)) ; innenfarbe durchsichtig
;SelectObject_(\hdc,GetStockObject_(#BLACK_PEN)) ; umrandung schwarz
;Rectangle_(\hdc,\rc\left,\rc\top,\rc\left+width0,\rc\bottom+1) ; text umranden
;Rectangle_(\hdc,\rc\left+width0-1,\rc\top,\rc\left+width0+width1,\rc\bottom+1) ; balken umranden
; text in column 0 zeichnen
SetTextColor_(\hdc,RGB($00,$00,$00)) ; textfarbe setzen
TextOut_(\hdc,\rc\left+5,\rc\top,@text,Len(text))
; balken mit dem pinsel in column 1 zeichen
SelectObject_(\hdc,brush)
SelectObject_(\hdc,GetStockObject_(#NULL_PEN))
Rectangle_(\hdc,\rc\left+width0,\rc\top+2,\rc\left+width0+percent,\rc\bottom) ; normale balken
;RoundRect_(\hdc,\rc\left+width0,\rc\top+2,\rc\left+width0+percent,\rc\bottom,12,12) ; alternativ: abgerundete balken ohne AntiAliasing
; pinsel loeschen
DeleteObject_(brush)
DeleteObject_(brushsel)
EndIf
EndWith
ProcedureReturn #CDRF_SKIPDEFAULT
EndIf
EndSelect
EndIf
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))
For i=0 To 199
AddGadgetItem(2,-1,Str(Random(100)))
Next
Repeat
EventID=WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
End
EndIf
ForEver
EndIf
Man kann natürlich auch ganz anderes in den \hdc zeichnen oder Bilder rein blitten.