Originariamente inviato da alka
Vi ricordo che, nello spirito del forum, qualsiasi soluzione al problema dovrebbe essere resa pubblica in questa discussione e non scambiata in privato.
Ciao!
già, hai ragione.
per la soluzione che posterò non dovrete ringraziare me, ma cassano *clap*clap*clap*
codice:
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 fired in the base WndProc
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (systemShutdown) Then
' reset the variable since they may cancel the shutdown
systemShutdown = False
If (DialogResult.Yes = _
MessageBox.Show("My application", "Would you care to save your work before logging off?", MessageBoxButtons.YesNo)) Then
e.Cancel = True
Else
e.Cancel = False
End If
End If
End Sub