 |
|
 |
THis is a good example, now you shoudl udpate it for c# since it can be a useful tool.
|
|
|
|
 |
|
|
 |
|
 |
Well, thank Jinhyuck Jung for the work. It seems good for the control to work. But I think it can do more, so I do some modification to the control.
Now it can show some text other than the percentage text, and even more, it can show some different color for the progress according to its value.
Maybe I will submit the codes on later if someone needs it. But the description of submitting confuses me a little. I don't know how to contact the original author.
So just wait...
Mike
|
|
|
|
 |
|
 |
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:
BOOL CListCtrlEx::GetCellRect(int iRow, int iCol, int nArea, CRect &rect)
{
CRect colRect;
if (!GetHeaderCtrl()->GetItemRect(iCol, colRect))
return FALSE;
if(!GetItemRect(iRow, rect, nArea))
return FALSE;
rect.left = colRect.left;
rect.right = colRect.right;
return TRUE;
}
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
|
|
|
|
 |
|
 |
Here is a more effecient method to dynamically embed progress bars into a list ctrl. (I used a CView-derived class -- though you can do pretty much the same thing in a CListCtrl-derived class). <code> void CEmbeddedProgressTest1View::OnPaint() { CListCtrl& wndList = GetListCtrl(); CHeaderCtrl* pwndHead = wndList.GetHeaderCtrl(); CClientDC dc(this); int iIndex = wndList.GetTopIndex(); for (int i = 0; i < wndList.GetItemCount() && i < wndList.GetCountPerPage(); i++, iIndex++) { CRect rcItem; wndList.GetSubItemRect(i, m_iProgress, LVIR_BOUNDS, rcItem); CProgressCtrl* pProgress = (CProgressCtrl*)m_paProgressBars.GetAt(iIndex); pProgress->MoveWindow(rcItem, TRUE); pProgress->Invalidate(); } CListView::OnPaint(); } </code> For this example, I created my Progress bars in OnInitialUpdate and set their ranges and steps there, though you can do those anywhere. I also had a member variable (m_paProgressBars) that stored the pointers to the progress bars after creation. (The index of the pointer in the array is also the item number in the list). Another member variable (m_iProgress), indicated the SubItem number where the progress bars should be drawn. Zac Howland
|
|
|
|
 |
|
 |
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();
}
There it is! Now you know how to really draw a progress control!! And a new trick that will complement your other programming.
-Mike Luongo
|
|
|
|
 |
|
 |
Mike Luongo wrote:
I hope this earns me some brownie points on this site. Because no one has emailed me here is the solution:
I think you must create a article and submit it to codeproject, this way everyone can read it.
MSN:maxsnts@hotmail.com
|
|
|
|
 |
|
 |
Thanks for posting a solution to this problem, but I don't think it is correct. The object is to redraw one column with a progress control -> Not reinvent/copy drawing of the whole control.
I have a nice little trick for drawing only one column that won't flicker or have a million child windows and all you do is draw the progress control. It is too long to post. Anyone who needs code could email me at luongomi@msu.edu
Until then, please do not use this code...
-Mike
|
|
|
|
 |
|
 |
Dragging the columns to a different location causes many problems with the status bar and where it is painted. Also, in the 5 minutes I spent looking at this example, it appears that the location of the progress control is hard coded into the first column. This is a very poor implementation.
|
|
|
|
 |
|
 |
Well, I'd be interested to see what you found, since it only takes 30 seconds to change the sample to draw to later columns, and they seem to work fine. In fact, its actually the column zero case that has problems...
--
AnthonyJ@planetquake.com
www.anthony.co.uk
|
|
|
|
 |