1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/msw/power.cpp
3
// Purpose: power management functions for MSW
4
// Author: Vadim Zeitlin
7
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
// ============================================================================
13
// ============================================================================
15
// ----------------------------------------------------------------------------
17
// ----------------------------------------------------------------------------
19
// for compilers that support precompilation, includes "wx.h".
20
#include "wx/wxprec.h"
30
#include "wx/msw/private.h"
32
#if !defined(__WINCE_STANDARDSDK__)
35
typedef SYSTEM_POWER_STATUS_EX SYSTEM_POWER_STATUS;
36
BOOL GetSystemPowerStatus(SYSTEM_POWER_STATUS *status)
38
return GetSystemPowerStatusEx(status, TRUE);
42
// ----------------------------------------------------------------------------
44
// ----------------------------------------------------------------------------
46
static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS *sps)
48
if ( !::GetSystemPowerStatus(sps) )
50
wxLogLastError(wxT("GetSystemPowerStatus()"));
59
// ============================================================================
61
// ============================================================================
63
wxPowerType wxGetPowerType()
65
#if !defined(__WINCE_STANDARDSDK__)
66
SYSTEM_POWER_STATUS sps;
67
if ( wxGetPowerStatus(&sps) )
69
switch ( sps.ACLineStatus )
72
return wxPOWER_BATTERY;
75
return wxPOWER_SOCKET;
78
wxLogDebug(wxT("Unknown ACLineStatus=%u"), sps.ACLineStatus);
85
return wxPOWER_UNKNOWN;
88
wxBatteryState wxGetBatteryState()
90
#if !defined(__WINCE_STANDARDSDK__)
91
SYSTEM_POWER_STATUS sps;
92
if ( wxGetPowerStatus(&sps) )
94
// there can be other bits set in the flag field ("charging" and "no
95
// battery"), extract only those which we need here
96
switch ( sps.BatteryFlag & 7 )
99
return wxBATTERY_NORMAL_STATE;
102
return wxBATTERY_LOW_STATE;
105
return wxBATTERY_CRITICAL_STATE;
110
return wxBATTERY_UNKNOWN_STATE;