⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getbat.cpp

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

#include <stdio.h>
#include <windows.h>
#include <tchar.h>

// display battery information
int WINAPI 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 
{
    SYSTEM_POWER_STATUS_EX2 sps;
    WORD wMainLevels;
    WORD wBackupLevels;
    BOOL fSupportsChange;
    DWORD dwValue;
    
    // get number of levels
    dwValue = BatteryDrvrGetLevels();
    wMainLevels = LOWORD(dwValue);
    wBackupLevels = HIWORD(dwValue);
    
    // do we support change notifications?
    fSupportsChange = BatteryDrvrSupportsChangeNotification();
    
    // get status
    DWORD dwLen = GetSystemPowerStatusEx2(&sps, sizeof(sps), TRUE);
    ASSERT(dwLen == sizeof(sps));
    if(dwLen == 0) {
        RETAILMSG(TRUE, (_T("GetSystemPowerStatusEx2() failed %d\r\n"), 
            GetLastError()));
    } else {
        RETAILMSG(TRUE, (_T("Line status is %s (0x%x)\r\n"), 
            sps.ACLineStatus == AC_LINE_ONLINE ? _T("AC") : 
            sps.ACLineStatus == AC_LINE_OFFLINE ? _T("Offline") :
            sps.ACLineStatus == AC_LINE_BACKUP_POWER ? _T("Backup") :
            sps.ACLineStatus == AC_LINE_UNKNOWN ? _T("Unknown") : _T("???"), 
            sps.ACLineStatus));
        RETAILMSG(TRUE, (_T("Main battery flag 0x%02x (%u levels), %02u%%, %lu (0x%08x) seconds remaining of %lu (0x%08x)\r\n"),
            sps.BatteryFlag, wMainLevels, sps.BatteryLifePercent, 
            sps.BatteryLifeTime, sps.BatteryLifeTime, 
            sps.BatteryFullLifeTime, sps.BatteryFullLifeTime));
        RETAILMSG(TRUE, (_T("Backup battery flag 0x%02x (%u levels), %02u%%, %lu (0x%08x) seconds remaining of %lu (0x%08x)\r\n"),
            sps.BackupBatteryFlag, wBackupLevels, sps.BackupBatteryLifePercent, 
            sps.BackupBatteryLifeTime, sps.BackupBatteryLifeTime, 
            sps.BackupBatteryFullLifeTime, sps.BackupBatteryFullLifeTime));
        RETAILMSG(TRUE, (_T("%u mV, %d mA, avg %d ma, avg interval %d, consumed %d mAH, %d C, backup %u mV, chem 0x%x\r\n"),
            sps.BatteryVoltage, sps.BatteryCurrent, sps.BatteryAverageCurrent, 
            sps.BatteryAverageInterval, sps.BatterymAHourConsumed, 
            sps.BatteryTemperature, sps.BackupBatteryVoltage, 
            sps.BatteryChemistry));
    }
    
    // update change timing information
    if(fSupportsChange) {
        TCHAR szBuf[256];
        SYSTEMTIME st;
        DWORD dwUsage, dwPreviousUsage;
        int iLen;
        
        BatteryGetLifeTimeInfo(&st, &dwUsage, &dwPreviousUsage);
        iLen = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szBuf, 
            sizeof(szBuf) / sizeof(szBuf[0]));
        ASSERT(iLen != 0);
        RETAILMSG(TRUE, (_T("Batteries last changed at %s\r\n"), szBuf));
        iLen = GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szBuf, 
            sizeof(szBuf) / sizeof(szBuf[0]));
        ASSERT(iLen != 0);
        RETAILMSG(TRUE, (_T("  on %s\r\n"), szBuf));
        RETAILMSG(TRUE, (_T("%lu ms usage, %lu ms previous usage\r\n"), dwUsage,
            dwPreviousUsage));
    }
    
    return 0;
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -