473,804 Members | 3,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3063

"Neeta" <Ne***@discussi ons.microsoft.c omwrote in message
news:1D******** *************** ***********@mic rosoft.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 = GetConsoleWindo w();
if (hwd != IntPtr.Zero)
{
EnableMenuItem( GetSystemMenu(h wd, 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***@discussi ons.microsoft.c omwrote in message
news:1D******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3941
by: Hautzendorfer | last post by:
Hello, I'm currently working on some printing stuff: I have to print out several .xml files using a stylesheet. Therefor I choose the Internetexplorer PlugIn via SHDocVW. My problem: After sending the print command via ExecWB for the first .xml document either the preview or the printer selection window occurs (depending on the passed parameter). This behaviour is ok.
5
2263
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here is to ensure that no child window can close while it is in a state where user entered information can be lost. I have just noticed that while the Closing event is caught if I click the X on the child window, it is not caught if I click the X on...
2
2522
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the user wants to save the data, but when the Application closes this event isn't thrown automatically. I added a loop to close each child window, but can't seem find how to catch the child window's cancel of the Closing event, so even if the user...
11
18352
by: ryanmhuc | last post by:
I have a function which needs to cancel the input into a text field on a form. I cancel the event in IE fine and the text does not get entered. But for firefox (1.0) I cancel the event and the text still gets entered. I've stripped the function down just to try to get it to work in Firefox. The alert does happen on the keydown event so it should be cancellable. function formatInput(e){
5
1386
by: James Hancock | last post by:
I would like to have some way that if there is no error handling and an exception is thrown in our application that it will do a last resort error handling so that we can send information to support about the error. Anyone have any ideas? I've tried putting a Try/catch around the Application.run() command but it only works some of the time. Thanks, James Hancock
3
17221
by: Elp | last post by:
Hi, I've developped a Window Form C# application which main form contains several activex controls. No problems most of the time but on some machine, the application crashes when the main form is closed with a NullReferenceException caused by the DisposeAxControl which, i guess, is supposed to dispose one of my ActiveX. This is not a big problem as the application is closing anyway but i'd like to suppress this crash message. However,...
2
1309
by: Eric Sabine | last post by:
I built a generic exception handler form which allows the user to get information from it, print it, email it, etc. for exceptions for which I explicitly didn't handle in code, such as missing permissions on a stored procedure, etc. I use this exception handler in all of my applications and it can be called as simply as follows try ... catch ex as sqlexception ExceptionHandler(ex, otherData1, otherData2)
5
2610
by: lord.zoltar | last post by:
How can I prevent the big close button in the top of the window from closing the window? I want to have and "are you sure?" confirmation so the user must press "Yes" before the program ends. Right now, I've tried catching the FormClosing and FormClosed events. The message box appears at the right time, but since the form is already closing, it doesn't matter if the user presses "Yes" or "No". how do I cancel the FormClosing?
3
1831
by: Anthony P. | last post by:
Hello Everyone, I am writing a Windows Mobile 5.0 application using VS 2..8 in VB.NET. When someone clicks the "Exit" menu option, which generates a button_click() event, I find it easy to display an "Are you sure?" MessgeBox before the application closes. That way, if they accidentally selected exit, they have a chance to back out. But I also want to catch the _closing() event on the form in case the user clicks the application close X...
0
9710
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9163
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4304
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 we have to send another system
3
3000
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.