redesign it.
your function GiveTime() works perfectly in my case.
Could you put the time consuming function into a worker thread and have
that
thread use PostMessage() to progress bar window. Then it could yield some
time once in a while.
Otherwise in your loop you could call a function like:
//
// Release main thread for background processing
//
void GiveTime()
{
// Idle until the screen redraws itself, et. al.
MSG msg;
while (::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
if (!AfxGetThread()->PumpMessage( )) {
::PostQuitMessage(0);
break;
}
}
// let MFC do its idle processing
LONG lIdle = 0;
while (AfxGetApp()->OnIdle(lIdle++ ))
;
}
When you call this it will allow other threads to process if there are
message pending.
Tom
"Peter" <Peter@discussions.microsoft.com> wrote in message
news:C78A4483-3358-429F-A611-3E8FE7A9C20F@microsoft.com...
Hi,
I spent some day with adding progress bar to my MFC application. The
reason
is several functions which may needs approx. tens of seconds for
processing.
All functions which needs to display and update progress bar are
handlers
for menu commands.
Progress bar control is placed into small modeless dialog, where close
button can be used for closing it and aborting time-consuming function.
My progress dialog is created in different thread (derived from
CWinThread)
than handlers of menu commands.
Mostly I have problem that close button on progress dialog does not
accept
mouse click and it's not possible to abort time-consuming function.
I think that it is probably some problem with MFC multithreading and
processing messages.
Can be modeless dialog started,displayed,updated in different thread in
the
same time when menu command handler is processed ?
Or some other tip how to organize code, classes, threads ?
Peter