This might help, from the list archives:

>>At 2:00 PM -0700 10/20/98, Jeff Davey wrote:
>>Does anyone know if there is a way to call battery image that appears on
>>the top of all the [Application] forms? I found the APIs to get battery
>>status and such, but it would be nice to put the bitmap in an application.
>
>Bitmap??  Ain't no bitmap, it's all just 'drawn', based on a gadget.  A
bitmap would probably save a bunch of lines of code though.
>
>--Bob
>
>P.S.  Here's a 'template' for the function, to get you started. :)
>
>static void DisplayBatteryLevel (FormPtr formP)
>{
>  RectangleType  r;
>   RectangleType  gaugeMainR;
>   RectangleType  gaugeEndR;
>   Word           frameEndWidth;
>   Word           frameEndHeight;
>   Word           batteryGaugeWidth;
>   Word           batteryPowerWidth;
>   Word           batteryGaugeMainWidth;
>   Word           batteryGaugeEndWidth;
>   Short          x1, x2, y1, y2;
>   Byte           batteryPercent;
>
>   // Now fill in how much of the battery is left
>   SysBatteryInfo(false, 0, 0, 0, 0, 0, &batteryPercent);
>
>   // If percent is same as old, do nothing
>   if (batteryPercent == LastKnownBatteryPercent)
>      return;
>
>   // Save new battery percent
>   LastKnownBatteryPercent = batteryPercent;
>
>   // Get the bounds of the battery gadget.
>   formP = FrmGetActiveForm();
>   FrmGetObjectBounds (formP, FrmGetObjectIndex (formP,
BatteryTestMainBatteryGadget), &r);
>
>   frameEndHeight = r.extent.y / 4;
>   frameEndWidth = frameEndHeight;
>   batteryGaugeWidth = r.extent.x - frameEndWidth - 3;
>
>   // Draw the frame of the battery gadget.
>   x1 = r.topLeft.x;
>   y1 = r.topLeft.y;
>   x2 = x1 + r.extent.x - frameEndWidth - 2;
>   y2 = y1 + r.extent.y - 1;
>   WinDrawLine (x1, y1, x1, y2);                   // left side
>   WinDrawLine (x1, y1, x2, y1);                   // top side
>   WinDrawLine (x1, y2, x2, y2);                   // bottom side
>   WinDrawLine (x2, y1, x2, y1 + frameEndHeight);
>   WinDrawLine (x2, y2, x2, y2 - frameEndHeight);
>   WinDrawLine (x2, y1 + frameEndHeight, x2 + frameEndWidth, y1 +
frameEndHeight);
>   WinDrawLine (x2, y2 - frameEndHeight, x2 + frameEndWidth, y2 -
frameEndHeight);
>   WinDrawLine (x2 + frameEndWidth, y1 + frameEndHeight,
>                x2 + frameEndWidth, y2 - frameEndHeight);
>
>   batteryGaugeWidth = r.extent.x - 2;
>   batteryPowerWidth = (batteryPercent * batteryGaugeWidth + 50) / 100;
>
>   batteryGaugeMainWidth = r.extent.x - frameEndWidth - 3;
>   batteryGaugeEndWidth = batteryGaugeWidth - batteryGaugeMainWidth;
>
>   // Draw the power indicator.
>   gaugeMainR.topLeft.x = r.topLeft.x + 1;
>   gaugeMainR.topLeft.y = r.topLeft.y + 1;
>   gaugeMainR.extent.x = batteryGaugeMainWidth;
>   gaugeMainR.extent.y = r.extent.y - 2;
>
>   gaugeEndR.topLeft.x = r.topLeft.x + batteryGaugeMainWidth + 1;
>   gaugeEndR.topLeft.y = r.topLeft.y + frameEndHeight + 1;
>   gaugeEndR.extent.x = batteryGaugeEndWidth - 1;
>   gaugeEndR.extent.y = r.extent.y - (frameEndHeight * 2) - 2;
>
>   if (batteryPowerWidth < batteryGaugeMainWidth)
>      gaugeMainR.extent.x = batteryPowerWidth;
>   WinDrawRectangle (&gaugeMainR, 0);
>
>   if (batteryPowerWidth < batteryGaugeMainWidth)
>      {
>      // And clear the battery which is used up
>      gaugeMainR.topLeft.x += gaugeMainR.extent.x;
>      gaugeMainR.extent.x = batteryGaugeMainWidth - gaugeMainR.extent.x;
>      WinEraseRectangle (&gaugeMainR, 0);
>      }
>
>   if (batteryPowerWidth > batteryGaugeMainWidth)
>      {
>      gaugeEndR.extent.x = batteryPowerWidth - batteryGaugeMainWidth;
>      WinDrawRectangle (&gaugeEndR, 0);
>
>      gaugeEndR.topLeft.x += gaugeEndR.extent.x;
>      gaugeEndR.extent.x = batteryGaugeEndWidth - gaugeEndR.extent.x;
>      }
>
>   WinEraseRectangle (&gaugeEndR, 0);
>}

My guess that updating the levels ever 15 seconds or so would not be
unreasonable.
Look up using the nilEvent message to drive your update.

----- Original Message -----
From: "John Crouch" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Wednesday, May 09, 2001 3:12 PM
Subject: Battery Meter


> I would like to create my own battery meter to visually display the
battery
> level when my app is running.  I have searched the Palm app source code as
> well as the newsgroup for ideas on how to do this but could not find
> anything.
>
> I am particularly interested in:
>
> 1. How to display the visual battery on the screen.  Some sort of gadget
> with a bitmap on top of it perhaps?
>
> 2. How to continually poll the battery so the display can be updated?
Would
> it be best to do this with an alarm, and if so how often is a reasonable
> amount of elapsed time without hogging processor time.
>
> If anyone can steer me in the right direction on how to do this I would
> appreciate it.  Thanks.
>
>
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to