Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

BatteryX

2.65/5 (14 votes)
15 Aug 20054 min read 1   778  
BatteryX shows you the current powerstatus of your Notebook.

Image 1

Introduction

Take a look at the manual inside the zip to see what's new.

Why BatteryX

BatteryX is a "must have" for each Notebook user. Use this program if you won't always take a look at the Windows battery using your mouse. BatteryX uses almost no resources. It has an intelligent energy information system. BatteryX refreshes automatically by default every 35 seconds but the user can also change the refresh time. It also uses the Windows Power Information Messages to refresh. So, if you connect to an external power device, BatteryX shows you "AC". I use these two systems because Windows does not always automatically send power massages, so just to be sure I've also set a refresh interval. If you are connected to an external power device, the interval timer stops and starts again when you're disconnected from the external power device. This system saves resources.

Compatible with

BatteryX is designed for Win XP or higher but should also work probably with Win 2K.

Refresh system

Image 2

Basic system

Image 3

Source code

Use VC++ 6.0 with the latest service pack to compile the source codes!!! If you want to compile it using VC++ .NET 2003 you're also able to compile the source but you need to change one parameter in the GetDevicePowerState function. This API seems to be different in VC++ 6.0 and VC++ .NET 2003.

How to work with the source:

Image 4

If you want to compile the source in release mode, just select battery2 in Release mode, otherwise select battery2 in Debug mode. All other parts of the project compiles in the mode which is selected for battery2.

Image 5

Press Erstellen->Alles neu erstellen to compile all parts of the project in the current selected mode.

Image 6

It seems that I may have installed another version of VC++ 6.0. With my version, I need just one parameter for ::GetDevicePowerState. Other versions need two parameters which you can see in the second part here. Just edit this method that works on your pc!!

Working with plug-in SDK

Since Version 2.2 UPDATE2 BatteryX supports also dynamic plug-in's. The source for the plug-in SDK is also included in the package. The main thought on plug-in support: If you've created a good program and want to include it into BatteryX, i.e. CPU info, Hardware Info, Remoteable Webcam control, wlan-status etc.., you just need to include the source into the SDK and start your code using the "Start"-method. You must also set the plug-in version, just version 1, and the internal name. This is the name which you can then see in the popup-menu in BatteryX.

After compiling the plug-in you'll get a DLL. This is the plug-in. Just copy it into the "plugins" folder in the Binaries directory. Then press the right mouse button on BatteryX. You can then see your own coded plug-in in the pop-up menu. After you've select it, BatteryX calls the "Start" method in the plug-in.

Image 7

In the sample picture you can see the new plug-in. "Testplugin which shows a Dialog" is just the internal name. By the way, you don't need to restart BatteryX. Every time you select the pop-up a new list of correct plug-in's are listed ;).

The directory looks like this...

Image 8

By the way: If you compile with STRG-F5 now, plug-ins are loaded because of the location. VC starts the program from battery2 instead of battery2\Binaries, so just start the EXE directly. Afterwards all the loaded plug-ins are correctly listed in the popup-menu.

Plug-in SDK 1.0 with dialog

I have updated the plug-in SDK v1.0 because you could have some problems to start a dialog in a DLL. This code now includes the MFC class code for a window and a function called DoModal().

void DoModal()
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CPluginDialog pd;
    pd.DoModal();
}

You need to insert the AFX_MANAGE_STATE command. If you don't include this line, the dialog does not start.

Credits

  • Thanks to Herbert K. for testing and hints.
  • Thanks to Daniel Chirca for CBattery.
  • Thanks to David Forrester for CBitmapDialog.
  • Thanks to Chris Maunder for CTestProgressCtrl.
  • Thanks to Keith Rule for CMemDC class.
  • Thanks to all beta testers.

TODO

  • Automatic updating system.
  • Integration into Taskbar !! like the IBM battery.
  • Operation system check for compatibility test.
  • Integration of Speech engine (maybe as a plug-in).

Take a look at histroy.txt in the package to see what's new. If you've ideas about how to enhance the program, please let me know.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here