how to get WM_POWERBROADCAST under Fivewin ?

how to get WM_POWERBROADCAST under Fivewin ?

Postby Jimmy » Sat Feb 04, 2023 7:11 am

hi,

i want to avoid "Energy-Saving" when App is running.

---

there is a WM_POWERBROADCAST Message which i use under Xbase++ / Ot4xb
Code: Select all  Expand view
  ELSEIF nMsg == WM_POWERBROADCAST
      DO CASE
         CASE wp = PBT_APMQUERYSUSPEND
            RETURN  BROADCAST_QUERY_DENY

         CASE wp = PBT_APMQUERYSUSPENDFAILED
            RETURN  BROADCAST_QUERY_DENY

         // since Vista ?
         CASE wp = PBT_APMQUERYSTANDBY
            RETURN  BROADCAST_QUERY_DENY

         CASE wp = PBT_APMQUERYSTANDBYFAILED
            RETURN  BROADCAST_QUERY_DENY

         CASE wp = PBT_APMSTANDBY
            RETURN  BROADCAST_QUERY_DENY

*         CASE wp = PBT_APMBATTERYLOW         ; ::_OnDummy("PBT_APMBATTERYLOW       ",Time())
*         CASE wp = PBT_APMOEMEVENT           ; ::_OnDummy("PBT_APMOEMEVENT         ",Time())
*         CASE wp = PBT_APMPOWERSTATUSCHANGE  ; ::_OnDummy("PBT_APMPOWERSTATUSCHANGE",Time())
*         CASE wp = PBT_APMRESUMEAUTOMATIC    ; ::_OnDummy("PBT_APMRESUMEAUTOMATIC  ",Time())
*         CASE wp = PBT_APMRESUMECRITICAL     ; ::_OnDummy("PBT_APMRESUMECRITICAL   ",Time())
*         CASE wp = PBT_APMRESUMESUSPEND      ; ::_OnDummy("PBT_APMRESUMESUSPEND    ",Time())
*         CASE wp = PBT_APMSUSPEND            ; ::_OnDummy("PBT_APMSUSPEND          ",Time())

this will DENY "Energy-Saving" if available

i guess i have to place it in :HandleEvent() ... but in which CLASS :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Antonio Linares » Sat Feb 04, 2023 7:31 am

Dear Jimmy,

You have to inherit a new class from TWindow and redefine the Method HandleEvent( nMsg, nWParam, nLParam )

Code: Select all  Expand view
CLASS TMyWindow FROM TWindow

   CLASSDATA lRegistered
   
   METHOD HandleEvent( nMsg, nWParam, nLParam )

ENDCLASS

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow

   if nMsg == WM_POWERBROADCAST
   endif  
   
return Super:HandleEvent( nMsg, nWParam, nLParam )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Jimmy » Sat Feb 04, 2023 8:46 am

hi Antonio,
Antonio Linares wrote:You have to inherit a new class from TWindow and redefine the Method HandleEvent( nMsg, nWParam, nLParam )

Ok, thx i will try it
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Horizon » Tue Feb 07, 2023 8:23 am

+1
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Jimmy » Mon Jun 12, 2023 7:28 pm

hi,

it seem that WM_POWERBROADCAST is not "fired" on every Windows 10/11 PC

on some PC it run fine hole Day but other still go "sleep" :?
so i use another Option and that seems to work fine on all PC ( > VISTA )

SetStandbyOFF(.T.) -> no Energy Saving
SetStandbyOFF(.F.) -> normal Energy saving


https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
Code: Select all  Expand view
#define ES_CONTINUOUS        0x80000000
#define ES_SYSTEM_REQUIRED   0x00000001
#define ES_DISPLAY_REQUIRED  0x00000002
#define ES_USER_PRESENT      0x00000004
#define ES_AWAYMODE_REQUIRED 0x00000040

FUNCTION SetStandbyOFF( lOnOff )
LOCAL nRet := 0
   DEFAULT lOnOff := .F.
   IF lOnOff = .T.
      nRet := DllCall( "KERNEL32.Dll",, "SetThreadExecutionState", nOr( ES_CONTINUOUS, ES_SYSTEM_REQUIRED, ES_DISPLAY_REQUIRED, ES_AWAYMODE_REQUIRED ) )
   ELSE
      nRet := DllCall( "KERNEL32.Dll",, "SetThreadExecutionState", ES_CONTINUOUS )
   ENDIF
RETURN nRet

p.s. how to make a HB_FUNC() of it :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Horizon » Tue Jun 13, 2023 4:45 pm

+1
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby nageswaragunupudi » Tue Jun 13, 2023 5:18 pm

Code: Select all  Expand view
HB_FUNC( SETSTANDBY )
{
   EXECUTION_STATE esFlags = ( HB_ISLOG( 1 ) && hb_parl( 1 ) ?
      ( ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_AWAYMODE_REQUIRED ) :
      ES_CONTINUOUS );

   hb_retnl( ( long ) SetThreadExecutionState( esFlags ) );
}
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: how to get WM_POWERBROADCAST under Fivewin ?

Postby Jimmy » Tue Jun 13, 2023 5:23 pm

hi,

thx to show me how HB_FUNC() look like
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests