Re: How detect that Windows is shutting down?
- Posted by ghaberek (admin) Aug 04, 2012
- 1689 views
sergelli said...
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