Home All Groups Group Topic Archive Search About

Urgent: XP, Vista logoff application (WM_QUERYENDSESSION)

Author
29 Nov 2007 3:34 PM
Clemente
Hi,

We have a VB.Net application that is sleeping until it receives a
logoff/shutdown event. We want the application running on Vista and
XP.

When the application receives those events it has to show a message
box, so the user can answer Yes or No, and then let the logoff/
shutdown process continues.

We are doing this in VB.Net listening to WM_QUERYENDSESSION message.

We are having the following problems:

.. - It doesnt work in Vista.
  - In XP, when the application receives the WM_QUERYENDSESSION
message it shows the System End Task window for this application,
before showing the message box we want.

We are using this VB . Net 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
            'MessageBox.Show("queryendsession: this is a logoff,
shutdown, or reboot")
            systemShutdown = True
        End If
        ' If this is WM_QUERYENDSESSION, the closing event should be
raised in the base WndProc.
        MyBase.WndProc(m)
    End Sub 'WndProc
-------------------------
    Private Sub frmMsg_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If (systemShutdown) Then
            ' Reset the variable because the user might cancel the
shutdown.
            systemShutdown = False
            If (System.Windows.Forms.DialogResult.Yes =
MessageBox.Show("My application", "Abort logoff?",
MessageBoxButtons.YesNo)) Then
                e.Cancel = True
            Else
                e.Cancel = False
            End If
        End If
    End Sub
-----------------------

Why this behaviour? Any ideas?

TIA,

Clemente
Portugal

Author
29 Nov 2007 5:28 PM
Lloyd Sheen
Show quote Hide quote
"Clemente" <clemente.fil***@gmail.com> wrote in message
news:3f47b67e-88ba-4d67-9bd0-3f9885c0d3d3@x69g2000hsx.googlegroups.com...
> Hi,
>
> We have a VB.Net application that is sleeping until it receives a
> logoff/shutdown event. We want the application running on Vista and
> XP.
>
> When the application receives those events it has to show a message
> box, so the user can answer Yes or No, and then let the logoff/
> shutdown process continues.
>
> We are doing this in VB.Net listening to WM_QUERYENDSESSION message.
>
> We are having the following problems:
>
> . - It doesnt work in Vista.
>  - In XP, when the application receives the WM_QUERYENDSESSION
> message it shows the System End Task window for this application,
> before showing the message box we want.
>
> We are using this VB . Net 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
>            'MessageBox.Show("queryendsession: this is a logoff,
> shutdown, or reboot")
>            systemShutdown = True
>        End If
>        ' If this is WM_QUERYENDSESSION, the closing event should be
> raised in the base WndProc.
>        MyBase.WndProc(m)
>    End Sub 'WndProc
> -------------------------
>    Private Sub frmMsg_FormClosing(ByVal sender As Object, ByVal e As
> System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
>        If (systemShutdown) Then
>            ' Reset the variable because the user might cancel the
> shutdown.
>            systemShutdown = False
>            If (System.Windows.Forms.DialogResult.Yes =
> MessageBox.Show("My application", "Abort logoff?",
> MessageBoxButtons.YesNo)) Then
>                e.Cancel = True
>            Else
>                e.Cancel = False
>            End If
>        End If
>    End Sub
> -----------------------
>
> Why this behaviour? Any ideas?
>
> TIA,
>
> Clemente
> Portugal

Not sure why you need to monitor the WndProc.  In the FormClosingEventArgs
there is an indication as to why the form is being closed.  Check it and if
it is system shutdown then show the message and cancel if the user wants.

Hope this helps
Lloyd Sheen