 |
|
 |
Easy to use. Works fine on various windows versions (expected on vista but that is not a problem of the code).
|
|
|
|
 |
|
 |
Hi Hans,
Once again you have done really good work. Thank for that.
I have a problem if I want to use it for a small range like 0...4.
The progress bar will not be filled to 25% at the first StepIt() call
and it never reach the 100% filling. Only 75% will be filled.
To reproduce it you can try this code in your OnButton1 method in demo app
instead of yours:
wndProgress
.SetRange(0, 4)
.EnableTimeLeft(m_bTimeLeft)
.SetText(_T("This is a progress window...\n\n")
_T("Try dragging it around, hitting Cancel or pressing ESC."));
for (int i = 0; i < 4; i++)
{
wndProgress.StepIt();
wndProgress.PeekAndPump();
Sleep(500);
}
Any idea?
Bye
Joerg
|
|
|
|
 |
|
 |
Hi Joerg,
Thanks for the kind words.
I assume you are trying this on XP? I just tested the code you gave and it works fine on Win7 - starts at 25%, then 50, then 75, then 100. Oh, well.
To solve this problem, there are several things to try: first, try to put a wndProgress.UpdateWindow() after the StepIt(). If this doesn't fix it, then you must get rid of the Sleep(500). The Sleep() puts the entire thread to sleep, including the message loop. Using Sleep() in a GUI thread is a very bad thing - I assume you just did this for a demo. You can use this function instead:
void Delay(DWORD dwMsecs)
{
static BOOL bInDelay = FALSE;
if (bInDelay)
return;
bInDelay = TRUE;
DWORD dwStrtmsecs, dwCurmsecs;
dwStrtmsecs = dwCurmsecs = ::GetTickCount();
do
{
if (!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
break;
}
dwCurmsecs = ::GetTickCount();
if (dwCurmsecs < dwStrtmsecs)
dwStrtmsecs = dwCurmsecs;
} while ((dwCurmsecs < (dwMsecs + dwStrtmsecs)));
bInDelay = FALSE;
}
Let me know if this works.
|
|
|
|
 |
|
 |
Hello Hans,
thank you for your fast response.
No I try this on Vista and yes the Sleep() is just for demo.
I have copied it to a XP and a Windows 2000 machine and it works as expected.
Your suggestions has no effect (on Vista).
I found something interesting for progress bar behaviour on Vista:
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/57899264-c902-4af9-a978-cfcae21e0b32/[^]
If I remove the manifest part
#pragma comment(linker,"/manifestdependency: ...
in the stdafx.h the progress bar works as expected.
I have success fully tried to use
::SetWindowTheme(m_wndProgress.GetSafeHwnd(), _T(""), _T("") );
But the problem is that I have to link the uxtheme.lib and this does not work on Windows 2000
which I have to support with my applications.
And the other problem: It looks ugly if all other controls have a vista visual style.
Perhaps tomorrow I will find an other solution.
Bye
Joerg
|
|
|
|
 |
|
 |
Hi Joerg,
I looked into this a bit more and found that this works perfectly on Vista:
wndProgress
.SetRange(0, 4)
.EnableTimeLeft(m_bTimeLeft)
.SetText(_T("This is a progress window...\n\n")
_T("Try dragging it around, hitting Cancel or pressing ESC."));
for (int i = 0; i < 5; i++) {
wndProgress.StepIt();
wndProgress.PeekAndPump();
Sleep(500);
}
Is this a possible solution for you?
|
|
|
|
 |
|
 |
Hello Hans,
yes this works but now the percent value in the caption will step over 100%.
This behaviour of the progress bar seems to be only a problem on Vista.
I will use your progress window without any workaround because most of the
users are still using Winodws XP and will update to Windows 7 in the future.
The window disapears on reaching the 100%, so most of the users will never
recognize the not full filled progress bar.
Again Hans, may thanks for sharing your ecellent code.
You will get my 5 for this progress window.
Bye
Joerg
|
|
|
|
 |
|
 |
I'll give a 10 if there' is,
ggg
|
|
|
|
 |
|
 |
Hello Hans,
Has anyone else reported this run time error when building the VS2005 project converted to VS2008? It works fine when I compile with VC6. I think that the problem might be a bug in the computation of the cbProperSize.
I'm running Vista (please forgive me) with both the VC6 and VS2008 compilers installed. The table below shows the sizes of the NONCLIENTMETRICS struct under both compilers and using the sizeof vs computed values.
cbProperSize sizeof(ncm)
VC6 344 340
VS2008 504 500
In both cases the computed size is 4 bytes too big. Maybe my development environment is flawed or maybe its a bug. In any event, just using the standard sizeof(OLD_NONCLIENTMETRICS) setting seems to eliminate the runtime error for me.
Thanks for all the great stuff you post!
|
|
|
|
 |
|
 |
Thanks for pointing this out. I only recently discovered this issue when another reader suggested deriving a new struct from NONCLIENTMETRICS, and setting the correct size in the ctor. However, I feel this may be overkill in this situation, and I have yet to see a need for iPaddedBorderWidth.
In any case, using the sizeof(OLD_NONCLIENTMETRICS) value will work, since Vista must handle the incompatibility caused by two struct sizes.
|
|
|
|
 |
|
 |
Could we have a C# version please please...
Tell me and I forget. Teach me and I remember. Involve me and I learn.
|
|
|
|
 |
|
 |
I usualy didn't read article from C++ section, but when i check this article in latest vote section and started reading, Wow... What a fantastic implementation.
Hope with in few days i will try to execute a C# version
5 from me !!!
|
|
|
|
 |
|
 |
That is a great article
You got my 5 to counter those silly one votes.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
 |
|
 |
For an article that is well written and provides a useful component I'm always surprised by the 1's.
Perhaps you've upset someone, Hans, with your well crafted solutions!
|
|
|
|
 |
|
 |
I don't know who they are or why they vote 1, but I'm pretty sure of one thing: they've never written an article.
|
|
|
|
 |
|
 |
Hans Dietrich wrote: I don't know who they are or why they vote 1, but I'm pretty sure of one thing: they've never written an article.
A few days ago I saw a good in depth article about an almost complicated technology(Detailed description of how two way data binding is done in .net) and I said what a good article. Much of a sudden I noticed on that site if a user comments and votes, the vote will be shown beside his/her comment. I saw a 1 and a reason attached to it: "This article didn't bind data to a ombobox". I can't remember the phrase exactly but it was almost like that. Yes really that stupid.
I'm trying to teach myself this: If there's a vote with no good reason and no chance for the author to fix a problem, then it's what an idiot did when he was unable to understand the article. It feels really bad but it's real.
You certainly know that those who have knowledge understand a great work, like it and thank you even if they say nothing.
We have a saying in Iran: A goldsmith understands real value of a jewel.
"In the end it's a little boy expressing himself." Yanni
|
|
|
|
 |
|
 |
You might be right, although my memory fails me sometimes, so I'm gonna give this a five now... see if anything changes. And if anyone here has an idea about what article I could write to release myself of the shame, please tell me. Anything at all. Just not something too hard.
EDIT: Nope! It wasn't me.
|
|
|
|
 |
|
 |
.dan.g. wrote: upset someone
I can't imagine Hans upsetting someone. He's a really cool guy.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
 |
|
 |
Maybe it's just an overflow of voting counter?
|
|
|
|
 |
|
 |
Very nice and subtle compliment: a 1 should be taken to mean a 6 over 5 - in case of this article, I agree. Very well written AND useful.
|
|
|
|
 |
|
 |
Any idea about a solution to let animation run even if no pump is given to popup window ?
The problem is that many COM interfaces took many time to wake up and the animation hang.
For example I normally open a progress window and then call Crystal Reports engine init, this tooks about 5 to 8 seconds..
Since I've seen many wonderfull ideas in your code... any suggestion ?
Good job as always.
Davide
|
|
|
|
 |
|
 |
Is the progress window's parent getting any messages at all when the Crystal Reports engine is initializing? If yes, then maybe you could set up a timer that calls the progress PeekAndPump() function while waiting for the engine.
|
|
|
|
 |
|
 |
Is what I've done... but timer has low priority and (and window paint even less) so the result when a call make intensive CPU usage is not as good as expected.
Another example is when a SQL Query (maybe minutes) is executed on the server itself, in this case the solution is an async exec, but I'm wondering a generic pourposes solution (maybe a thread that keep alive?), I've also explored this kind of solution but with poor results.
thank you again for your interest.
Davide
|
|
|
|
 |
|
 |
Why not roll an hourglass around until the init is finished, then begin the progress dialog? The user is used to an hourglass spinning while things prepare to happen.
|
|
|
|
 |
|
 |
in some cases (ie external process or DBCC procedure) some 'non breakable' operations are very long to execute.. So I'd prefer animation ( "user don't think we crash" - PKZIP 1.0 source when changing chararcter while zipping)
|
|
|
|
 |
|
 |
Why not running that Lengthly operations on a worker thread?
|
|
|
|
 |