Link to home
Start Free TrialLog in
Avatar of bs161900
bs161900

asked on

Where to place my CWnd::OnTimer(...) call ?

Hi experts,

I am working on a SDI application, that on startup builds a table of about 1000 values.
Since those calculations can take a few seconds, I want a modal dialog box to pop up,
showing a progressbar as the calculations advange, and disappear when all is done.
I use a timer to proces each value in the table. My problem is, that I do not know
where to place my CWnd::SetTimer(...) call. (Fires at roughly 55 millisecond intervals).
When I call it from the CDialog::OnInitDialog() my dialog box does not appear always,
especially on slower machines. Here the dialog´s WM_PAINT message seems never to get
handled.
Could someone tell me how to solve this one. Any help would be greatly appreciated.
Avatar of GlennDean
GlennDean

I would say place it in the constructor to the class you expect to process the WM_TIMER messages.  Then, in ClassWizard, add a handler for the WM_TIMER message.
   Oh, using a value under 100 milliseconds for how often you want to receive WM_TIMER messages "appears" to default to a value of 100 (atleast on Windows 95).  Somehow the timeslice value is relevant but I don't know how.
   Glenn
Hi,

R U trying to process one record at a time, whenever a Timer message called?. If yes, what I suggest is, Display a modal dialog box, put the progress bar in it. And InOnitDialog(), Initialise the progress bar, set the range to it, and set the timer using this->SetTimer(1, 10, NULL);. Then map the WM_TIMER message and do the following

.....::OnTimer(...)
{
KillTimer(1);
while(records are there)
{
process the record.
update the progress bar.
continue for the next record.
}
}

That will the required job.

Hope this helps.
VinExpert
Avatar of Zoppo
Hi bs161900,

Try a ShowWindow( SW_SHOW ) in OnInitDialog before the SetTimer() function (and after the CDialog::OnInitDialog()) to force the dialog being displayed ...

ZOPPO
This is how I did it, without WM_TIMER.

In your CProgressDialog create a function that looks something like this:

void CProgressDialog::SetProgress (int nCurrentPost, int nTotalPosts)
{
float f;
nCurrentPost++;

f = (nCurrentPost / (float)nTotalPosts) * 100;
f = f + (float)0.5;
int nProgress = (int)f;

m_ctrlProgress.SetPos (nProgress);

CString str;
str.Format(_T("Importing post %d of %d"), nCurrentPost, nTotalPosts);
m_ProgressStatic.SetWindowText(str);
}

then in your class where you start to build your table, first create a modeless dialog:
CProgressDialog dlg;
dlg.Create (IDD_PROGRESS_DIALOG);

then call the function SetProgress:

for (int i = 0; i < .......
    dlg.SetProgress (i, nNumberPosts);

When you are done destroy the dialog:
dlg.DestroyWindow ();

That worked for me, perhaps not what you were after....

Good luck....
/joakimf

ASKER CERTIFIED SOLUTION
Avatar of TallBoy
TallBoy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bs161900

ASKER

I learned a lot from this little piece of code. It pushed me in the right direction.

Thanks