Hi,
I have a program that does not get its form properly updated with Palm OS
3.5 DR4.
I am responding to frmUpdateEvent and calling my MainUpdateForm() routine
that calls FrmDrawForm(pForm); However, within the MainUpdateForm, I call my
UpdateBatteryLevel() function that puts a bitmap on the form to show the
current battery level. When this is called, I get a bus error in POSE.
Any ideas on what the problem might be?
Here is some code of interest.
// from MainEventHandler()
case frmUpdateEvent:
MainUpdateForm();
break;
static void MainUpdateForm(void)
{
// ??? FormPtr pForm = FrmGetActiveForm();
FormPtr pForm = FrmGetFormPtr(formID_main);
FrmDrawForm(pForm);
// update battery level
UpdateBatteryLevel(true);
}
static void UpdateBatteryLevel(Boolean forceUpdate)
{
VoidHand hBitmap;
WinHandle hScreen;
Int batteryBitmapID = bitmapID_battery100;
Byte batteryLevelPercent;
Boolean pluggedIn;
RectangleType rect;
static int lastBatteryLevel = -1;
int currentBatteryLevel;
GetVoltage(NULL, &batteryLevelPercent, &pluggedIn);
if(batteryLevelPercent <= 10)
batteryBitmapID = bitmapID_battery000;
else if(batteryLevelPercent <= 20)
batteryBitmapID = bitmapID_battery020;
else if(batteryLevelPercent <= 40)
batteryBitmapID = bitmapID_battery040;
else if(batteryLevelPercent <= 60)
batteryBitmapID = bitmapID_battery060;
else if(batteryLevelPercent <= 80)
batteryBitmapID = bitmapID_battery080;
else if(batteryLevelPercent <= 100)
batteryBitmapID = bitmapID_battery100;
// update only if level has changed
currentBatteryLevel = batteryBitmapID + (pluggedIn ? 1000 : 0);
if(lastBatteryLevel == currentBatteryLevel && !forceUpdate)
return;
lastBatteryLevel = currentBatteryLevel;
hScreen = WinSetDrawWindow(hOffscreen);
// draw battery level
hBitmap = DmGet1Resource('Tbmp', batteryBitmapID);
WinDrawBitmap(MemHandleLock(hBitmap), 0, 0);
MemHandleUnlock(hBitmap);
// drawing charging
if(pluggedIn) {
if(batteryLevelPercent < 100)
hBitmap = DmGet1Resource('Tbmp', bitmapID_charging);
else
hBitmap = DmGet1Resource('Tbmp', bitmapID_chargingComplete);
WinDrawBitmap(MemHandleLock(hBitmap), CHARGING_LEFT, CHARGING_TOP);
MemHandleUnlock(hBitmap);
}
// set display back to screen
hOffscreen = WinSetDrawWindow(hScreen);
// copy battery level to screen
rect.topLeft.x = 0;
rect.topLeft.y = 0;
rect.extent.x = BATTERY_WIDTH;
rect.extent.y = BATTERY_HEIGHT;
WinCopyRectangle(hOffscreen, hScreen, &rect,
BATTERY_LEFT, BATTERY_TOP, scrCopy);
}
// note here that hOffscreen is created with my StartApplication code.
// Here is a portion.
hOffscreen = WinCreateOffscreenWindow(BATTERY_WIDTH, BATTERY_HEIGHT,
screenFormat, &err);
Thanks,
Mike McCollister
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html