 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Yahia El-Qasem Guest
|
Posted: Tue Jul 29, 2003 7:51 am Post subject: Re: How to Abort a Heavy Process using the ESC key ? |
|
|
Just a guess :
Assign ESC key as hotkey for your app... setup a handler for the hotkey...
use Application->ProcessMessages () within you loop between any slow
operations...
HTH
Yahia
"Roberto Gomez Torres" <roberto (AT) tiempo-digital (DOT) com> schrieb im Newsbeitrag
news:3f26157d (AT) newsgroups (DOT) borland.com...
| Quote: | Hello Pals.
Hope you can help me with this one.
My application can start a heavy process making many operations inside a
slow Loop.
The user may want to stop that process and abort using the ESC key.
I want to detect when the user press the ESC key, display a Dialog asking
for confirmation to break the process, and tell the function to stop
working.
Which is the optimal way to do it ?
Please let me know.
And thanks a lot in advance.
======================
Roberto Gómez Torres
Tiempo Digital
Mexico City, Mexico
www.tiempo-digital.com
[email]roberto (AT) tiempo-digital (DOT) com[/email]
======================
|
|
|
| Back to top |
|
 |
oLiVeS Guest
|
Posted: Tue Jul 29, 2003 8:42 am Post subject: Re: How to Abort a Heavy Process using the ESC key ? |
|
|
GetAsyncKeyState is probably what you are looking for.
I used this myself to escape an image process in a project I did a while
back.
#define WAS_PRESSED(s) ((s & 0x0001)==0x0001)
short state = GetAsyncKeyState(VK_ESCAPE);
if(WAS_PRESSED(state))
{
// Cancel Operation
}
|
|
| Back to top |
|
 |
Simon Elliott Guest
|
Posted: Tue Jul 29, 2003 8:50 am Post subject: Re: How to Abort a Heavy Process using the ESC key ? |
|
|
Roberto Gomez Torres <roberto (AT) tiempo-digital (DOT) com> writes
| Quote: | Hope you can help me with this one.
My application can start a heavy process making many operations inside a
slow Loop.
The user may want to stop that process and abort using the ESC key.
I want to detect when the user press the ESC key, display a Dialog asking
for confirmation to break the process, and tell the function to stop
working.
Which is the optimal way to do it ?
|
This depends whether your heavy process is in a thread or not, and
whether or not it's acceptable for the confirmation dialog to be modal.
I don't know what the optimal method is, but this is how I'd do it.
Others here may have better ideas!
Assuming:
* the heavy process is not in a thread.
* a modal dialog is not acceptable
* the heavy process is called from your main form:
When the heavy process is running, set a flag (a bool instance variable
of your main form).
Use the OnKeyDown event of the main form. In the event handler, check
for the ESC key being pressed at the same time as the flag is set. If
this is the case, the OnKeyDown event handler creates the confirmation
form.
When you design the confirmation form, give it a closure property which
executes when the OK button is pressed. (This allows your confirmation
form to be used generically so you won't need to design a new
confirmation form for each heavy process you want to terminate.) When
your OnKeyDown handler creates the form, it should assign another method
of your main form as this closure. Let's call this method
"TerminateHeavyProcess".
TerminateHeavyProcess sets another flag (a bool instance variable of
your main form).
Your heavy process needs to check this flag from time to time and return
if the flag is set. It also needs to allow events to happen so that the
confirmation form is displayed, perhaps by calling
Application->ProcessMessages() every now and again.
--
Simon Elliott
http://www.ctsn.co.uk/
|
|
| Back to top |
|
 |
Roberto Gomez Torres Guest
|
Posted: Wed Jul 30, 2003 4:47 pm Post subject: Re: How to Abort a Heavy Process using the ESC key ? |
|
|
Thank you pals.
I will try all your sugestions.
Muchas gracias.
======================
Roberto Gómez Torres
Tiempo Digital
Mexico City, Mexico
www.tiempo-digital.com
[email]roberto (AT) tiempo-digital (DOT) com[/email]
======================
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|