]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/power.cpp
022e624dadfb8c52521cea4d5170ee83442294fe
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"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS
*sps
)
38 if ( !::GetSystemPowerStatus(sps
) )
40 wxLogLastError(_T("GetSystemPowerStatus()"));
47 // ============================================================================
49 // ============================================================================
51 wxPowerType
wxGetPowerType()
53 SYSTEM_POWER_STATUS sps
;
54 if ( wxGetPowerStatus(&sps
) )
56 switch ( sps
.ACLineStatus
)
59 return wxPOWER_BATTERY
;
62 return wxPOWER_SOCKET
;
65 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps
.ACLineStatus
);
71 return wxPOWER_UNKNOWN
;
74 wxBatteryState
wxGetBatteryState()
76 SYSTEM_POWER_STATUS sps
;
77 if ( wxGetPowerStatus(&sps
) )
79 // there can be other bits set in the flag field ("charging" and "no
80 // battery"), extract only those which we need here
81 switch ( sps
.BatteryFlag
& 7 )
84 return wxBATTERY_NORMAL_STATE
;
87 return wxBATTERY_LOW_STATE
;
90 return wxBATTERY_CRITICAL_STATE
;
94 return wxBATTERY_UNKNOWN_STATE
;