IonicWind Software

IWBasic => Console Corner => Topic started by: JoaoAfonso on September 07, 2011, 01:42:38 PM

Title: Detecting close on console
Post by: JoaoAfonso on September 07, 2011, 01:42:38 PM
Good evening.

Is there a way to detect when an EB/IW console app receives the message to close?

I pretend to run a subroutine with some instructions before the console closes. The workaround I am thinking is to use window/dialog, but what I really want is detect the console window close.

Any info and/or a little sample would be appreciated.

On a side note, I still use an EB paied version to do some small apps. What I need to do to get IW latest version? Or what IW version I can download/use considering I'm a subscribed member? I'm going to read posts in proper forum, but as this matter came into my mind right now...

Thanks in advance.

Best regards,
Title: Re: Detecting close on console
Post by: LarryMc on September 07, 2011, 05:29:49 PM
Don't know exactly what you are wanting to do but this gives you something to play with.

$include "windowssdk.inc"

OPENCONSOLE
SetConsoleCtrlHandler(&cleanup,true)
PRINT "hello"

DO:UNTIL INKEY$ <> ""

CLOSECONSOLE
cleanup(-99)
END

sub cleanup(t:uint),int
/*
0 A CTRL+C signal was received, either from keyboard input or
from a signal generated by the GenerateConsoleCtrlEvent function.

1 A CTRL+BREAK signal was received, either from keyboard input
or from a signal generated by GenerateConsoleCtrlEvent.

2 A signal that the system sends to all processes attached to
a console when the user closes the console (either by clicking
Close on the console window's window menu, or by clicking
the End Task button command from Task Manager).

5 A signal that the system sends to all console processes
when a user is logging off. This signal does not indicate
which user is logging off, so no assumptions can be made.
Note that this signal is received only by services. Interactive
applications are terminated at logoff, so they are not
present when the system sends this signal.


6 A signal that the system sends to all console processes when
the system is shutting down.

*/
messagebox 0,"I'm in cleanup","info"+str$(t)
return 0
endsub


LarryMc
Title: Re: Detecting close on console
Post by: JoaoAfonso on September 08, 2011, 04:33:16 AM
Good morning.

That was exactly what I was after. It's like a destructor for the console.

I have a few years of IB/CB/EB/CB/... and never saw this console control :) I always forget to check windowssdk.inc previously, though...

Thank you for the information.
Title: Re: Detecting close on console
Post by: LarryMc on September 08, 2011, 05:29:35 AM
OPENCONSOLE / CLOSECONSOLE has always been there and has nothing to do with windowssdk.inc

I always use Sapero's windowssdk.inc because it keeps me from having to look up the declarations for API functions I might use.

Glad it helped you.

LarryMc