BatteryMonitor

BatteryMonitor Namespace Reference

Root namespace. More...

Functions

void addNotifyIcon (HWND hwnd)
 Adds an icon to the taskbar.
void cleanUp (HWND hwnd)
 Memory and handler cleanups, taskbar icon removal.
void errOut (void)
 Error output.
BATTERY_INFORMATION getBatteryInformation ()
 retrieves battery informations from the system.
void initDevice (void)
 Retrieves the path of the battery device.
HWND setupWindow (int nCmdShow)
 Shows the main window.
long setupWindowClass (void)
 registers the window class stored in classname.
void showBatteryInfo (HWND hwnd)
 Shows a balloon tip with battery information.
void shutdown (void)
 Tries to shut down the computer.
LRESULT CALLBACK wndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 The window procedure.

Variables

double battery = 0
 Battery charge.
long batterylifetime = -1
 Remaining battery lifetime in seconds.
HBRUSH blue
 Blue brush.
char classname [14]
 Name of registered window class.
char * devicepath
 Path to battery device.
HBRUSH green
 Green brush.
HINSTANCE instance
 Application instance.
HBRUSH red
 Red brush.
bool shutdown_enabled = false
 Indicates, if shutdown was invoked by BatteryMonitor.
UINT WM_TASKBARCREATED = 0
 Window message for taskbarcreated-event.
HBRUSH yellow
 Yellow brush.

Detailed Description

Root namespace.


Function Documentation

void BatteryMonitor::addNotifyIcon ( HWND  hwnd)

Adds an icon to the taskbar.

Parameters:
[in]hwndThe window handle of the window whose window procedure receives the events occuring.
See also:
Windows API

Definition at line 234 of file main.cpp.

void BatteryMonitor::cleanUp ( HWND  hwnd)

Memory and handler cleanups, taskbar icon removal.

Parameters:
[in]hwndThe window handle of the window associated with the taskbar icon.

Definition at line 92 of file main.cpp.

void BatteryMonitor::errOut ( void  )

Error output.

If BatteryMonitor is compiled in debug configuration (with a DEBUG defined) , a messagebox containing the error text is shown.

Definition at line 123 of file main.cpp.

BATTERY_INFORMATION BatteryMonitor::getBatteryInformation ( )

retrieves battery informations from the system.

This funktion retrieves battery information from the system. If any error occurs, errOut() will be called and the DesignedCapacity member of the returned struct is set to 0.

Returns:
Battery informations

Definition at line 328 of file main.cpp.

void BatteryMonitor::initDevice ( void  )

Retrieves the path of the battery device.

This function retrieves the path of the battery device and stores it into devicepath.

Definition at line 301 of file main.cpp.

HWND BatteryMonitor::setupWindow ( int  nCmdShow)

Shows the main window.

This funktion creates a window of the class stored in classname. This window is automatically set click-through, transparent and topmost.

Parameters:
[in]nCmdShowCan override the default visibility-parameters
Returns:
The window handle of the newly created window
See also:
Windows API

Definition at line 66 of file main.cpp.

long BatteryMonitor::setupWindowClass ( void  )

registers the window class stored in classname.

Returns:
The error code of RegisterClassEx, the corresponding windows api call.

Definition at line 105 of file main.cpp.

void BatteryMonitor::shutdown ( void  )

Tries to shut down the computer.

This function is called if remaining battery lifetime is less than 5 minutes.

See also:
addNotifyIcon(HWND hwnd)

Definition at line 273 of file main.cpp.

LRESULT CALLBACK BatteryMonitor::wndProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

The window procedure.

Here, all window logic is done such as mouse handling and so on.

See also:
Windows API for further information

Definition at line 133 of file main.cpp.


Variable Documentation

Battery charge.

Battery charge, positive if battery is discharging, negative if charging. (e.g. if 75% and changing, battery is 0.75). If battery status cannot be determined, battery is 2.

Definition at line 142 of file main.h.

Remaining battery lifetime in seconds.

Remaining battery lifetime in seconds. -1 is status cannot be determined.

Definition at line 148 of file main.h.

Name of registered window class.

See also:
Windows API

Definition at line 154 of file main.h.

Path to battery device.

The batteryinformation can be read from a pseudo-file, which path is stored here.

See also:
Windows API

Definition at line 115 of file main.h.

Application instance.

See also:
Windows API

Definition at line 134 of file main.h.

Window message for taskbarcreated-event.

This message must be registered with windows, so that the application gets informed if the taskbar is (re-)created. This is necessary to update the taskbar-icon.

Definition at line 162 of file main.h.