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 #if !defined(__WINCE_STANDARDSDK__)
36 typedef SYSTEM_POWER_STATUS_EX SYSTEM_POWER_STATUS
;
37 BOOL
GetSystemPowerStatus(SYSTEM_POWER_STATUS
*status
)
39 return GetSystemPowerStatusEx(status
, TRUE
);
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS
*sps
)
49 if ( !::GetSystemPowerStatus(sps
) )
51 wxLogLastError(wxT("GetSystemPowerStatus()"));
60 // ============================================================================
62 // ============================================================================
64 wxPowerType
wxGetPowerType()
66 #if !defined(__WINCE_STANDARDSDK__)
67 SYSTEM_POWER_STATUS sps
;
68 if ( wxGetPowerStatus(&sps
) )
70 switch ( sps
.ACLineStatus
)
73 return wxPOWER_BATTERY
;
76 return wxPOWER_SOCKET
;
79 wxLogDebug(wxT("Unknown ACLineStatus=%u"), sps
.ACLineStatus
);
86 return wxPOWER_UNKNOWN
;
89 wxBatteryState
wxGetBatteryState()
91 #if !defined(__WINCE_STANDARDSDK__)
92 SYSTEM_POWER_STATUS sps
;
93 if ( wxGetPowerStatus(&sps
) )
95 // there can be other bits set in the flag field ("charging" and "no
96 // battery"), extract only those which we need here
97 switch ( sps
.BatteryFlag
& 7 )
100 return wxBATTERY_NORMAL_STATE
;
103 return wxBATTERY_LOW_STATE
;
106 return wxBATTERY_CRITICAL_STATE
;
111 return wxBATTERY_UNKNOWN_STATE
;