473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prevent closing with Alt + F4

How do I make sure my program cannot be closed by using Alt + F4
--
Thanks for reading
Jul 21 '05 #1
3 7165
Well, you could override the KeyDown/KeyPress and ignore those
combinations, or handle the OnClosing event and check for what kind of
closing is performed

protected override void OnClosing(Cance lEventArgs e)
{
System.Diagnost ics.StackTrace O = new System.Diagnost ics.StackTrace( true);
System.Diagnost ics.StackFrame F = O.GetFrame(7);
if(F.GetMethod( ).Name == "DefWndProc ")
e.Cancel = true; // user ended the application (ALT-F4, clicking the
corner X etc)
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2
Thanks a lot Morten. But i don't understand a single line of code.
The thing is, i'm just a vb.net rookie. But thanks anyhow.

"Morten Wennevik" wrote:
Well, you could override the KeyDown/KeyPress and ignore those
combinations, or handle the OnClosing event and check for what kind of
closing is performed

protected override void OnClosing(Cance lEventArgs e)
{
System.Diagnost ics.StackTrace O = new System.Diagnost ics.StackTrace( true);
System.Diagnost ics.StackFrame F = O.GetFrame(7);
if(F.GetMethod( ).Name == "DefWndProc ")
e.Cancel = true; // user ended the application (ALT-F4, clicking the
corner X etc)
}
--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 21 '05 #3
The VB.NET code should be very similar. The StackTrace class is used for
debugging purposes as it contains a trace of methods called in your
application put into StackFrames, the 8th last StackFrame will reveal what
triggered the OnClosing event so we retrieve the StackFrame and compare
the Method Name with known values like "DefWndProc " = User ended the
application by means of ALT-F4 etc, "SendMessag e" = this/Me.Close() was
called from within your application, "DispatchMessag eW" = User ended the
application by means of the TaskManager (aborting process) etc.
On Tue, 15 Mar 2005 08:39:08 -0800, waisty vb.net rookie
<wa************ ***@discussions .microsoft.com> wrote:
Thanks a lot Morten. But i don't understand a single line of code.
The thing is, i'm just a vb.net rookie. But thanks anyhow.

"Morten Wennevik" wrote:
Well, you could override the KeyDown/KeyPress and ignore those
combinations, or handle the OnClosing event and check for what kind of
closing is performed

protected override void OnClosing(Cance lEventArgs e)
{
System.Diagnost ics.StackTrace O = new
System.Diagnost ics.StackTrace( true);
System.Diagnost ics.StackFrame F = O.GetFrame(7);
if(F.GetMethod( ).Name == "DefWndProc ")
e.Cancel = true; // user ended the application (ALT-F4, clicking the
corner X etc)
}
--
Happy Coding!
Morten Wennevik [C# MVP]


--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #4

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

Similar topics

1
1415
by: kishor kotecha | last post by:
Hi, I have created a .net app. all works fine. but, i want to prevent closure (kill) of this app when the user of the machine does a 'log off' of windows/xp. currently what is happening is that when the user does 'log off', the log
22
7581
by: alecjames1 | last post by:
I have a form which the user must complete before closing. I have disabled the window x button and use my own exit button. When selected it checks to see if the user has completed the entries otherwise it cancels the close. However, the user can still right click on the task bar and close my application. Is there any way of preventing this. Thanks Alex
7
7120
by: alan | last post by:
Hello, When the user try the close the application (click the top right side button "X"), I would like to do a checking first. If the checking return false, prevent the application terminate. Anyone know how to do it? Thanks.
4
410
by: Daniel Walzenbach | last post by:
Hi, does anybody know the JavaScript the guys at Microsoft used in MS CRM to prevent people from closing a browser window and asking them (on the client) what they really want to do? If you don't know what I'm talking about take a look at MS CRM. Open a form, make some changes and try to close the form without saving first. Instead of closing the form you will be asked if you'd like to save first or discard the changes. I have often...
9
2283
by: Daniel Walzenbach | last post by:
Hi I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx) as a popup using either window.open or window.showModalDialog. Since I want to warn the users of my application when they try to close page1.aspx and have changed the values in the meantime I thought about using the “onbeforeunload” event of the...
2
2333
by: Snuyt | last post by:
Hallo, when a form is closed by clicking the closing button (cross in the right upper corner of the form), it is also disposed. Can I prevent this, and instead of closing (and disposing) the form, just hide the form? (it is not the main form) thanks, Snuyt
2
3529
by: kevininstructor | last post by:
I want to prevent a user from closing an application while doing critical operations. The following code (concept came from MSDN) works except for when the user attempts to terminate via "Task List" which causes "Program not responding"...press "Cancel" and no issues, press "End now" and sure enough it ends. My question is; is there any method to prevent the "Application not responding" message from appearing? Current code:
4
3131
by: tlyczko | last post by:
I have been looking on the NGs and I found this code to show if a subform has no records. I have this code in the MAIN form OnClose event: Private Sub btnClose_Click() '4/16/06 new code that cancels the close event if the BeforeUpdate code fires '4/16/06 see...
3
13059
by: sravan_reddy001 | last post by:
i want to prevent a form from closing.. to do this i want to handle the formClosing or FormClosed events. from here i want to prevent the form from closing. New instance of same form should not be used. is there any way to do this? is it posiible to do the same thing with anycode?
7
5238
by: Michiel Rapati-Kekkonen | last post by:
Hi, I would like my record to be saved only when my own close button (with all it's checks) is used. I made the winodws close button disappear, but you still can close using the right mouse click. also when designing, going to design mode saves the record. So I tried: OnClose : Me.Undo. My own cancel button uses it and it works ok,
0
10040
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
9873
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
9846
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
9713
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
8713
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 projectplanning, coding, testing, and deploymentwithout 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...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
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
3806
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
2666
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.