1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/power.cpp
3 // Purpose: power management functions for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/msw/private.h"
34 typedef SYSTEM_POWER_STATUS_EX SYSTEM_POWER_STATUS
;
35 BOOL
GetSystemPowerStatus(SYSTEM_POWER_STATUS
*status
)
37 return GetSystemPowerStatusEx(status
, TRUE
);
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS
*sps
)
47 if ( !::GetSystemPowerStatus(sps
) )
49 wxLogLastError(_T("GetSystemPowerStatus()"));
56 // ============================================================================
58 // ============================================================================
60 wxPowerType
wxGetPowerType()
62 SYSTEM_POWER_STATUS sps
;
63 if ( wxGetPowerStatus(&sps
) )
65 switch ( sps
.ACLineStatus
)
68 return wxPOWER_BATTERY
;
71 return wxPOWER_SOCKET
;
74 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps
.ACLineStatus
);
80 return wxPOWER_UNKNOWN
;
83 wxBatteryState
wxGetBatteryState()
85 SYSTEM_POWER_STATUS sps
;
86 if ( wxGetPowerStatus(&sps
) )
88 // there can be other bits set in the flag field ("charging" and "no
89 // battery"), extract only those which we need here
90 switch ( sps
.BatteryFlag
& 7 )
93 return wxBATTERY_NORMAL_STATE
;
96 return wxBATTERY_LOW_STATE
;
99 return wxBATTERY_CRITICAL_STATE
;
103 return wxBATTERY_UNKNOWN_STATE
;