我想防止显示器进入睡眠状态(Windows设置,而不是显示器设置)。我正在使用c++。我打什么电话?

最佳答案

class KeepDisplayOn
{
public:
    KeepDisplayOn()
    {
        mPrevExecState = ::SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
        ::SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &mPrevScreenSaver, 0);
        ::SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, FALSE, NULL, 0);
    }

    ~KeepDisplayOn()
    {
        ::SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, mPrevScreenSaver, NULL, 0);
        ::SetThreadExecutionState(mPrevExecState);
    }

private:
    UINT                mPrevScreenSaver;
    EXECUTION_STATE     mPrevExecState;
};

07-24 09:23