實現視頻長時間播放而顯示器不會關閉或者屏保出現的簡單方法

在項目中遇到了一個問題,用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
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 SetThreadExecutionState periodically.

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.



 

發佈了24 篇原創文章 · 獲贊 1 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章