实现视频长时间播放而显示器不会关闭或者屏保出现的简单方法


MSDN地址: SetThreadExecutionState function


、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

对于一些Windows应用程序,必须要保证os不能休眠才能有效工作,如迅雷下载软件,如果os进入休眠,则会导致网络不正常,从而导致不能下载东西。那木有没有1种机制,当打开软件的时候,就自动将os设为不休眠状态呢?这里我介绍一种QT应用程序不让windows进入休眠的方法:

[html]  view plain  copy
  1. ::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);  
只需要在QT应用程序入口函数中加入该语句就可以了,这样os就不会进入休眠了,该语句声明在winbase.h中,是windows的api。


、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

实现视频长时间播放而显示器不会关闭或者屏保出现的简单方法: 


在项目中遇到了一个问题,用directdraw做的播放器在系统长时间运行后,由于系统设定了省电模式等电源选项的问题,长时间运行后播放器会出现黑屏现象。

 

解决方案:摘自MSDN

SetThreadExecutionState

 

The SetThreadExecutionState function enables applications to inform the system that it is in use, thereby preventing the system from entering the sleeping power state or turning off the display while the application is running.

EXECUTION_STATE SetThreadExecutionState( EXECUTION_STATE esFlags );

Parameters
esFlags
[in] Thread's execution requirements. This parameter can be one or more of the following values.
FlagMeaning
ES_CONTINUOUS
0x80000000
Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.
ES_DISPLAY_REQUIRED
0x00000002
Forces the display to be on by resetting the display idle timer.
ES_SYSTEM_REQUIRED
0x00000001
Forces the system to be in the working state by resetting the system idle timer.
Return Values

If the function succeeds, the return value is the previous thread execution state.

If the function fails, the return value is NULL.

Remarks

Activities that are automatically detected include local keyboard or mouse input, server activity, and changing window focus. Activities that are not automatically detected include disk or CPU activity and video display.

Calling SetThreadExecutionState without ES_CONTINUOUS simply resets the idle timer; to keep the display or system in the working state, the thread must call SetThreadExecutionStateperiodically.

To run properly on a power-managed computer, applications such as fax servers, answering machines, backup agents, and network management applications must use ES_SYSTEM_REQUIRED | ES_CONTINUOUS when they process events. Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input. Applications such as word processors, spreadsheets, browsers, and games do not need to call SetThreadExecutionState .

The SetThreadExecutionState function cannot be used to prevent the user from putting the computer in standby mode. To prevent the user from putting the computer in standby mode, the application must deny the PBT_APMQUERYSUSPEND event.

This function does not stop the screen saver from executing either.


、参考来源:xp、win7下如何取消屏保、取消电源管理、、、、、、

取消电源管理,避免睡眠、待机:
::SetThreadExecutionState( ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED );
 
恢复电源管理:
::SetThreadExecutionState( ES_CONTINUOUS );



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值