471,338 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Catching the cancel event of console application

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,
--
Analyst Programmer
Jul 11 '07 #1
2 2893

"Neeta" <Ne***@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
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

Jul 11 '07 #2
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 ?
--
Neeta
Programmer Analysts
"Mr. Arnold" wrote:
>
"Neeta" <Ne***@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
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

Jul 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ron L | last post: by
11 posts views Thread by ryanmhuc | last post: by
5 posts views Thread by James Hancock | last post: by
3 posts views Thread by Elp | last post: by
2 posts views Thread by Eric Sabine | last post: by
5 posts views Thread by lord.zoltar | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.