]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/power.cpp
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"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS
*sps
)
39 if ( !::GetSystemPowerStatus(sps
) )
41 wxLogLastError(_T("GetSystemPowerStatus()"));
48 // ============================================================================
50 // ============================================================================
52 wxPowerType
wxGetPowerType()
54 SYSTEM_POWER_STATUS sps
;
55 if ( wxGetPowerStatus(&sps
) )
57 switch ( sps
.ACLineStatus
)
60 return wxPOWER_BATTERY
;
63 return wxPOWER_SOCKET
;
66 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps
.ACLineStatus
);
72 return wxPOWER_UNKNOWN
;
75 wxBatteryState
wxGetBatteryState()
77 SYSTEM_POWER_STATUS sps
;
78 if ( wxGetPowerStatus(&sps
) )
80 // there can be other bits set in the flag field ("charging" and "no
81 // battery"), extract only those which we need here
82 switch ( sps
.BatteryFlag
& 7 )
85 return wxBATTERY_NORMAL_STATE
;
88 return wxBATTERY_LOW_STATE
;
91 return wxBATTERY_CRITICAL_STATE
;
95 return wxBATTERY_UNKNOWN_STATE
;