Catching the cancel event of console application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I creating a console application.
In that I want to catch the cancel event of the console application .Please
guide me in this.I figured out that I will have to attach event to the
console.How can I do that?

Please help !

Thanks,
 
Neeta said:
Hi,

I creating a console application.
In that I want to catch the cancel event of the console application
.Please
guide me in this.I figured out that I will have to attach event to the
console.How can I do that?

The only thing you may be able to do is disable the Close button. That way,
the user has to press an exit key that you check for in code or the user has
to go to Task Manager to kill the Console application.

http://www.codeproject.com/tips/disableClose.asp
 
Thanks for the reply I tried the following code:


IntPtr hwd = GetConsoleWindow();
if (hwd != IntPtr.Zero)
{
EnableMenuItem(GetSystemMenu(hwd, false),
SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
}

It seems EnableMenuItem works absolutely fine with forms .For Forms it
disables the cancel buton and also the Alt+F4 option.But when i use it for
console it doesnot.
Am I missing something here ?
 
Back
Top