How to disable Windows screensaver and power management

xiaoxiao2021-03-06  79

When writing programs such as monitoring, multimedia, large-scale data processing, we often need to disable screen protection and power management to ensure the normal operation of the program. In general, it is possible to use analog mouse keyboard actions to disable screen protection and power management under 95, but the same method is applied to 2000 / NT, but it is often invalid, which is related to the system settings. Using the Windows Platform SDK interface API can easily disable screen protection and power management, the only defect is that this method cannot be applied to WIN32 applications under Windows 95. Here, I will introduce the specific method.

Use SystemParametersInfo API to achieve this disable the screen saver and power management: BOOL SystemParametersInfo (UINT uiAction, // system parameter to retrieve or set UINT uiParam, // depends on action to be taken PVOID pvParam, // depends on action to be Taken uint fwinini // user profile update option;

The following is to disable the screen saver code: void DisableScrSaver () {BOOL bScrActive; SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0, & bScrActive, 0); if (bScrActive) {SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);}} The following is the screensaver is activated Code: Void CNETRGCLTDLG :: EnableScrsaver () {SystemParametersInfo (SPI_SETSCREENSAVEAVE, TRUE, NULL, 0);}

Since the disabled power protection cannot be used by the Win32 application under win95, it is necessary to determine the current operating system in advance whether it is Win95, which is assumed to be implemented with the function bool iswin95 (). The following is a code for disabling power protection: void disablepmmsaver () {// Due to the particularity of power management, it cannot be implemented directly with the SPI_SETLOWPowerActive command word, but to set the delay. //

SystemParametersInfo (SPI_GETLOWPOWERTIMEOUT, 0, & m_nLowpowerTimeout, 0); SystemParametersInfo (SPI_GETPOWEROFFTIMEOUT, 0, & m_nPoweroffTimeout, 0); SystemParametersInfo (SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0); SystemParametersInfo (SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);}

The following code is to enable power protection void EnablePmmSaver () {SystemParametersInfo (SPI_SETLOWPOWERTIMEOUT, m_nLowpowerTimeout, NULL, 0); SystemParametersInfo (SPI_SETPOWEROFFTIMEOUT, m_nPoweroffTimeout, NULL, 0); m_nLowpowerTimeout = 0; m_nPoweroffTimeout = 0;}

转载请注明原文地址:https://www.9cbs.com/read-121860.html

New Post(0)