How can a console app detect when it is being closed?

Don Clugston dac at nospam.com.au
Tue Aug 1 02:05:57 PDT 2006


Suppose I have the trivial console app:

import std.stdio;

static ~this()
{
     writefln("Exiting program");
}

void main()
{
     scope (exit) writefln("Exiting scope");
   for (;;) {
     writefln("xxx");
  }
}

When you press ctrl-C, neither of the exit messages are printed.
What I'd like to do is pop up an "Are you sure?" message box on any 
attempt to close the program. I could create an invisible window from 
the console app, but I'm hoping for something less ugly.  I just don't 
know how to intercept WM_QUIT messages from a console app -- any ideas?



More information about the Digitalmars-d-learn mailing list