|
-
Aug 1st, 2007, 10:32 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Listen for Windows Shutdown and close app problem
I have an application that sits in the task tray and when the user issues a shutdown request I intercept using the following code:
I am not going to include all the DLLImport code to shorten post a little.
Code:
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if ((m.Msg == 0x11) || (m.Msg == 0x0016) || (m.Msg == 0xA123)) // WM_QUERYENDSESSION Or WM_ENDSESSION Or RF_UNLOADMSG
{
// Check for Windows shutdown event
_WindowsShutdownRequested = true;
Application.Exit();
}
else
base.WndProc(ref m);
}
Then in my _FormClosing event I have the following code:
Code:
private void FormSettings_FormClosing(object sender, FormClosingEventArgs e)
{
// Check for Windows shutdown event
if (!_WindowsShutdownRequested)
{
// Code to minimize to tray goes here...
}
}
This all seems to work fine, but even though my app closes and is removed from the task tray, Windows doesn't continue to shutdown. I have to click sutdown again.
Do theses messages only listen for the shutdown event and abort it or am I doing something wrong in my code?
Thanks in advance,
CT
-
Aug 2nd, 2007, 01:08 AM
#2
Re: Listen for Windows Shutdown and close app problem
You don't need that WndProc stuff. The FormClosing event tells you why the form is closing. This code is VB.NET but you should get the idea.
-
Aug 2nd, 2007, 06:36 AM
#3
Thread Starter
Addicted Member
Re: Listen for Windows Shutdown and close app problem
 Originally Posted by jmcilhinney
You don't need that WndProc stuff. The FormClosing event tells you why the form is closing. This code is VB.NET but you should get the idea.
Man, I feel silly. I never even found that in any on my google searches and never even saw it as part of event (e).
I finnaly did get the WndProc working, but I think I will give the method you provided since it is much cleaner.
jmcilhinney, I wish I could give you more rep, since you never seem to fail in finding solutions, but you seem to be the only one ever responding.
Thanks again,
CT
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|