How do I make a console mode program trap and act on te Exit triggered by clicking theX?

I am writing a (console mode for now) program, and I need for the program to save its current state before exitting. Currently, Windows just closes the program with no warning, when the X is pressed... I would like the program to autosave on close.
Posted on 2003-06-10 22:20:22 by V Coder
The "X" on the DOS window closes the VDM for this DOS seesion.
AFAIK, There is no requirement ( or method ) to notify the DOS session it's being closed.
But it does not stop you from programming a work around.

I am going to assume, that you are unable to port this program to a regular Windows program.

Note: It requires two programs, the original console program and an executor program that you need to write.

Look up the VDM programming in MSDN, and you can open your own VDM session in the which you can control the closing of. Then you must figure out a inter-process/session communication from the VDM executor program to the Console program running inside the VDM session.

Regards, P1 :cool:
Posted on 2003-06-11 09:59:16 by Pone

How do I make a console mode program trap and act on te Exit triggered by clicking theX?

I am writing a (console mode for now) program, and I need for the program to save its current state before exitting. Currently, Windows just closes the program with no warning, when the X is pressed... I would like the program to autosave on close.


One solution is to write your console program as a Windows GUI app and put in the usual message processing loop that handles things like closing down the window. A little publicized trick is that any GUI app can open up a console window (and then operate like a normal console application within that window). I haven't tried to do what you're proposing, but it's worth exploring to create a small Win32 GUI "shell" program that handles the close operation and then inject your console app into that program.

I'm in the process of rendering the first six chapters of "Windows Programming in Assembly Language" and, as it just so happens, Chapter Six discusses how to use console windows in a GUI application. When I get this up on Webster you might want to take a look at this.

Cheers,
Randy Hyde
Posted on 2003-06-11 13:23:51 by rhyde
Thanks Randy, Pone.

I should have waded into ICZ windows tutorials by now, and experimented with WinLoop etc...
I'll do it soon.
Posted on 2003-06-12 07:59:07 by V Coder