Thanks, Tom. As I understand, the only way to make it work is to have
You could put the heavy computation into a worker thread which would allow
your UI thread to process or use something like calling the following
routine in the loop where the work is being done (cycles being hogged).
/
// 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++ ))
;
}
Tom
"Eugene" <ypodolyan@hotmail.com> wrote in message
news:1158103038.339035.221380@i3g2000cwc.googlegroups.com...
I have a problem. In my application, a user can trigger a heavy
computation of various properties from a dialog window that also shows
the progress with a CProgressCtrl. I do not know how to stop the
processing if the user decides that the process takes too long.
I have a PreTranslateMessage function that checks for ESC key, but it
is useless. No matter how many times I press ESC during the
computations, the PreTranslateMessage is not called until the
computations are complete.
Putting Sleep() inside the computations doesn't help. The whole Process
sleeps and PreTranslateMessage is not called. And I do not have
separate Threads.
Is it possible to do something here without using Threads? I want to
avoid it because my functions, which perform the computations, are the
members of a class and use a lot of class members (data). If I am to
use threads, these functions cannot be class members anymore and I will
have to pass a lot of stuff to them, including a pointer to the
CProgressCtrl, which may not work this way.
Any suggestions?