 |
|
|
 |
|
 |
Hi!
I've found a bug: when user selects multiple cells, only one (last selected) cell is highlighted.
To fix this replace code in CGridCellProgress::Draw :
if (bBacklit)
replace with
if (bBacklit || GetState() & GVIS_SELECTED)
That's all! Good luck!
|
|
|
|
 |
|
|
 |
|
 |
Another issue cropped up when trying to put a progress control in a narrow column (or the user resizes the column to a very narrow width). The percentage value ends up being displayed on top of adjacent cells. I don't know if this is a desirable feature, but personally did not like it. I added an if check to check if the width of the percentage text is greater than the width of the rectangle passed in the CGridCellProgress::Draw() method.
I added the following line in the "if (m_bPercentage)" block immediatly after the "pDC->DrawText (s, rcTmp, DT_CALCRECT | DT_SINGLELINE | DT_RIGHT | DT_NOPREFIX);" line:
// Only put the percetage value in if the
// width of the cell is large enough to
// fit it.
if (rcTmp.Width() < rect.Width())
{
rcTmp.left = rect.right - rcTmp.Width ();"
.
.
.
rcTmp.left = rect.left;
}
This will simply cause the percentage not to display if the column width is to narrow for it. A future enhancement would be nice if it displayed the percentage on the little "tooltip" that pops up when hovering over the cell.
Steven Konopa
|
|
|
|
 |
|
 |
You have been a busy chap!
Its nice to see that the article has been of use to somebody. I (and other authors I suppose) always wonder whether people have been downloading the code, liking it, disliking, changing it, etc.
I'll integrate your changes at the weekend and put them in. I am rather surprised at the PathCompactPath error though - you'd think the SDK would be a bit more solid, wouldn't you?
I even looked to see if there was a KB article on MSDN about the issue too...
Thanks for the changes,
Iain.
|
|
|
|
 |
|
 |
I've tried to look it up in the Knowledge Base on MSDN myself and came up empty when I originally discovered the problem. I also tried to just "Google" it up on the 'Net in general, and again, pretty much came up empty handed. One detail I did forget to mention was that this was all while using Visual Studio .NET 2003.
I also tried looking through this site and it's accompanying message forum to see if anybody else encountered the same type of problem with the Grid Control or any of it's offshoots/add-ons, and again - nothing.
I haven't tried it yet, but maybe I ought to try a simple program that just calls the PathCompactPath function and see if the same problem exhibits itself. That way, I could rule out that it is the Grid Control and perhaps prove it is the API itself. I'll also have to try this under VS 2005 (I have a copy of the Standard Edition on my laptop).
But, anyway, thanks for the nice bit of work on this Progress thing. I was about to write this myself, only to find I was beaten to the punch, since this was excatly what I needed for a current project I am working on.
Steven Konopa
|
|
|
|
 |
|
 |
I've just added a couple of lines to my demo dialog program:
m_Grid.SetColumnCount (2); m_Grid.SetRowCount (10);
m_Grid.SetFixedRowCount (1); m_Grid.ExpandColumnsToFit ();
in order to test the problems, and I don't see the effects you are describing. The strings collapse to a single character and a single dot, while the percentages just get drawn right-justified.
When the article was written, I was running Win2K, but my dev machine is now XP.
What OS are you running on?
Iain.
|
|
|
|
 |
|
 |
I am running Windows XP Pro w/ Service Pack 2.
I did make some changes to the "demo" program - using it to basically "mock-up" a prototype dialog that I am going to pitch to my customer. I've also added a "tree-column" using Ken Bertelson's Grid Tree Control:
(in CGridPogressCellDlg.h):
CTreeColumn m_TreeColumn;
unsigned char ucPatternAry[] = {1,2,3,3,2,3,3,1,2,3,3,2,3,3,2,3,3,2,3,3};
m_Grid.SetColumnCount (11);
m_Grid.SetRowCount (21);
m_TreeColumn.TreeSetup( &m_Grid, // tree acts on a column in this grid
TREE_COLUMN, // which column has tree
sizeof( ucPatternAry), // total number of rows in the
// tree if totally expanded
1, // Set fixed row count now
ucPatternAry,// Tree Level data array --
// must have aiTotalRows of entries
TRUE, // T=show tree (not grid) lines
FALSE); // do not use images in tree
First test purposes, I put a single progress cell in column 9. I then manually shrunk it way down.
m_Grid.SetCellType (1, 9, RUNTIME_CLASS(CGridCellProgress));
pProg = (CGridCellProgress *)m_Grid.GetCell (1, PROGRESS_COLUMN);
pProg->SetText ("Reading");
pProg->SetPos (0);
The code in the "OnTimer" method was modified as follows:
CGridCellProgress *pProg;
pProg = (CGridCellProgress *)m_Grid.GetCell (1, 9);
pProg->SetPos ( (pProg->GetPos () + 1) % (pProg->GetUpper ()+1) );
m_Grid.Invalidate ();
Any of these factors may cause the problem to arise. I guess, if push comes to shove, I could just e-mail the entire project zipped up and let you bang on it for a bit.
Steven Konopa
|
|
|
|
 |
|
 |
Found an really weird bug, and don't even know if it is a bug in the Win32 API (in this case, the PathCompactPath function) itself or a problem with the Grid Control code.
The problem is that whenever a progress control is put in a cell with a very small column width (say, less than 12 pixels), a "Run-Time Check Failure #2 - Stack around the variable 'szText' was corrupted." message box is generated and displayed. I traced it down to the PathCompactPath function call inside the CGridCellProgress::Draw() method (around line 165 or so). I have no idea exactly what is the cause of the error, but it is related to when PathCompactPath tries to fit an ellipse ("...") in a width that is to narrow (less than about 12 pixels given the default font in the grid control). Yes, why would anybody want to put a progress control in such a narrow column width, but if the grid control can allow it, than we better be able to handle it.
To fix/get around this problem, I implemented the following code, starting at line 167 (inside the "if (m_bCompactPath)" block). The comment should explain it sufficiently:
// For some reason, the stack gets corrupted if
// PathCompactPath tries to compact a string to
// fit in a width less than the width of a "..." string.
// (A "Run-time Check #2" message box pops-up.)
// It is unknown if this is a bug in PathCompactPath itself,
// or a bug in the GridControl code. Check what the width
// of an ellipses ("...") string would be via a "DrawText"
// method using the "DT_CALCRECT" flag. If the width of
// the rectangle into which to compact the path text is less
// than the width of the "..." rectangle, then don't attempt
// to call the PathCompactPath.
CRect rcEllipse (rcTmp);
pDC->DrawText ("...", rcEllipse, GetFormat() | DT_CALCRECT | DT_NOPREFIX);
if (rcTmp.Width () > rcEllipse.Width())
{
if (PathCompactPath (pDC->GetSafeHdc (), szText, rcTmp.Width ()))
s = szText;
}
Steven Konopa
|
|
|
|
 |
|
 |
Hi Iain!
I'm working only with vm.I've create an ocx(excuse my poor english....i'm italian)with several methods and properties.The cells of the grid in vm could be edited(combo ceck ecc..).I'll try to use your class and i'll send you an e-mail when finished
|
|
|
|
 |
|
 |
Hi!
I'm using the grid inj virtual mode with database.Is it possible to use your cell type in vm?
|
|
|
|
 |
|
 |
I've not actually used VM before, so I couldn't give you a straight answer. Looking at the CGridCtrl's
article, and a quick peek at the souce, I don't think VM is compatible with any cell types. I could
be wrong though.
If I am wrong, and my cell type needs a change or two, let me know and I'll update the code.
Good luck!
Iain.
|
|
|
|
 |
|
 |
I've had a further look at virtual mode, and I'm *really* sure that virtual mode only works with
the default cell type. Look at:
CGridCtrl::GetCell (...) and
CGridCtrl::GetDefaultCell (...).
That said, you could use CGridCtrl::SetDefaultCellType (RUNTIME_CLASS(CGridCellProgress)), and
enhance the cell type to notify and ask for the progress information at each cell position. If you set the
position to min, and disable percentages, then it behaves like a normal cell.
I hope that helped a little more,
Iain.
|
|
|
|
 |
|
 |
I feel all choked up. *Sniff*.
Iain.
|
|
|
|
 |
|