Click here to Skip to main content
Click here to Skip to main content

Adding progress bars to a list control

By , 2 Sep 2001
 
<!-- Download Links --> <!-- Article image -->

Sample Image - napster.jpg

<!-- Main HTML starts here -->

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

About the Author

Jinhyuck Jung

Korea (Republic Of) Korea (Republic Of)
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNeedes updatingmemberDonsw11-Dec-08 11:15 
GeneralMy vote of 2memberDonsw11-Dec-08 11:14 
GeneralIt can do more...memberMikeylas30-Oct-06 18:32 
GeneralIgnore the below comments (+fix)memberAnthonyJ28-Apr-03 7:33 
GeneralMore Effecient MethodmemberZac Howland22-Mar-02 5:45 
GeneralHERE's the correct waymemberMike Luongo8-Dec-01 8:31 
I hope this earns me some brownie points on this site. Because no one has emailed me here is the solution:
 
1) Create a listview (not ownerdrawn)
2) Override the paint function using the code below
 
void CMyListView::OnPaint()
{
//CPaintDC dc(this); // device context for painting
 
CListCtrl & List = GetListCtrl();
CHeaderCtrl * pHeader = List.GetHeaderCtrl();
 
//Get the item rectangle for the subitem
// nProgress = column to draw progress control
CRect rectItem;
List.GetSubItemRect( 0, nProgress, LVIR_BOUNDS, rectItem );
 
//Get the client rectangle for finding the bottom of the column
CRect rectClient;
GetClientRect( rectClient );
 
//get the header rectangle so we know the update rectangle
CRect rectHeader;
pHeader->GetClientRect( rectHeader );
 
//readjust the item rect to equal the column rectangle
rectItem.top = rectHeader.bottom;
rectItem.bottom = rectClient.bottom;
 
//validate the region this will exclude the region during the
// OnPaint virtual call
ValidateRect( rectItem );
 
//////////////
// Draw progress controls here
// *Do not use paintdc (it validates the whole client)
CClientDC dc(this);
 
//get the item rect
int nDrawIndex = List.GetTopIndex();
for ( int nIndex = 0;
nIndex < List.GetCountPerPage();
nIndex++ )
{
//Draw item -> nDrawIndex
nDrawIndex++;
}
 
CListView::OnPaint();
}
OMG | :OMG: OMG | :OMG: OMG | :OMG: OMG | :OMG:
 
There it is! Now you know how to really draw a progress control!! And a new trick that will complement your other programming.
 
Roll eyes | :rolleyes: -Mike Luongo
GeneralRe: HERE's the correct waymemberMax Santos19-Jul-03 15:51 
GeneralYOU'RE DOING IT ALL WRONG!!!memberMike Luongo8-Dec-01 8:16 
GeneralMany bugsmemberTre20-Nov-01 14:29 
GeneralRe: Many bugsmemberAnthonyJ28-Apr-03 7:16 

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130617.1 | Last Updated 3 Sep 2001
Article Copyright 2001 by Jinhyuck Jung
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid