我不希望我的默认睡眠操作是混合睡眠,但偶尔我想使用混合睡眠。
我如何告诉 Windows“进入混合睡眠”?
注:我是不是要求将“睡眠”选项(待机)替换为混合睡眠操作。我需要两个都可以使用。
答案1
我最终一个黑客程序通过临时更改设置来实现这一点,但这真的不是我想要的……如果有人想出更好的解决方案,请发布。否则,如果有人觉得这有帮助,这里是代码:
#include <tchar.h>
#include <Windows.h>
#include <PowrProf.h>
extern "C"
//int _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
int _tmain(int, LPTSTR[])
{
ULONG error = 1;
HANDLE hSem = CreateSemaphore(NULL, 1, 1, TEXT("Global\\HybridSleep.{A88FD0FD-4C24-23c0-88F6-B51A145FB444}"));
if (hSem != NULL && GetLastError() != ERROR_ALREADY_EXISTS)
{
GUID *guid,
allowHybridSleepGuid = { 0x94ac6d29, 0x73ce, 0x41a6, 0x80, 0x9f, 0x63, 0x63, 0xba, 0x21, 0xb4, 0x7e },
sleepSubgroupGuid = { 0x238C9FA8, 0x0AAD, 0x41ED, 0x83, 0xF4, 0x97, 0xBE, 0x24, 0x2C, 0x8F, 0x20 };
SYSTEM_POWER_STATUS sps;
if (GetSystemPowerStatus(&sps))
{
error = PowerGetActiveScheme(NULL, &guid);
if (error == ERROR_SUCCESS)
{
__try
{
ULONG index;
error = (sps.ACLineStatus ? PowerReadACValueIndex : PowerReadDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, &index);
if (error == ERROR_SUCCESS && index <= 1)
{
__try
{
ULONG newIndex = 1 - index; //Opposite old value
error = (sps.ACLineStatus ? PowerWriteACValueIndex : PowerWriteDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, newIndex);
if (error == ERROR_SUCCESS)
{
PowerSetActiveScheme(NULL, guid);
SetSuspendState(FALSE, FALSE, FALSE);
}
}
__finally
{
if ((sps.ACLineStatus ? PowerWriteACValueIndex : PowerWriteDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, index) == ERROR_SUCCESS)
{ PowerSetActiveScheme(NULL, guid); }
}
}
}
__finally { LocalFree(guid); }
}
}
}
return error;
}
它执行对面的当前混合睡眠设置。
答案2
在控制面板中,您可以选择创建自己的电源计划。您可以通过它根据自己的喜好更改设置。您还可以在此处找到更多信息:http://windows.microsoft.com/en-us/windows7/Sleep-and-hibernation-frequently-asked-questions