Re: Sometimes Cancel button doesn't work
vicky wrote:
Hi ALL!
I am using a SDI application, in which, i am using a modeless dialog
to show progress control.
I am calling a javabean program which is returning data and I am
checking the status of this job in a loop,when, job is finished, I
destroy the dialog.
But when i press CANCEL button while processing, cancel button does
not get depressed and call for canceling the current job is not being
made.
I tried my level the best but unable to understand the problem.
The problem is that you are looping. As long as that loop code is
running your program is not checking for and responding to messages. So
paint messages (to depress the button) and button click messages (to
tell you to stop) are not processed. Generally speaking, you need to
avoid time consuming loops within the main thread: Just do something
brief and then return to MFC so the program will continuously process
waiting messages.
The ultimate solution is to do such lengthy loops in a secondary thread.
But you might want to avoid threading complications by using SetTimer
and a WM_TIMER message handler: For each timer message just do one step
of your looping operation, then return. This will give messages, like
the cancel click, a change to get in between timer ticks.
--
Scott McPhillips [VC++ MVP]