I'm trying to create an utility that impede users to shutdown the machine and instead do some maintenance tasks and when completed, programmatically shutdown the PC.
The problem I'm facing is the following:
I'm successfully 'trapping' the session end/shutdown when it is issued from the start menu, but when I push the power button instead, it works fine the first time (the event is trapped by the application) but if you push the power button for a second time, the event is not trapped and the system shutdown with no warning about 30/40 seconds later.
EDIT: I'm testing in another WIn7 machine now (and the event is trapped by the app 30/40 seconds later but no shutdown occurs).
Any ideas?
Tested on 32 bits Windows 7 Pro and Starter. Current HMG version.
This is the code:
Code: Select all
#include "hmg.ch"
#define WM_QUERYENDSESSION 0x0011
Function Main
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 500 HEIGHT 300 ;
TITLE 'On Shutdown Test' ;
MAIN
END WINDOW
CREATE EVENT PROCNAME OnCloseSession() HWND Form_1.HANDLE STOREINDEX nIndex
EventProcessAllHookMessage ( nIndex, .T. )
Form_1.Center
Form_1.Activate
Return Nil
Function OnCloseSession()
IF EventMSG() == WM_QUERYENDSESSION
CallDll32 ( "CancelShutdown" , "User32.dll" )
MSGINFO("Do My Thing Here!!!")
return 0
ENDIF
Return nil