Progress bar inside listicon (quick attemp)

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Progress bar inside listicon (quick attemp)

Post by BackupUser »

Code updated for 5.20+

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
Last edited by fsw on Thu Aug 22, 2013 7:59 pm, edited 1 time in total.
Reason: Code updated for 5.20+
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi Justin
GREAT!!! Very nice example... Its exactly what Tranquil and me searched and wanted in our application! Really cool! [/;)]

Btw... Mabye you know a way how to create/use ListViewGadgets with TreeGadget inside!? If you know eD*nkey for example you will know what i mean... If you dont really know what i mean atm, have a look to the forum (beginners or wishlist) !? Or just write me a mail: [url]mailto:twill@gmx.de[/url]

Many thanks in advance and keep on your great work! :wink:


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

Are you doing an edonkey clone? :)

I haven't seen a control like that lately, i don't remember how they look, but i guess you have to subclass (not sure if it's the exact term) the treeview in the listview, i have no idea of how to do it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hello Justin
Yep, tranquil and me are working on an edonkey clone... Thats one of the reasons why we asked Fred so often to have complete (!) filestreaming support for CRC32 / MD5 and UDP support!! :)

We still hope to have the streaming support for the next PB release!? Atm we are on a part in our application where we really need that stuff to continue our project!

Hi @ all
Have someone here on the forum (maybe a code-guru!? :wink: how to create/use those listview gadgets with treegadgets like in edonkey and some other appz? Thanks in advance for any hint or example! :)

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

@MrVain: I've been able to put TreeGadget inside ListIconGadget using SetParent_(), but afterwards I get some redrawing problems when sliding the ListIconGadget. But maybe you can solve that.

Bye,

El_Choni
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Progress bar inside listicon (quick attemp)

Post by ricardo »

Hi,

How to be able to paint the second row, per example or a different column?
ARGENTINA WORLD CHAMPION
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: Progress bar inside listicon (quick attemp)

Post by Lord »

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=2 ;subitem 2 <---------
                  If paint=#True
                    ;update rect
                    rc\right=(rc\right) + _step:Debug rc\right
                    
                    ;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=2 ;subitem 2 <---------
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:Debug _step
        paint=#True
        SetGadgetItemText(1,0,"", 2) ; activate the painting cycle - 2 <---------
        
    EndSelect
  EndIf
  
Until eid=#PB_Event_CloseWindow
Change lines 47, 86 and 108 to specify the wanted column.
Image
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Progress bar inside listicon (quick attemp)

Post by ricardo »

Lord wrote: Sat Jun 11, 2022 10:34 am [Change lines 47, 86 and 108 to specify the wanted column.
Great!!

And for the row?

Thanks in advance
ARGENTINA WORLD CHAMPION
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: Progress bar inside listicon (quick attemp)

Post by Lord »

ricardo wrote: Sat Jun 11, 2022 6:05 pm ...
And for the row?
...
Sorry, I don't know.
It was just my "quick attemp" to this problem.
Maybe someone else can solve...
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Progress bar inside listicon (quick attemp)

Post by mk-soft »

Without API and Paint

Code: Select all

;-TOP

Image = CreateImage(0, 16, 16, 32, #Red)
Image2 = CreateImage(1, 16, 16, 32, #Blue)

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  ResizeGadget(0, 10, 10, dx - 20, dy - 20)
EndProcedure

Procedure Main()
  Protected dx, dy
  Protected value, progress.s
  
  If OpenWindow(0, 210, 210, 820, 520, "Window", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
    
    dx = WindowWidth(0)
    dy = WindowHeight(0)
    
    ListIconGadget(0, 10, 10, dx - 20, dy - 20, "Column 0", 200)
    AddGadgetColumn(0, 1, "Comlum 1", 100)
    AddGadgetColumn(0, 2, "Comlum 2", 400)
    
    For i = 0 To 25
      value = Random(100)
      progress = LSet("", value / 5, Chr($25A0))
      If i & 1
        AddGadgetItem(0, -1, "Data " + i + #LF$ + "Value " + value + #LF$ + progress, ImageID(1))
        SetGadgetItemColor(0, i, #PB_Gadget_FrontColor, $0000C0, 2)
      Else
        AddGadgetItem(0, -1, "Data " + i + #LF$ + "Value " + value + #LF$ + progress, ImageID(0))
        SetGadgetItemColor(0, i, #PB_Gadget_FrontColor, $00C000, 2)
      EndIf 
    Next
    
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1436
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Progress bar inside listicon (quick attemp)

Post by jacdelad »

mk-softs version looks even better when using $2587.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Progress bar inside listicon (quick attemp)

Post by mk-soft »

jacdelad wrote: Thu Jun 16, 2022 2:16 am mk-softs version looks even better when using $2587.
:wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply