foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions | Data Fields | Static Private Member Functions
CPowerRequestAPI

#include <CPowerRequest.h>

Public Member Functions

 CPowerRequestAPI ()
 
bool Bind ()
 
bool IsValid ()
 
HANDLE PowerCreateRequestNamed (const wchar_t *str)
 
void Toggle (HANDLE hRequest, bool bToggle, POWER_REQUEST_TYPE what)
 
void ToggleDisplay (HANDLE hRequest, bool bDisplay)
 
void ToggleExecution (HANDLE hRequest, bool bSystem)
 
void ToggleSystem (HANDLE hRequest, bool bSystem)
 

Static Public Member Functions

static bool IsWin8 ()
 
static WORD myGetOSVersion ()
 

Data Fields

pPowerClearRequest_t PowerClearRequest
 
pPowerCreateRequest_t PowerCreateRequest
 
pPowerSetRequest_t PowerSetRequest
 

Static Private Member Functions

template<typename func_t >
static bool Bind (func_t &f, HMODULE dll, const char *name)
 

Detailed Description

Definition at line 17 of file CPowerRequest.h.

Constructor & Destructor Documentation

CPowerRequestAPI::CPowerRequestAPI ( )
inline

Definition at line 19 of file CPowerRequest.h.

20  Bind();
21  }
pPowerClearRequest_t PowerClearRequest
Definition: CPowerRequest.h:65
pPowerCreateRequest_t PowerCreateRequest
Definition: CPowerRequest.h:63
pPowerSetRequest_t PowerSetRequest
Definition: CPowerRequest.h:64

Member Function Documentation

bool CPowerRequestAPI::Bind ( )
inline

Definition at line 22 of file CPowerRequest.h.

22  {
23  HMODULE kernel32 = GetModuleHandle(_T("kernel32.dll"));
24  return Bind(PowerCreateRequest, kernel32, "PowerCreateRequest")
25  && Bind(PowerSetRequest, kernel32, "PowerSetRequest")
26  && Bind(PowerClearRequest, kernel32, "PowerClearRequest") ;
27  }
pPowerClearRequest_t PowerClearRequest
Definition: CPowerRequest.h:65
pPowerCreateRequest_t PowerCreateRequest
Definition: CPowerRequest.h:63
pPowerSetRequest_t PowerSetRequest
Definition: CPowerRequest.h:64
template<typename func_t >
static bool CPowerRequestAPI::Bind ( func_t &  f,
HMODULE  dll,
const char *  name 
)
inlinestaticprivate

Definition at line 67 of file CPowerRequest.h.

67  {
68  f = reinterpret_cast<func_t>(GetProcAddress(dll, name));
69  return f != NULL;
70  }
bool CPowerRequestAPI::IsValid ( )
inline

Definition at line 28 of file CPowerRequest.h.

28 {return PowerCreateRequest != NULL;}
pPowerCreateRequest_t PowerCreateRequest
Definition: CPowerRequest.h:63
static bool CPowerRequestAPI::IsWin8 ( )
inlinestatic

Definition at line 54 of file CPowerRequest.h.

54  {
55  auto ver = myGetOSVersion();
56  return ver >= 0x602;
57  }
static WORD myGetOSVersion()
Definition: CPowerRequest.h:58
static WORD CPowerRequestAPI::myGetOSVersion ( )
inlinestatic

Definition at line 58 of file CPowerRequest.h.

58  {
59  const DWORD ver = GetVersion();
60  return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8);
61  }
HANDLE CPowerRequestAPI::PowerCreateRequestNamed ( const wchar_t *  str)

Definition at line 32 of file CPowerRequest.cpp.

32  {
33  winapi_substitute::REASON_CONTEXT ctx = {POWER_REQUEST_CONTEXT_VERSION, POWER_REQUEST_CONTEXT_SIMPLE_STRING};
34  ctx.Reason.SimpleReasonString = const_cast<wchar_t*>(str);
35  return this->PowerCreateRequest(&ctx);
36 }
union winapi_substitute::_REASON_CONTEXT::@14 Reason
pPowerCreateRequest_t PowerCreateRequest
Definition: CPowerRequest.h:63
void CPowerRequestAPI::Toggle ( HANDLE  hRequest,
bool  bToggle,
POWER_REQUEST_TYPE  what 
)
inline

Definition at line 44 of file CPowerRequest.h.

44  {
45  if (bToggle) {
46  PowerSetRequest(hRequest, what);
47  } else {
48  PowerClearRequest(hRequest, what);
49  }
50 
51  }
pPowerClearRequest_t PowerClearRequest
Definition: CPowerRequest.h:65
pPowerSetRequest_t PowerSetRequest
Definition: CPowerRequest.h:64
void CPowerRequestAPI::ToggleDisplay ( HANDLE  hRequest,
bool  bDisplay 
)
inline

Definition at line 40 of file CPowerRequest.h.

40  {
41  Toggle(hRequest, bDisplay, PowerRequestDisplayRequired);
42  }
void Toggle(HANDLE hRequest, bool bToggle, POWER_REQUEST_TYPE what)
Definition: CPowerRequest.h:44
void CPowerRequestAPI::ToggleExecution ( HANDLE  hRequest,
bool  bSystem 
)
inline

Definition at line 34 of file CPowerRequest.h.

34  {
35  const POWER_REQUEST_TYPE _PowerRequestExecutionRequired = (POWER_REQUEST_TYPE)3;
36  const POWER_REQUEST_TYPE RequestType = IsWin8() ? _PowerRequestExecutionRequired : PowerRequestSystemRequired;
37  Toggle(hRequest, bSystem, RequestType);
38  }
void Toggle(HANDLE hRequest, bool bToggle, POWER_REQUEST_TYPE what)
Definition: CPowerRequest.h:44
__in POWER_REQUEST_TYPE RequestType
Definition: CPowerRequest.h:10
static bool IsWin8()
Definition: CPowerRequest.h:54
void CPowerRequestAPI::ToggleSystem ( HANDLE  hRequest,
bool  bSystem 
)
inline

Definition at line 30 of file CPowerRequest.h.

30  {
31  Toggle(hRequest, bSystem, PowerRequestSystemRequired);
32  }
void Toggle(HANDLE hRequest, bool bToggle, POWER_REQUEST_TYPE what)
Definition: CPowerRequest.h:44

Field Documentation

pPowerClearRequest_t CPowerRequestAPI::PowerClearRequest

Definition at line 65 of file CPowerRequest.h.

pPowerCreateRequest_t CPowerRequestAPI::PowerCreateRequest

Definition at line 63 of file CPowerRequest.h.

pPowerSetRequest_t CPowerRequestAPI::PowerSetRequest

Definition at line 64 of file CPowerRequest.h.


The documentation for this class was generated from the following files: