Catching the cancel event of console application

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,
 
M

Mr. Arnold

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
 
G

Guest

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top