3 typedef HANDLE (WINAPI * pPowerCreateRequest_t) (
7 typedef BOOL (WINAPI * pPowerSetRequest_t) (
12 typedef BOOL (WINAPI * pPowerClearRequest_t) (
23 HMODULE kernel32 = GetModuleHandle(_T(
"kernel32.dll"));
31 Toggle(hRequest, bSystem, PowerRequestSystemRequired);
35 const POWER_REQUEST_TYPE _PowerRequestExecutionRequired = (POWER_REQUEST_TYPE)3;
36 const POWER_REQUEST_TYPE
RequestType =
IsWin8() ? _PowerRequestExecutionRequired : PowerRequestSystemRequired;
37 Toggle(hRequest, bSystem, RequestType);
41 Toggle(hRequest, bDisplay, PowerRequestDisplayRequired);
44 void Toggle(
HANDLE hRequest,
bool bToggle, POWER_REQUEST_TYPE what) {
59 const DWORD ver = GetVersion();
60 return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8);
67 template<
typename func_t>
static bool Bind(func_t & f, HMODULE dll,
const char * name) {
68 f =
reinterpret_cast<func_t
>(GetProcAddress(dll, name));
76 void SetSystem(
bool bSystem);
77 void SetExecution(
bool bExecution);
78 void SetDisplay(
bool bDisplay);
void ToggleExecution(HANDLE hRequest, bool bSystem)
void SetDisplay(bool bDisplay)
void SetSystem(bool bSystem)
static WORD myGetOSVersion()
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
HANDLE PowerCreateRequestNamed(const wchar_t *str)
static bool Bind(func_t &f, HMODULE dll, const char *name)
void Toggle(HANDLE hRequest, bool bToggle, POWER_REQUEST_TYPE what)
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
pPowerClearRequest_t PowerClearRequest
__in POWER_REQUEST_TYPE RequestType
pPowerCreateRequest_t PowerCreateRequest
CPowerRequest(const wchar_t *Reason)
void ToggleSystem(HANDLE hRequest, bool bSystem)
void ToggleDisplay(HANDLE hRequest, bool bDisplay)
pPowerSetRequest_t PowerSetRequest
void SetExecution(bool bExecution)