|
-
Jan 17th, 2002, 01:15 AM
#1
Thread Starter
Hyperactive Member
System Shutdown
My application needs to know when the system is shutting down. Is there any API or an alternative way to determine if the user has initiated System Shutdown?
-
Jan 17th, 2002, 07:27 AM
#2
Frenzied Member
Use the UnloadMode parameter of the QueryUnload event:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbAppWindows Then
'user is exiting windows...
End If
End Sub
HTH,
Duncan
-
Jan 17th, 2002, 07:33 AM
#3
For future reference, here are all of the unloadmodes that you could use
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'there are 5 unloadmode levels
Select Case UnloadMode
Case vbFormControlMenu 'UnloadMode 0
'form is being unloaded via the Close
'command from the System menu
Case vbFormCode 'UnloadMode 1
'Unload Me has been issued from code
Case vbAppWindows 'UnloadMode 2
'Windows itself is closing
Case vbAppTaskManager 'UnloadMode 3
'the Task Manager is closing the app
Case vbFormMDIForm 'UnloadMod 4
'an MDI child form is closing because
'its parent form is closing
End Select
End Sub
-
Jan 17th, 2002, 10:23 PM
#4
QueryUnload DOES NOT WORK FOR WIN2k
I have not been able to get QueryUnload or Unload to work in Win2k when the User presses the Power Button on a ATX Power Supply.
Does ANYONE know the API routine to capture windows messages and detect when the operating system is shutting down?
My program losses data because I can't detect when it is shutting down.
Now if the user goes to Start > Shutdown > Shutdown then there is no problem.
Anyone with Win2k and ATX Power you will notice when you press the Power Button the computer shutdowns like three times fasters then going through the start button.
Megatron could you maybe help? I have posted this question on Microsoft Public VB WinAPI Newsgroup and no one has the answer.
Eagerly awaiting reply.
-
Jan 17th, 2002, 11:51 PM
#5
Thread Starter
Hyperactive Member
Thanx guys this would be of a great help for now...I wonder how I just missed that....
The problem that ALFware is having is part of my problem too since i`m actually using Win2k proffessional so a little help on that too might be useful to my little program....
Last edited by vbud; Jan 18th, 2002 at 01:17 AM.
-
May 6th, 2002, 06:15 PM
#6
Any luck?
I am glad that someone else has run into this issue
I have posted it so many times at the Microsoft newsgroups but none of them have come back with anything useful.
Any Gurus out there that know the solution?
Thanks
-
May 6th, 2002, 06:36 PM
#7
Subclass your window and catch the WM_QUERYENDSESSION message. This message is sent to all windows when windows is about to end the session.
-
May 6th, 2002, 06:39 PM
#8
Megatron: Does WM_QUERYENDSESSION apply to all OS, across the board? (Even XP)?
-
May 6th, 2002, 06:45 PM
#9
All except for Windows CE.
-
May 6th, 2002, 08:11 PM
#10
I'm sure I did that...
Also isn't the Form_QueryUnload() just a wrap for that anyway?
Megatron is it possible for you to post the Subclassing example for this exact situation? I have used subclassing before and it worked on Win98 and WinXP but for some reason in Win2k when you press the ATX Power button it didn't send the message.
Megatron if you have a newish computer and running windows 2k make a program to capture this message and get it to log to a text file when the computer shuts down. Then run it and use the power button to shut down the computer. You should find that windows does it's normal saving settings... and closing stuff then shuts off. However I notice that using the power button to shutdown takes about 50% less time that the Start > Shutdown method?
Is there any difference? wouldn't the power button just be a "shortcut" for shutdown?
If you could post a working sample I would love to double check my original findings.
Thanks Megatron
-
May 7th, 2002, 03:27 PM
#11
Also isn't the Form_QueryUnload() just a wrap for that anyway?
Yes, but WM_QUERYENDSESSION allows you to distinguish between a shutdown and a log-off.
However I notice that using the power button to shutdown takes about 50% less time that the Start > Shutdown method?
I'm not sure, but I think it's because when you press power-off (instead of shutdown), windows will only do the minimum requirements.
-
May 8th, 2002, 02:11 AM
#12
How about an example?
Would it be possible to send me a working example project that subclasses the form and does something when the query comes through.
Thanks megatron
-
May 8th, 2002, 02:34 PM
#13
This should work
Add to a module
VB Code:
Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public WinProcOld As Long
Private Const ENDSESSION_LOGOFF = &H80000000
Private Const WM_QUERYENDSESSION = &H11
Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_QUERYENDSESSION Then
If wParam = ENDSESSION_LOGOFF Then
Debug.Print "logging off"
Else
Debug.Print "Shutting down"
End If
WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WinProcOld&
WinProcOld& = 0
End Sub
Add to a form
VB Code:
Private Sub Form_Load()
SubClassWnd hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub
-
May 8th, 2002, 11:34 PM
#14
Will give it a go...
Also megatron how can I get a copy of that VBFE Library, sounds interesting and rather useful but can't seem to find a link to download it.
-
May 9th, 2002, 03:27 PM
#15
The VBFE library was cancelled a couple years ago (I didn't have the time to finish it).
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
|