Is there any way to determing why a form is closing? As in if the user
cliced the x button or if a system shutdown has started.
thanks for any help
Mickey Swanson 8 2148
what do you mean, are you trying to avoid form closing or what?
"Mickey Swanson" <sw*****@dixi e-net.com> wrote in message
news:uN******** ******@TK2MSFTN GP09.phx.gbl... Is there any way to determing why a form is closing? As in if the user cliced the x button or if a system shutdown has started.
thanks for any help Mickey Swanson
if a user clicks the x button I need to hide and minimize the form but I
can't just place this in the form.closing event because it will prevent
windows from shutting down. So I need to find out what is closing the form,
either a user or the operating system.
does that help describe what i'm looking for?
Mick
"pei_world" <pe*******@hotm ail.com> wrote in message
news:uc******** ********@TK2MSF TNGP12.phx.gbl. .. what do you mean, are you trying to avoid form closing or what?
"Mickey Swanson" <sw*****@dixi e-net.com> wrote in message news:uN******** ******@TK2MSFTN GP09.phx.gbl... Is there any way to determing why a form is closing? As in if the user cliced the x button or if a system shutdown has started.
thanks for any help Mickey Swanson
Hi Mickey,
No unforutnately not at least just using code in the Closing() event
handler. However, you can use WndProc to check for the system shutdown then
set a flag that the system is trying to shut down the app.
Something like this:
protected override void WndProc(ref Message m)
{
if (this.bNotifyIc on)
{
const int WM_QUERYENDSESS ION = 0x011;
if (m.Msg == WM_QUERYENDSESS ION)
this.bWindowsSh uttingDown = true;
}
base.WndProc(re f m);
}
In this case I use to trap the ShutDown event when the app is running in
NotifyIcon mode because usually when you shut down the form in that mode you
don't want to shut it down but minimize to the tray. The shut down message
however should need to be handled.
+++ Rick ---
--
Rick Strahl
West Wind Technologies http://www.west-wind.com/ http://www.west-wind.com/webblog/
----------------------------------
Making waves on the Web
"Mickey Swanson" <sw*****@dixi e-net.com> wrote in message
news:uN******** ******@TK2MSFTN GP09.phx.gbl... Is there any way to determing why a form is closing? As in if the user cliced the x button or if a system shutdown has started.
thanks for any help Mickey Swanson
I've never used the WndProc. do you know where I can look at a more indepth
code sample.
Mick
"Rick Strahl [MVP]" <ri********@hot mail.com> wrote in message
news:eG******** ********@tk2msf tngp13.phx.gbl. .. Hi Mickey,
No unforutnately not at least just using code in the Closing() event handler. However, you can use WndProc to check for the system shutdown
then set a flag that the system is trying to shut down the app.
Something like this:
protected override void WndProc(ref Message m) { if (this.bNotifyIc on) { const int WM_QUERYENDSESS ION = 0x011; if (m.Msg == WM_QUERYENDSESS ION) this.bWindowsSh uttingDown = true; } base.WndProc(re f m); }
In this case I use to trap the ShutDown event when the app is running in NotifyIcon mode because usually when you shut down the form in that mode
you don't want to shut it down but minimize to the tray. The shut down message however should need to be handled.
+++ Rick ---
--
Rick Strahl West Wind Technologies http://www.west-wind.com/ http://www.west-wind.com/webblog/ ---------------------------------- Making waves on the Web
"Mickey Swanson" <sw*****@dixi e-net.com> wrote in message news:uN******** ******@TK2MSFTN GP09.phx.gbl... Is there any way to determing why a form is closing? As in if the user cliced the x button or if a system shutdown has started.
thanks for any help Mickey Swanson
I think I understand. This is what I came up with.
protected override void WndProc(ref Message m)
{
const int WM_QUERYENDSESS ION = 0x011;
switch(m.Msg)
{
case WM_QUERYENDSESS ION:
this.bWindowsSh uttingDown = true;
break;
}
base.WndProc(re f m);
}
private void frmMDI_Closing( object sender,
System.Componen tModel.CancelEv entArgs e)
{
if(this.bWindow sShuttingDown)
{
Application.Exi t();
}
else
{
e.Cancel = true;
this.Hide();
this.WindowStat e = System.Windows. Forms.FormWindo wState.Minimize d;
}
}
"Rick Strahl [MVP]" <ri********@hot mail.com> wrote in message
news:eG******** ********@tk2msf tngp13.phx.gbl. .. Hi Mickey,
No unforutnately not at least just using code in the Closing() event handler. However, you can use WndProc to check for the system shutdown
then set a flag that the system is trying to shut down the app.
Something like this:
protected override void WndProc(ref Message m) { if (this.bNotifyIc on) { const int WM_QUERYENDSESS ION = 0x011; if (m.Msg == WM_QUERYENDSESS ION) this.bWindowsSh uttingDown = true; } base.WndProc(re f m); }
In this case I use to trap the ShutDown event when the app is running in NotifyIcon mode because usually when you shut down the form in that mode
you don't want to shut it down but minimize to the tray. The shut down message however should need to be handled.
+++ Rick ---
--
Rick Strahl West Wind Technologies http://www.west-wind.com/ http://www.west-wind.com/webblog/ ---------------------------------- Making waves on the Web
"Mickey Swanson" <sw*****@dixi e-net.com> wrote in message news:uN******** ******@TK2MSFTN GP09.phx.gbl... Is there any way to determing why a form is closing? As in if the user cliced the x button or if a system shutdown has started.
thanks for any help Mickey Swanson
Hi Mickey,
Yes, I think your code is correct. But I want to add more information to
you :) (For your original question about few information about WndProc)
WndProc encapsulated the win32 windows procedure. So you can override it
and handle certain message to do more indepth things.(When normal .Net
event does not meet your need)
To find the value of these message constant, you can look it up in the API
viewer followed with VB6.0.
To understand the message mechanism of windows application, I think the
best resource is some win32 SDK programming book. Such as "Programmin g
Windows" by Charles Petzold.
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Thanks, that helps alot.
I needed the tip on where to look up the constant values.
I also sent this to you directly by mistake. MS shouldn't put the Reply and
Reply Group button so close together. :-)
thanks,
Mick
""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:s9******** ******@cpmsftng xa07.phx.gbl... Hi Mickey,
Yes, I think your code is correct. But I want to add more information to you :) (For your original question about few information about WndProc) WndProc encapsulated the win32 windows procedure. So you can override it and handle certain message to do more indepth things.(When normal .Net event does not meet your need) To find the value of these message constant, you can look it up in the API viewer followed with VB6.0. To understand the message mechanism of windows application, I think the best resource is some win32 SDK programming book. Such as "Programmin g Windows" by Charles Petzold.
Hope this helps,
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Hi Mickey,
Thanks for your feedback.
I am glad my reply makes sense to you.
Beside the API viewer, there are some windows const that was not normal
used. They are defined in the *.h files in the C:\Program Files\Microsoft
Visual Studio\VC98\Inc lude\ directory. So you can use the Edit|Find and
Replace|Find in Files menu in VS.net IDE.
Merry Christmas!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ThunderMusic |
last post by:
Hi,
I'm trying to have a MSN Messenger like form/app closing behavior. When I
click on the X button, I only want the form to disappear and when I
double-click on the notify icon or right-click on it and choose Open from
the context menu, I want the form to reappear. For that, I got the point
covered. Even when the form is minimize, the behavior is like MSN Messenger.
But one problem arose. When I close the form (the first time), it...
|
by: RAJ |
last post by:
hi
plz tell me how to know "how window is going to close"...
i have to right code for X button of forms...
plz telll me
thanks
bye
|
by: Chris Bruce |
last post by:
In my application I need a way to distiguish between the following events:
1. When a user closes an MDI child window.
2. When the user closes the MDI parent window which subsequently closes
the MDI child window.
My application does certain logic when the user actually closes the MDI
child form by clicking the "X" in the upper right hand. My application,
however, should not execute this logic if the user closes the MDI parent. I...
|
by: Nenad Dobrilovic |
last post by:
Hi,
is there any way to find out how form was closed (by calling it's method
Close() or by clicking on the 'close' button in control box)?
Also, can I close the form in that way that Cloing/Closed events are not
triggered?
|
by: Gary Miller |
last post by:
Does anyone know how to detect a modeless form on closing by the form that
invoked the modeless form?
form.Show();
| |
by: **Developer** |
last post by:
When I get a closing event in a MID Child form I don't know if the child
form is closing or the main form is closing.
Is there a way to tell?
Thank
|
by: **Developer** |
last post by:
I've been looking but can't find out how in a form Closing event to know if
the closing is because the form's "X" had been clicked or the main form's
"X" was clicked.
That is, I need to know if just the form is closing or the application is
closing.
Do you know how to tell?
|
by: Zytan |
last post by:
I have created a new form from the main form. When I close the main
form with the 'x' close button, its Form.FormClosed event is run, but
not the dialog's.
Is this normal? It is ok / dangerous? How can I force shutdown code
within the dialog's Form.FormClosed event run?
Zytan
|
by: zacks |
last post by:
I have a .NET 2.0 MDI application where the child form has a Tab
Control. Each of the Tab in the Tab Control has a Validating event to
handle what it should do when the user changes tabs.
But these Validating Events are also fired when either the child form
or the main (parent) form Close icon is clicked. And I need for these
events to know if they are being invoked because the app (or child
window) is being closed. I have set a boolean...
|
by: rbrowning1958 |
last post by:
Hello,
I am confused by dispose etc. and hope someone can set me right.
1. The Dispose(Bool) the IDE generates for a form has nothing to do
with IDisposable, right?
2. So when is this called? When a form is closed? If this is caused
automatically when a form is closed how can I then access things on a
modal from after ShowDialog() returns? Or is it only for modeless
forms?
|
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...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |