Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Win32 API获取Windows屏幕保护程序超时 我想在Windows上创建一个简单的C++应用程序来检查显示关闭时间。_C++_Winapi - Fatal编程技术网

使用Win32 API获取Windows屏幕保护程序超时 我想在Windows上创建一个简单的C++应用程序来检查显示关闭时间。

使用Win32 API获取Windows屏幕保护程序超时 我想在Windows上创建一个简单的C++应用程序来检查显示关闭时间。,c++,winapi,C++,Winapi,经过一番搜索后,我使用windows.h找到了这个函数 int time; bool check; check = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &time, 0); if (check) { cout << "The Screen Saver time is : " << time << endl; } else { cout << "Sorry dud

经过一番搜索后,我使用windows.h找到了这个函数

int time;
bool check;
check = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &time, 0);
if (check) {
    cout << "The Screen Saver time is : " << time << endl;
}
else {
    cout << "Sorry dude the windows api can't do it" << endl;
}
int时间;
布尔检查;
check=SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT,0,&time,0);
如果(检查){
cout屏幕保护程序超时和显示断电超时是两件不同的事情

SPI_GETSCREENSAVETIMEOUT
返回屏幕保护程序超时时间——激活屏幕保护程序的时间。如果从未配置屏幕保护程序,则该值为0

显示断电超时时间是切断屏幕电源的时间,是电源配置文件的一部分(例如电池和交流电源)

用于获取显示器断电超时:

#include <iostream>
#include <windows.h>
#include <powerbase.h>

#pragma comment(lib, "PowrProf.lib")

int main() {
    SYSTEM_POWER_POLICY powerPolicy;
    DWORD ret;

    ret = CallNtPowerInformation(SystemPowerPolicyCurrent, nullptr, 0, &powerPolicy, sizeof(powerPolicy));

    if (ret == ERROR_SUCCESS) {
        std::cout << "Display power-off timeout : " << powerPolicy.VideoTimeout << "s \n";
    }
    else {
        std::cerr << "Error 0x" << std::hex << ret << std::endl;
    }

}