|
-
Jan 20th, 2004, 04:23 AM
#1
Thread Starter
Member
Form... QueryUnload, UnLoadMode .NET equiv? [RESOLVED]
I have a program in which in most cases I want it stay open - thus it intercepts the close command and minimizes instead.
In VB6 the QueryUnload events UnLoadMode would allow me to distinguish between an application shutdown and Windows being shutdown.
I am using the Closing event in VB.NET as QueryUnload no longer exists to intercept app close commands but this no longer has a UnLoadMode so how to I work out it it’s Task Manger, Windows and so on closing and not my application?
Currently my program will not allow Windows to shutdown!!!
Any help appreciated, Thanks.
Last edited by McBain2; Jan 22nd, 2004 at 07:58 AM.
-
Jan 20th, 2004, 10:59 AM
#2
-
Jan 20th, 2004, 11:59 AM
#3
Thread Starter
Member
Thanks, just what I was looking for!
-
Jan 22nd, 2004, 07:57 AM
#4
Thread Starter
Member
In fact, finally came up with a better, simpler and more effective solution...
Adding the code...
VB Code:
Private Shared WM_QUERYENDSESSION As Integer = &H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
'MsgBox("queryendsession: this is a logoff, shutdown, or reboot")
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be fired in the base WndProc
MyBase.WndProc(m)
End Sub 'WndProc
...to the form that handles the intercept of the closedown - cancelling and minimizing to a system tray icon instead.
Then you can use the systemShutdown boolean to determine if you should really shutdown in the Closing event, e.g.
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not systemShutdown Then 'cancel shutdown unless system is shutting down...
e.Cancel = True
End If
End Sub
Works a treat!
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
|