473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

form.closing

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
Nov 15 '05 #1
8 2129
what do you mean, are you trying to avoid form closing or what?
"Mickey Swanson" <sw*****@dixie-net.com> wrote in message
news:uN**************@TK2MSFTNGP09.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

Nov 15 '05 #2
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*******@hotmail.com> wrote in message
news:uc****************@TK2MSFTNGP12.phx.gbl...
what do you mean, are you trying to avoid form closing or what?
"Mickey Swanson" <sw*****@dixie-net.com> wrote in message
news:uN**************@TK2MSFTNGP09.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


Nov 15 '05 #3
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.bNotifyIcon)
{
const int WM_QUERYENDSESSION = 0x011;
if (m.Msg == WM_QUERYENDSESSION)
this.bWindowsShuttingDown = true;
}
base.WndProc(ref 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*****@dixie-net.com> wrote in message
news:uN**************@TK2MSFTNGP09.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

Nov 15 '05 #4
I've never used the WndProc. do you know where I can look at a more indepth
code sample.
Mick

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:eG****************@tk2msftngp13.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.bNotifyIcon)
{
const int WM_QUERYENDSESSION = 0x011;
if (m.Msg == WM_QUERYENDSESSION)
this.bWindowsShuttingDown = true;
}
base.WndProc(ref 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*****@dixie-net.com> wrote in message
news:uN**************@TK2MSFTNGP09.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


Nov 15 '05 #5
I think I understand. This is what I came up with.

protected override void WndProc(ref Message m)
{
const int WM_QUERYENDSESSION = 0x011;
switch(m.Msg)
{
case WM_QUERYENDSESSION:
this.bWindowsShuttingDown = true;
break;
}
base.WndProc(ref m);
}

private void frmMDI_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if(this.bWindowsShuttingDown)
{
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
}
}
"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:eG****************@tk2msftngp13.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.bNotifyIcon)
{
const int WM_QUERYENDSESSION = 0x011;
if (m.Msg == WM_QUERYENDSESSION)
this.bWindowsShuttingDown = true;
}
base.WndProc(ref 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*****@dixie-net.com> wrote in message
news:uN**************@TK2MSFTNGP09.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


Nov 15 '05 #6

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 "Programming
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.

Nov 15 '05 #7
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.microsoft.com> wrote in message
news:s9**************@cpmsftngxa07.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 "Programming
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.

Nov 15 '05 #8

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\Include\ 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.

Nov 15 '05 #9

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

Similar topics

3
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...
5
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
1
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...
2
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...
6
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();
1
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
6
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...
11
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 /...
19
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...
19
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?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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
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
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
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...

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.