Restored from previous forum. Originally posted by Justin.
This code draws a progress bar using the GDI rather than subclassing a progress control.
I did it fast, maybe there are better ways.
It does not handle resizing, but i think it can be easily done computing the width before drawing (last callback msg).
Click on the button to step 10%, 100 pixels total width, i choosed the easy way..
If you want to understand something you should read this:
http://msdn.microsoft.com/library/en-us ... stdraw.asp
Code: Select all
;Progress bar inside Listview using GDI
;Justin 10/2002
#NM_CUSTOMDRAW=#NM_FIRST-12
#CDDS_ITEM=65536
#CDDS_PREPAINT=1
#CDDS_SUBITEM=131072
;CDDS_ITEMPREPAINT=#CDDS_ITEM|#CDDS_PREPAINT
#CDRF_DODEFAULT=0
#CDRF_NOTIFYITEMDRAW=32
#CDRF_NOTIFYSUBITEMDRAW=32
#CDRF_NEWFONT=2
#CDRF_SKIPDEFAULT=4
#LVM_GETSUBITEMRECT=#LVM_FIRST+56
#LVIR_BOUNDS=0
;subitem rect structure
rc.RECT
;progress brush
hred=CreateSolidBrush_(RGB(255,0,0))
Procedure listproc(hwnd,msg,wparam,lparam)
Shared hl,_step,rc,hred,paint
ret=#PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*ptr.NMLVCUSTOMDRAW=lparam
Select *ptr\nmcd\hdr\code
Case #NM_CUSTOMDRAW
Select *ptr\nmcd\dwDrawStage
Case #CDDS_PREPAINT
ret=#CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEM | #CDDS_PREPAINT ;CDDS_ITEMPREPAINT
ret=#CDRF_NOTIFYSUBITEMDRAW
Case #CDDS_SUBITEM | #CDDS_ITEM | #CDDS_PREPAINT ;CDDS_SUBITEM | CDDS_ITEMPREPAINT
If *ptr\nmcd\dwItemSpec=0 ;item 0
If *ptr\iSubItem=1 ;subitem 1
If paint=#True
;update rect
rc\right=(rc\right) + _step
;device context
hdevice=*ptr\nmcd\hdc
;paint rect
FillRect_(hdevice,@rc,hred)
_step=0 ;10% each time
paint=#False
ret=#CDRF_SKIPDEFAULT
Else
ret=#CDRF_DODEFAULT
EndIf
EndIf
EndIf
EndSelect
EndSelect
EndSelect
ProcedureReturn ret
EndProcedure
;- main
hWnd=OpenWindow(0,10,10,500,500,"Custom Draw List View",#PB_Window_SystemMenu)
hl=ListIconGadget(1,10,10,400,400,"File",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(1,1,"Progress",100)
AddGadgetColumn(1,2,"Time",80)
AddGadgetItem(1,0,"file" + Chr(10) + "" + Chr(10) + "12")
ButtonGadget(2,20,450,50,20,"Step it!")
SetWindowCallback(@listproc())
;get subitem rect
rc\top=1 ;subitem 1
rc\left=#LVIR_BOUNDS
SendMessage_(hl,#LVM_GETSUBITEMRECT,0,@rc) ;item 0
width=(rc\right)-(rc\left) ;subitem width (we already know it)
;reduce rect to 0 width
rc\right=(rc\right)-width
_step=0
Repeat
eid=WaitWindowEvent()
If eid=#PB_Event_Gadget
Select EventGadget()
Case 2 ;10% step
_step + 10
paint=#True
SetGadgetItemText(1,0,"",1) ; activate the painting cycle
EndSelect
EndIf
Until eid=#PB_Event_CloseWindow