コード例 #1
0
ファイル: PowerSchemes.cpp プロジェクト: ruanzx/PSMJ
/// <summary>
/// Applies the custom power plan.
/// </summary>
/// <returns></returns>
BOOL PowerSchemes::ApplyCustomPowerPlan()
{
	BOOL bSuccess = TRUE;

	/************************************************************************/
	/* Create power request                                                 */
	/************************************************************************/   
	powerReasonContext = new REASON_CONTEXT;
	powerReasonContext->Version = POWER_REQUEST_CONTEXT_VERSION;
	powerReasonContext->Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING; // POWER_REQUEST_CONTEXT_DETAILED_STRING
	powerReasonContext->Reason.SimpleReasonString = L"Power capping for SMJ";

	hPowerRequest = PowerCreateRequest(powerReasonContext);

	// The calling process continues to run instead of being suspended or terminated 
	// by process lifetime management mechanisms. When and how long the process 
	// is allowed to run depends on the operating system and power policy settings.
	//
	// Value: 
	//  PowerRequestDisplayRequired   : The display remains on even if there is no user input for an extended period of time
	//  PowerRequestSystemRequired    : The system continues to run instead of entering sleep after a period of user inactivity
	//  PowerRequestAwayModeRequired  : Continues to run but turns off audio and video to give the appearance of sleep
	//  PowerRequestExecutionRequired : (win 8 or later)The calling process continues to run 
	//                                  instead of being suspended or terminated by process 
	//                                  lifetime management mechanisms
	if(!PowerSetRequest(hPowerRequest, PowerRequestSystemRequired)) 
	{
		//printf("PowerSetRequest failed\n"); 
	}

	DWORD mySchemeIndex;
	*mySchemeGuid = GUID_POWER_AWARE_SMJ;
	if( !IsPowerSchemeExist(*mySchemeGuid, mySchemeIndex))
	{
		/* Not exist */
		bSuccess&=CreateCustomPowerPlan();
	} 

	/************************************************************************/
	/*  Apply new power scheme                                              */
	/************************************************************************/
	bSuccess&=ApplyPowerScheme(*mySchemeGuid);

	bSuccess&=GetCurrentPowerSettings(); 

	return bSuccess;
}
コード例 #2
0
ファイル: win32_common.cpp プロジェクト: bronnel/RetroArch
bool win32_suppress_screensaver(void *data, bool enable)
{
#ifdef _XBOX
   return false;
#else
   typedef HANDLE (WINAPI * PowerCreateRequestPtr)(REASON_CONTEXT *context);
   typedef BOOL   (WINAPI * PowerSetRequestPtr)(HANDLE PowerRequest, POWER_REQUEST_TYPE RequestType);
   HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
   PowerCreateRequestPtr powerCreateRequest =
     (PowerCreateRequestPtr)GetProcAddress(kernel32, "PowerCreateRequest");
   PowerSetRequestPtr    powerSetRequest =
     (PowerSetRequestPtr)GetProcAddress(kernel32, "PowerSetRequest");

   if(enable)
   {
      if(powerCreateRequest && powerSetRequest)
      {
         /* Windows 7, 8, 10 codepath */
         POWER_REQUEST_CONTEXT RequestContext;
        HANDLE Request;

         RequestContext.Version = POWER_REQUEST_CONTEXT_VERSION;
         RequestContext.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING;
         RequestContext.Reason.SimpleReasonString = L"RetroArch running";

         Request = PowerCreateRequest(&RequestContext);

         powerSetRequest( Request, PowerRequestDisplayRequired);
         return true;
      }
     else
      {
         /* XP / Vista codepath */
         SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
         return true;
      }
   }

   return false;
#endif
}