473,503 Members | 11,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Console App capturing close button event

Hi,
I have a console app, i want to be able to do some clean up when the
user exits the application. So, i need to capture the red close window
button event on the "cmd.exe" window. How can i do this?

I know that i can make my app a windows app and hide the window - right
now, this is not enough of a reason to go this route. And in that case,
i would have to have the user to go to the task manager or provide
another means to shutdown the app when needed such as another utility
program or write code into the prog to check for an already running
instance and shut it down and then continue.
thanks,
BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 19 '06 #1
3 7817
Willy posted sample how to do this
http://groups.google.com/group/micro...88a7bf4cfb4832

"Meya-awe" wrote:
Hi,
I have a console app, i want to be able to do some clean up when the
user exits the application. So, i need to capture the red close window
button event on the "cmd.exe" window. How can i do this?

I know that i can make my app a windows app and hide the window - right
now, this is not enough of a reason to go this route. And in that case,
i would have to have the user to go to the task manager or provide
another means to shutdown the app when needed such as another utility
program or write code into the prog to check for an already running
instance and shut it down and then continue.
thanks,
BRAMOIN


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Apr 19 '06 #2
I am using C#, so i don't know how to import Kernel32 into it. in any
case, when i used the other suggestion: Binding to the process, it does
not work. Here is a simplified version of my code

namespace progName
{
class progName
{
private static progName pName = null;

public delegate void OnExited(object o, System.EventArgs e);

// other variable initializations

public progName()
{ // some object initialization }

[STAThread]
static void Main(string[] args)
{
pName = new progName();

System.Diagnostics.Process thisProc =
System.Diagnostics.Process.GetCurrentProess();

thisProc.EnableRaisingEvents = true;
thisProc.Exited += new EventHandler(pName.OnExited);

while(pName._shutDown == false)
{
thisProc.WaitForExit();
pName._shutDown = true;
}

// psuedo code ....Call other objects shutdown
}

pubic void OnExited(object o, System.EventArgs e)
{
// psuedo code ... Call other objects shutdown
}
}
}

I put a breakpoint on the first line in OnExited and it is never called
when i close the window.

BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 19 '06 #3
Correction: Binding to the process worked and the
System.Diagnostics.Process method did not work. Also, this binding to
the process method that i have mentioned is in the link suggested by
Willy: news:5A**********************************@microsof t.com...

BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1626
by: ashutosh.bhardwaj1980 | last post by:
Hi, I amdeveloping a web site in ASP and it is a secure site. I would like someone to help me on this: -->i dont want 2 users to accesss my site with the same username parallely. --> Also...
2
1697
by: orekin | last post by:
Hi The application I am working on has a starting screen with some configuration choices and the following: - OK button - QUIT button - x button in the Control/System menu box (top right...
10
5996
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
12
3729
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would...
10
8443
by: shiry | last post by:
Hi, I need to do some important cleanup before my console application exists. I used the console ctrl event. This is working well and it fires for all cases, including the CTRL_CLOSE_EVENT (if I...
3
2018
by: Sujoan | last post by:
Hi, What is WMI? Is it possible to use WMI event to capture a Toolbar button click(using RSOP_IEToolbarButton object) from a DLL(A Browser Helper Object in my project)?If so,please provide me some...
4
1578
by: miha.vitorovic | last post by:
Hi all. I know this is more of a DOM question, but here it goes: Browser == Firefox suppose I have two frames. One has many links and is opening pages in the other one. I would like to check...
2
3038
by: =?Utf-8?B?TmVldGE=?= | last post by:
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...
2
3563
by: Nageshwarrao | last post by:
Hi All, I have a window.open() popup.In which I placed an "Close" button.when I Click on that "Close" button it will pass some information to the Database and after that the window will...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.