Reputation: 17293
I was wondering if there's a way to enable or disable monitor/screen timeout from a C++ program on a global scale? (I have one catch though, it must be backward compatible with Windows XP SP3.)
I'm talking about this global setting:
of this one for XP:
Upvotes: 1
Views: 912
Reputation: 432
A complete sample:
bool applyVideoTimeout(DWORD newtimeOut)
{
SYSTEM_POWER_POLICY powerPolicy;
DWORD ret;
DWORD size = sizeof(SYSTEM_POWER_POLICY);
ret = CallNtPowerInformation(SystemPowerPolicyAc, nullptr, 0, &powerPolicy, size);
if ((ret != ERROR_SUCCESS) || (size != sizeof(SYSTEM_POWER_POLICY)))
{
return false;
}
powerPolicy.VideoTimeout = newtimeOut
ret = CallNtPowerInformation(SystemPowerPolicyAc, &powerPolicy, size, nullptr, 0);
if ((ret != ERROR_SUCCESS))
{
return false;
}
return true;
}
Upvotes: 1
Reputation: 17293
For those who's interested, here's how to fix this:
Call CallNtPowerInformation(SystemPowerPolicyAc) API to get or set the display timeout value, and use SYSTEM_POWER_POLICY::VideoTimeout member.
Upvotes: 2