Urgent: XP, Vista logoff application (WM_QUERYENDSESSION)

C

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
 
L

Lloyd Sheen

Clemente said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top