Help: How can I detect system power shutdown, logoff, etc.

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Help: How can I detect system power shutdown, logoff, etc.

Post 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
Regards,

Danny
Manila, Philippines
User avatar
gfilatov
Posts: 1116
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Help: How can I detect system power shutdown, logoff, et

Post 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 :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Help: How can I detect system power shutdown, logoff, et

Post by dhaine_adp »

Hi Grigory,

Thank you very much for posting. I will try your code.


Regards,

Danny
Regards,

Danny
Manila, Philippines
Post Reply