Page 1 of 1
Help: How can I detect system power shutdown, logoff, etc.
Posted: Mon Nov 08, 2010 9:18 am
by dhaine_adp
Hello all,
Has anyone got a code to detect logoff, shutdown, restart, hibernate, sleep and suspend in windows?
If I have an application that logs the time or duration (start time and end time) and if windows suddenly restarted, logoff by user without closing the application. So at least if the shutdown, logoff event is detected I can update the "End Time and End Date" and then close the app. I believed I cannot prevent the shutdown and I don't to intefere with it. What I wanted is simply update and closed the Apps.
Is this possible with HMG? Any help and advise is welcome..
Regards,
Danny
Re: Help: How can I detect system power shutdown, logoff, et
Posted: Mon Nov 08, 2010 10:06 am
by gfilatov
dhaine_adp wrote:Hello all,
Has anyone got a code to detect logoff, shutdown, restart, hibernate, sleep and suspend in windows?
If I have an application that logs the time or duration (start time and end time) and if windows suddenly restarted, logoff by user without closing the application. So at least if the shutdown, logoff event is detected I can update the "End Time and End Date" and then close the app. I believed I cannot prevent the shutdown and I don't to intefere with it. What I wanted is simply update and closed the Apps.
Is this possible with HMG? Any help and advise is welcome..
Hello Danny,
Yes, it is possible with HMG. You should trap the Windows messages
WM_QUERYENDSESSION and
WM_ENDSESSION in your local function Events(). Please be so kind to revise a working skeleton of program for Minigui Extended and try to adapt this code for HMG.
Code: Select all
#include "minigui.ch"
#define APP_TITLE "Hello World!"
/*
*/
Function Main
SET EVENTS FUNCTION TO MYEVENTS
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE APP_TITLE ;
MAIN
END WINDOW
CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
Return
#define WM_QUERYENDSESSION 0x0011
#define WM_ENDSESSION 0x0016
*------------------------------------------------------------------------------*
function MyEvents ( hWnd, nMsg, wParam, lParam )
*------------------------------------------------------------------------------*
do case
case nMsg == WM_QUERYENDSESSION
MSGINFO("OK", "QUERY")
Return 1 // try 0 to block the exit
case nMsg == WM_ENDSESSION
MSGINFO("OK", "END")
Return 1
otherwise
Events ( hWnd, nMsg, wParam, lParam )
endcase
Return (0)
Hope that give you an idea

Re: Help: How can I detect system power shutdown, logoff, et
Posted: Wed Nov 10, 2010 4:50 am
by dhaine_adp
Hi Grigory,
Thank you very much for posting. I will try your code.
Regards,
Danny