使用Win32 API获取Windows屏幕保护程序超时 我想在Windows上创建一个简单的C++应用程序来检查显示关闭时间。
经过一番搜索后,我使用windows.h找到了这个函数使用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
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;
}
}