[fpc-pascal] Detecting console close with red X on windows
james at productionautomation.net
Sun May 19 19:10:10 CEST 2019
Thanks! That was quite helpful! I have a test program kind of working.
I notice I only get 5 seconds to do what I am going to before it closes, and I also notice that my program can no longer respond to keystrokes after I hit the red X. How do other programs get around this? For example if I open word for windows and type something and hit the X it asks if I want to save it and will wait indefinitely for a response. Is this a limitation because I am running console application, Is there a way I can do this with my console application as well?
Here is my test program:
var x,y: longint;
Function Console_Handler(dwCtrlType: Dword) : BOOL; stdcall;
Case dwCtrlType of
For X:= 1 to 2000000 do //this keeps the Console_Handler busy so my program continues to execute;
if SetConsoleCtrlHandler(@Console_handler, TRUE) then
Writeln('Console CTRL Handler Installed')
Writeln('Console CTRL Handler Not Installed');
Until CloseTheProgram or keypressed;
If Keypressed then
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Henry Vermaak
Sent: Sunday, May 19, 2019 11:44 AM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] Detecting console close with red X on windows
On Sun, 19 May 2019 at 14:33, James Richters <james at productionautomation.net> wrote:
> Could I please get an example of this? I see lots of examples of how to do it in C but when I try to translate to pascal I always struggle a quite a bit.
Have a look at the fpc source in packages/fv/src/w32msg.inc and search for SetConsoleCtrlHandler and then HandleConsoleCtrl. There's nothing to it, really.
fpc-pascal maillist - fpc-pascal at lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal