I have got the control to work. I needed to do a few fixes in it though.
Fixes: (as suggested here, but I found the suggestions too late)
A. OnPaint MUST use CPaintDC. There's no excuse for calling GetDC. This way, the control gets never validated! It's caught in an infinite loop, getting zillions of WM_PAINTs.
B. If you fix A, StepIt() doesn't redraw the control. InvalidateRect(NULL) in StepIt() does the trick.
What I did:
1. I have created a new thread for the "progress dialog". I create the progress dialog in InitInstance().
2. In progress dialog's OnInitDialog, I call SetTimer (and adjust the snake).
3. In OnTimer handler, I do StepIt().
4. In dialog's PostNcDestroy, I call PostQuitMessage to finish the thread.
5. When I want to close the dialog, I call DestroyWindow() on it from the main thread.
I tried to use the control in my app. I found that message boxes do not popup in front of the app after creating this control. A simple test of the fact is to create a message box immediately after the create call to the snake control.
Firstly, this is an Indefinite progress control. Any job thats indefinite has to be placed in a seperate thread(also read Johnny anonymous' comment). So Until I bring up a thread encapsulated(Like CAnimateCtrl's Play) version I advise the developers to put it in a seperate thread(I'm held up in other work currently).
As has already been mentioned by the author in another
comment, this control will work perfectly outside of
the main thread. For single-threaded applications it
can be made to work just as well.
The main problem is the Sleep() call located in
CMainFrame::OnStart(). This freezes all message
processing for the application and then the
abbrieviated message loop must process all the
pending messages before the control is updated
by the call the StepIt().
To fix the problem in the demo, do the following:
1) Remove the call to Sleep() in CMainFrame::OnStart()
(in a real single-threaded application you would
probably want to add some things to the event
2) Add timing code to the EZSnakeCtrl class.
Since sleep was removed, the control will be
drawing itself as fast as you machine will let
it. An easy way to control the speed would be
to use the timeGetTime() call to limit the
stepping to once every 10 milliseconds or so.
Here's one way to do that.
Add the following member variable...
Add the following in the constructor...
m_dwResolution = 10; // note: you may want to add a member function to set this at run time...
Add the following at the top of the CEZSnakeCtrl::StepIt()
You'll probably want to add some code to exit the
message loop if the WM_QUIT message as received or
if a custom message you've defined is posted to the
thread. The code above should take care of the
problems people are having.