Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / MFC
Article

Adding progress bars to a list control

Rate me:
Please Sign up or sign in to vote.
3.89/5 (14 votes)
2 Sep 2001 160.5K   3.7K   82   13
A simple extension that allows you to add a progress indicator as an item in a list control

Sample Image - napster.jpg

Introduction

This code shows how to add a progress control to a listview control. If you want to use this code, copy listctrlex.h and listctrlex.cpp to your project and subclass it.

These files are good examples of owner-draw control and custom draw list controls. if you want to visually show various data in your listview controls (such as progress, which is done here), you'll need these.

There is another way to show a progress control in a listview control - that is embedding progress bar control in your listview control. For this case that isn't necessary because the code presented here works properly and I don't want to worry about processing child window's messages.

I implemented and tested on Windows 2000 Proffesional, Visual C++ 6.0 with Service Pack 5. Untested under Unicode.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Korea (Republic of) Korea (Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNeedes updating Pin
Donsw11-Dec-08 11:15
Donsw11-Dec-08 11:15 
GeneralMy vote of 2 Pin
Donsw11-Dec-08 11:14
Donsw11-Dec-08 11:14 
GeneralIt can do more... Pin
Mikeylas30-Oct-06 18:32
Mikeylas30-Oct-06 18:32 
GeneralIgnore the below comments (+fix) Pin
AnthonyJ28-Apr-03 7:33
AnthonyJ28-Apr-03 7:33 
The idea of creating lots of CProgressCtrl windows sounds horribly inefficient if you're planning on displaying large datasets. Even just creating enough to fill the list seems bad (what if its resizable? - gets messy).

This is exactly what ownerdrawn / customdrawn lists were for - slight tweaks to the way the list is drawn. My own need for this control needs a slightly modified style of bar, so would the posters below recommend I create a derived CProgressCtrl to do the drawing too?

As for the column heading problems, the only problem is that GetCellRect is calculating an incorrect rectangle for column 0, because CListCtrl::GetSubItemRect() doesnt handle this case nicely. My fix for this (seems to work nicely for all the cases I've tried) is to replace GetCellRect with this:

<br />
BOOL CListCtrlEx::GetCellRect(int iRow, int iCol, int nArea, CRect &rect)<br />
{<br />
	CRect colRect;<br />
	if (!GetHeaderCtrl()->GetItemRect(iCol, colRect))<br />
		return FALSE;<br />
<br />
	if(!GetItemRect(iRow, rect, nArea))<br />
		return FALSE;<br />
	<br />
	rect.left = colRect.left;<br />
	rect.right = colRect.right;<br />
	<br />
	return TRUE;<br />
}<br />


The only negative comment that I have is the name of the class - there are lots of classes called CListCtrlEx, so I'd have chosen something more descriptive - eg CProgressListCtrl.

--
AnthonyJ@planetquake.com
www.anthony.co.uk
GeneralMore Effecient Method Pin
Zac Howland22-Mar-02 5:45
Zac Howland22-Mar-02 5:45 
GeneralRe: More Effecient Method Pin
mrsilver18-May-17 6:56
mrsilver18-May-17 6:56 
GeneralHERE's the correct way Pin
8-Dec-01 8:31
suss8-Dec-01 8:31 
GeneralRe: HERE's the correct way Pin
Max Santos19-Jul-03 15:51
Max Santos19-Jul-03 15:51 
GeneralRe: HERE's the correct way Pin
mrsilver18-May-17 7:00
mrsilver18-May-17 7:00 
GeneralYOU'RE DOING IT ALL WRONG!!! Pin
8-Dec-01 8:16
suss8-Dec-01 8:16 
GeneralMany bugs Pin
20-Nov-01 14:29
suss20-Nov-01 14:29 
GeneralRe: Many bugs Pin
AnthonyJ28-Apr-03 7:16
AnthonyJ28-Apr-03 7:16 
GeneralRe: Many bugs Pin
mrsilver18-May-17 6:59
mrsilver18-May-17 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.