MSDN地址: SetThreadExecutionState function
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
对于一些Windows应用程序,必须要保证os不能休眠才能有效工作,如迅雷下载软件,如果os进入休眠,则会导致网络不正常,从而导致不能下载东西。那木有没有1种机制,当打开软件的时候,就自动将os设为不休眠状态呢?这里我介绍一种QT应用程序不让windows进入休眠的方法:
只需要在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.
Flag Meaning ES_CONTINUOUS
0x80000000Informs 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
0x00000002Forces the display to be on by resetting the display idle timer. ES_SYSTEM_REQUIRED
0x00000001Forces 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 );