472,119 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Windows won't shut down

Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}
Nov 16 '05 #1
4 5709
Claire,

I don't think that is the case. When windows is shutting down, if your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in
the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button
mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases
and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}

Nov 16 '05 #2
Hi Nicholas:

I have a similar issue that Claire has. But I have no idea how to implement
WndProc.

Can you show me how to implement WndProc ?

Thanks

David Kao

"Nicholas Paldino [.NET/C# MVP]" wrote:
Claire,

I don't think that is the case. When windows is shutting down, if your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Running XP pro, SP2. Visual studio .NET 2003. App written in C#

I have written an application that hides itself when run and shows a
notification icon in the system tray.
If the main form is visible/restored to the desktop, and I tell windows to
restart, windows shuts down fine.
If the main form is minimized to the tray and I tell windows to restart,
other desktop apps close down fine but my program's icon remains sat in
the
system tray, windows doesn't close down and there's no error messages.
In normal use, I only allow the app to close down from a right button
mouse
activated menu when the app sits in the task bar.

The code for the Closing event is as follows. The menu "close application"
click changes the DialogResult from None to Cancel.
I tested and found that the Closing event is being called in both cases
and
,afaik, the result should be ignored anyway as Windows OS is being closed
down.
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if (DialogResult == DialogResult.None)

{

e.Cancel = true;

WindowState = FormWindowState.Minimized;

}
}


Nov 16 '05 #3
David,

It's just an override on your main form:

protected override void WndProc(ref Message m)
{
// Perform pre-processing here.

// Call the base.
base.WndProc(ref m);

// Post-processing here.
}

What you do for the pre or post processing is up to you.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:DF**********************************@microsof t.com...
Hi Nicholas:

I have a similar issue that Claire has. But I have no idea how to
implement
WndProc.

Can you show me how to implement WndProc ?

Thanks

David Kao

"Nicholas Paldino [.NET/C# MVP]" wrote:
Claire,

I don't think that is the case. When windows is shutting down, if
your
app cancels the request to shut down, then it will halt the shutdown.

I think that you should override the WndProc method of your form, and
then handle the WM_QUERYENDSESSION and WM_ENDSESSION messages yourself,
indicating that it is ok to shut down when you get them. I think that
the
cancel request from your Closing event handler is being channeled back in
response to these messages.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Running XP pro, SP2. Visual studio .NET 2003. App written in C#
>
> I have written an application that hides itself when run and shows a
> notification icon in the system tray.
> If the main form is visible/restored to the desktop, and I tell windows
> to
> restart, windows shuts down fine.
> If the main form is minimized to the tray and I tell windows to
> restart,
> other desktop apps close down fine but my program's icon remains sat in
> the
> system tray, windows doesn't close down and there's no error messages.
> In normal use, I only allow the app to close down from a right button
> mouse
> activated menu when the app sits in the task bar.
>
> The code for the Closing event is as follows. The menu "close
> application"
> click changes the DialogResult from None to Cancel.
> I tested and found that the Closing event is being called in both cases
> and
> ,afaik, the result should be ignored anyway as Windows OS is being
> closed
> down.
> private void frmOptions_Closing(object sender,
> System.ComponentModel.CancelEventArgs e)
>
> {
>
> if (DialogResult == DialogResult.None)
>
> {
>
> e.Cancel = true;
>
> WindowState = FormWindowState.Minimized;
>
> }
>
>
> }
>


Nov 16 '05 #4
Thanks Nicholas,
I don't believe my app is receiving this message.
It's very difficult to track down as you can't run the app in the debugger
at that level of shutdown.
I stuck a message box in wndproc to show on either message and it didn't
fire.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Myo Zaw | last post: by
2 posts views Thread by =?Utf-8?B?R2xlbm4=?= | last post: by

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.