|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <windows.h>
#include <powrprof.h>
#include <iostream>
#pragma comment(lib, "PowrProf.lib")
struct OldSettings
{
POWER_ACTION m_lidCloseAc;
POWER_ACTION m_lidCloseDc;
};
enum LidClose
{
LID_DO_NOTHING = 0,
LID_STAND_BY
};
class Petal
{
public:
Petal();
~Petal();
void SetLidCloseAction(UINT schemeID, GLOBAL_POWER_POLICY &policy, int action);
void SetResumePassword(bool resumePassword);
void Update();
public:
SYSTEM_POWER_STATUS m_battery;
GLOBAL_POWER_POLICY m_policy;
OldSettings m_oldSettings;
UINT m_schemeID;
};
// A function to set the lid close action to none.
void Petal::SetLidCloseAction(int action)
{
if (action == LID_DO_NOTHING)
{
m_policy.user.LidCloseAc.Action = PowerActionNone;
m_policy.user.LidCloseDc.Action = PowerActionNone;
}
else if (action == LID_STAND_BY)
{
m_policy.user.LidCloseAc.Action = PowerActionSleep;
m_policy.user.LidCloseDc.Action = PowerActionSleep;
}
WriteGlobalPwrPolicy(&m_policy);
SetActivePwrScheme(m_schemeID, &m_policy, NULL);
}
// A function to set whether the resume password option is on.
void Petal::SetResumePassword(bool resumePassword)
{
if (resumePassword)
{
system("powercfg /globalpowerflag on /option resumepassword");
}
else
{
system("powercfg /globalpowerflag off /option resumepassword");
}
}
void Petal::Update()
{
while (true)
{
GetSystemPowerStatus(&m_battery);
if (m_battery.BatteryLifePercent >= 50)
{
SetLidCloseAction(LID_DO_NOTHING);
}
else
{
SetLidCloseAction(LID_STAND_BY);
}
}
}
Petal::~Petal()
{
SetResumePassword(true);
m_policy.user.LidCloseAc.Action = m_oldSettings.lidCloseAc;
m_policy.user.LidCloseDc.Action = m_oldSettings.lidCloseDc;
WriteGlobalPwrPolicy(&m_policy);
SetActivePwrScheme(m_schemeID, &m_policy, NULL);
}
Petal::Petal()
{
SetResumePassword(false);
// Get the default scheme.
GetActivePwrScheme(&m_schemeID);
ReadGlobalPwrPolicy(&m_policy);
// Set some default vars.
m_oldSettings.lidCloseAc = m_policy.user.LidCloseAc.Action;
m_oldSettings.lidCloseDc = m_policy.user.LidCloseDc.Action;
SetLidCloseAction(LID_DO_NOTHING);
}
// Called when the program is run.
int main()
{
Petal *application = new Petal();
application->Update();
delete application;
}
这段代码编译时候报错。
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(27) : error C2146: syntax error : missing ';' before identifier 'LidOpenWakeAc'
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(27) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(27) : error C2501: 'LidOpenWakeAc' : missing storage-class or type specifiers
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(28) : error C2146: syntax error : missing ';' before identifier 'LidOpenWakeDc'
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(28) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\program files\microsoft sdks\windows\v6.0a\include\powrprof.h(28) : error C2501: 'LidOpenWakeDc' : missing storage-class or type specifiers |
|