Windows 如何阻止屏保运行,并防止系统关闭显示器和进入待机状态

阻止屏幕保护

bool active = false;
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, false, &active, SPIF_SENDWININICHANGE);

防止系统关闭显示器或进入待机状态

程序启动时,调用:

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);

程序退出时,调用:

SetThreadExecutionState(ES_CONTINUOUS);

C#

//定义API函数
[DllImport("kernel32.dll")]
static extern uint SetThreadExecutionState(uint esFlags);
const uint ES_SYSTEM_REQUIRED = 0x00000001;
const uint ES_DISPLAY_REQUIRED = 0x00000002;
const uint ES_CONTINUOUS = 0x80000000;
//播放时调用
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
//播放结束后调用
SetThreadExecutionState(ES_CONTINUOUS);
赞(0)
未经允许不得转载:TaKaSa » Windows 如何阻止屏保运行,并防止系统关闭显示器和进入待机状态

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址