Results 1 to 4 of 4

Thread: Form... QueryUnload, UnLoadMode .NET equiv? [RESOLVED]

  1. #1

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60

    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.

  2. #2

  3. #3

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Thanks, just what I was looking for!

  4. #4

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    In fact, finally came up with a better, simpler and more effective solution...

    Adding the code...
    VB Code:
    1. Private Shared WM_QUERYENDSESSION As Integer = &H11
    2.     Private Shared systemShutdown As Boolean = False
    3.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    4.         If m.Msg = WM_QUERYENDSESSION Then
    5.             'MsgBox("queryendsession: this is a logoff, shutdown, or reboot")
    6.             systemShutdown = True
    7.         End If
    8.         ' If this is WM_QUERYENDSESSION, the closing event should be fired in the base WndProc
    9.         MyBase.WndProc(m)
    10.     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:
    1. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         If Not systemShutdown Then 'cancel shutdown unless system is shutting down...
    3.             e.Cancel = True
    4.         End If
    5.     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
  •  



Click Here to Expand Forum to Full Width