Hi,
how I can intercept from my application when Windows shutdown or logoff ?
And if it's possible, Windows can wait that my application makes various operations before it shutdown/logoff ?
TIA
How intercept shutdown or logoff ?
-
- New User
- Posts: 5
- Joined: Fri Aug 06, 2004 2:55 pm
In order to do that, you must inspect the messages Windows send to your app. It may be done by using SetWindowCallback() function:
But I can't tell how many time the system will wait until forcing your app to close. May be (I'm not sure
) that Windows will query your app from time to time sending a message $11 to see if it is all right to shutdown the system. In that case, I think you should return 0 (zero) to the caller (instead of the default Result) until your app is done with the cean-up. As I said, I'm not sure about that.
Well, at least it is a good start point, I think
Code: Select all
Declare.l MyWindowCallback(WindowID, Message, wParam, lParam)
OpenWindow(0,0,0,320,200,#PB_Window_SystemMenu, "Test Window")
SetWindowCallback(@MyWindowCallback())
Procedure.l MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If Message = $16 ; End Session Message
If wParam
; the section is ending
If lParam
;user is logging off
MessageRequester("X", "User is is logging off.")
Else
;user is shutting down the system.
MessageRequester("X", "User is shutting down the system.")
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Repeat
If WaitWindowEvent() = #PB_Event_CloseWindow: Break: EndIf
ForEver

Well, at least it is a good start point, I think

Derlidio Siqueira
There are two messages: #WM_QUERYENDSESSION and #WM_ENDSESSION
You receive #WM_QUERYENDSESSION first, there you can choose wether
you want windows to actually shut down or not, by returning 0, you tell
Windows, that your program is not ready to be shut down, and by returning 1,
you indicate that your program can be shut down now.
After that, you receive the #WM_ENDSESSION, which tells you that your
program will now be terminated. After you return from the callback procedure
when you get this message, windows will terminate your app.
See here:
http://msdn.microsoft.com/library/defau ... ession.asp
Timo
You receive #WM_QUERYENDSESSION first, there you can choose wether
you want windows to actually shut down or not, by returning 0, you tell
Windows, that your program is not ready to be shut down, and by returning 1,
you indicate that your program can be shut down now.
After that, you receive the #WM_ENDSESSION, which tells you that your
program will now be terminated. After you return from the callback procedure
when you get this message, windows will terminate your app.
See here:
http://msdn.microsoft.com/library/defau ... ession.asp
Timo
quidquid Latine dictum sit altum videtur
Re: How intercept shutdown or logoff ?
Hi,
I stumbled over this thread and found the MSDN link above is dead
so I searched for the actual one : http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx
~ Vera
I stumbled over this thread and found the MSDN link above is dead
so I searched for the actual one : http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx
~ Vera
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
Re:
> You receive #WM_QUERYENDSESSION first, there you can choose wether
> you want windows to actually shut down or not, by returning 0, you tell
> Windows, that your program is not ready to be shut down, and by returning 1
Yep, but remember this is not 100% reliable, as Windows will disobey it if it wants. Happened to me the other day. So if your app is expecting to halt Windows in its tracks, you'll be kidding yourself. (Not you personally, Freak). Just something to be aware of. In other words, if you detect that Windows is shutting down, you'd best just do all your shutdown stuff FAST instead of trying to stop Windows...
> you want windows to actually shut down or not, by returning 0, you tell
> Windows, that your program is not ready to be shut down, and by returning 1
Yep, but remember this is not 100% reliable, as Windows will disobey it if it wants. Happened to me the other day. So if your app is expecting to halt Windows in its tracks, you'll be kidding yourself. (Not you personally, Freak). Just something to be aware of. In other words, if you detect that Windows is shutting down, you'd best just do all your shutdown stuff FAST instead of trying to stop Windows...
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.