鱼C论坛

 找回密码
 立即注册
查看: 3516|回复: 2

引用头文件的问题

[复制链接]
发表于 2012-6-12 20:58:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-6-12 21:17:19 | 显示全部楼层
:(竟然没有人编译通过的么
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-6-13 00:21:52 | 显示全部楼层
才开始学C++  看不懂哦
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-13 17:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表