1. How detect that Windows is shutting down?
- Posted by sergelli Aug 04, 2012
- 1653 views
Hello
How can my program can detect that Windows is shutting down and have time to perform tasks, before turning off?
This is possible with Euphoria?
Thanks in advance.
2. Re: How detect that Windows is shutting down?
- Posted by ghaberek (admin) Aug 04, 2012
- 1684 views
Hello
How can my program can detect that Windows is shutting down and have time to perform tasks, before turning off?
This is possible with Euphoria?
Thanks in advance.
If you are writing a Win32Lib application, you can use w32HEvent to catch the WM_QUERYENDSESSION event. If you want to cancel the shutdown, you can call returnValue(w32False), but as Microsoft states in their documentation, "it is good practice to respect the user's actions."
constant WM_QUERYENDSESSION = #0011 constant -- possible values for lParam ENDSESSION_CLOSEAPP = #00000001, ENDSESSION_CRITICAL = #40000000, ENDSESSION_LOGOFF = #80000000 procedure Main_onEvent( integer pSelf, integer pEvent, sequence pParams ) atom uMsg = pParams[1] -- atom wParam = pParams[2] -- (unused) atom lParam = pParams[3] if uMsg = WM_QUERYENDSESSION then switch lParam do case ENDSESSION_CLOSEAPP then -- The application is using a file that must be replaced, the -- system is being serviced, or system resources are exhausted. case ENDSESSION_CRITICAL then -- The application is forced to shut down. case ENDSESSION_LOGOFF then -- The user is logging off. end switch end if end procedure setHandler( Main, w32HEvent, routine_id("Main_onEvent") )
-Greg
3. Re: How detect that Windows is shutting down?
- Posted by sergelli Aug 04, 2012
- 1605 views
Thanks Greg
I really liked this solution.
But to complete, how do I continue the shutdown, then that my program solve their tasks?
To continue the shutdown, just do not use the "returnValue(w32False)" ? This is correct?
4. Re: How detect that Windows is shutting down?
- Posted by petelomax Aug 08, 2012
- 1501 views
But to complete, how do I continue the shutdown, then that my program solve their tasks?
I vaguely remember dealing with this for Edita quite a few years ago. The relevant code (arwen not win32lib) I ended up with is:
elsif(msg = WM_ENDSESSION and wParam) or msg = WM_CLOSE then return saveAllFilesAndINI() elsif msg = WM_QUERYENDSESSION then if saveAllFilesAndINI() then return {0} end if end if
So it is not a question of "do you have enough time?", just do whatever you need to before returning.
HTH, Pete