琪依坤 | 羽毛在飛

Good Luck To You!

闲置关闭设备

目前知道的解决办法有如下几个:
1、采用定时器,每隔一定时间,发送一个键盘消息,例如,每隔50*1000毫秒发送keybd_event(VK_F24,0,KEYEVENTF_KEYUP| KEYEVENTF_SILENT,0);
   [OK]
2、SystemParametersInfo(SPI_SETBATTERYIDLETIMEOUT,dwTime,0,TRUE)
   [FAILED]
3、SetPowerRequirement(_T("BKL1:"), D0, POWER_NAME, NULL, 0)
   [FAILED]
   该方法来自msnews group,没有产生效果
4、PowerManager/ReloadActivityTimeouts
   修改[HKEY_LOCAL_MACHINE/System/CurrentControlSet/Control/Power/Timeouts]值,然后调用如下代码:
   HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE,_T("PowerManager/ReloadActivityTimeouts"));
 if(hEvent != NULL)
 {
  
  SetEvent(hEvent);
  
  CloseHandle(hEvent);
  
    }

 

示例代码:

#define RK_SYSTEM_CCS_CONTROL_POWER  TEXT("SYSTEM//CurrentControlSet//Control//Power")
#define RV_BATTPOWEROFF  TEXT("BattPowerOff")
#define RV_EXTPOWEROFF  TEXT("ExtPowerOff")

#define RK_SYSTEM_CCS_CONTROL_POWER2  TEXT("SYSTEM//CurrentControlSet//Control//Power//Timeouts")
#define RV_BATTPOWEROFF2  TEXT("BattSuspendTimeout")
#define RV_EXTPOWEROFF2  TEXT("ACSuspendTimeout")

DWORD dwValue=0;
 HKEY hKey=NULL;
 DWORD   dwDisposition;

 RegCreateKeyEx(HKEY_LOCAL_MACHINE, RK_SYSTEM_CCS_CONTROL_POWER2,(DWORD) 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, (LPSECURITY_ATTRIBUTES) NULL,&hKey, &dwDisposition);
 
 dwValue = 120;
 RegSetValueEx(hKey,RV_BATTPOWEROFF2, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));

 dwValue = 120;
 RegSetValueEx(hKey,RV_EXTPOWEROFF2, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));

 RegCloseKey(hKey);

HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE,_T("PowerManager/ReloadActivityTimeouts"));
 if(hEvent != NULL)
 {
  
  SetEvent(hEvent);
  
  CloseHandle(hEvent);
  
    }

更多精彩请关注公众号:

发表评论:

Powered By Z-BlogPHP 1.7.2

沪ICP备12032294号-1