It would be real nice if someone from Palm would let us know if there
will be a "proper" scheme for uniquely numbering the Bitmap IDs
uniquely for the MenuCmdBar.
The following code snippet is a suggestion for how we developers
could unilaterally be unique with our apps by searching for the first
free Resource ID after the System MenuCmdBar Bitmap Resource ID's
(BarInfoBitmap = 10037) but before the SecLockBitmap = 10050. Which
gives us 13 to play with (which would fill up the MenuCmd Bar if we
ever got to it!!!!).
//find an unused resource ID starting from the BarInfoBitmap
while ( DmGetResource ( bitmapRsc,
BarInfoBitmap + resID ) != 0 && (BarInfoBitmap + resID ) <
SecLockBitmap)
{
resID++;
}
Boolean HandleMenuCmdBarNotifyLaunch(SysNotifyParamType *params)
{
DmSearchStateType searchInfo;
UInt16 cardNo;
LocalID appdbID;
Err err=errNone;
UInt16 bitmapID=BarCopyBitmap;
UInt32 appRef=0;
UInt32 iconRef=0;
DmOpenRef iconRsrc=NULL, iconDMRef = NULL;
UInt16 dbAttributes;
MemHandle CommandBarIconH, NewCommandBarIconH;
UInt16 CommandBarIconID=0;
UInt16 resID=0;
//Try and use the BugMe Icon by storing it in a separate
resource DB
//that we leave open and with a wierd resource ID
appdbID = DmFindDatabase(0, AppIconDBName);
if (appdbID)
{
err = DmDatabaseInfo(0, appdbID,NULL, &dbAttributes,
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if ( !(dbAttributes & dmHdrAttrOpen) ) //open it and
leave it open if it isnt for some reason
{
iconRsrc = DmOpenDatabaseByTypeCreator (
AppIconDBType, 'EPIc', dmModeReadOnly | dmModeLeaveOpen );
err = DmGetLastErr();
}
//Find out the the Resource ID
iconDMRef = DmOpenDatabaseByTypeCreator (
AppIconDBType, 'EPIc', dmModeReadOnly );
if (iconDMRef)
{
DmResourceInfo(iconDMRef, 0,NULL ,
&CommandBarIconID, NULL) ;
DmCloseDatabase(iconDMRef);
}
if (CommandBarIconID)
CommandBarIconH = DmGetResource ( bitmapRsc,
CommandBarIconID );
else
err = 1; //Force us to create a resource if
we cant find one
if ( !(CommandBarIconH) ) //cant find the icon so
perhaps the db wasnt really open (find this problem after a soft
reset)
{
iconRsrc = DmOpenDatabaseByTypeCreator (
AppIconDBType, 'EPIc', dmModeReadOnly | dmModeLeaveOpen );
err = DmGetLastErr();
}
if (!err)
iconRef = CommandBarIconID;
}
if (!appdbID || err ) //Create it afresh if it doesnt exist -
and leave it open
{
err = DmCreateDatabase(0, AppIconDBName , 'EPIc',
AppIconDBType, true);
if ( !err )
{
//find an unused resource ID starting from
the BarInfoBitmap
while ( DmGetResource ( bitmapRsc,
BarInfoBitmap + resID ) != 0 && (BarInfoBitmap + resID ) <
SecLockBitmap)
{
resID++;
}
iconRsrc = DmOpenDatabaseByTypeCreator (
AppIconDBType, 'EPIc', dmModeReadWrite );
CommandBarIconH = DmGetResource ( bitmapRsc,
BmiconBitmapFamily );
NewCommandBarIconH = DmNewResource (
iconRsrc, bitmapRsc, BarInfoBitmap + resID, MemHandleSize
(CommandBarIconH) );
DmWrite(MemHandleLock(NewCommandBarIconH), 0,
MemHandleLock(CommandBarIconH), MemHandleSize(CommandBarIconH));
MemHandleUnlock(NewCommandBarIconH);
MemHandleUnlock(CommandBarIconH);
DmReleaseResource(NewCommandBarIconH);
DmReleaseResource(CommandBarIconH);
DmCloseDatabase(iconRsrc);
}
iconRsrc = DmOpenDatabaseByTypeCreator (
AppIconDBType, 'EPIc', dmModeReadOnly | dmModeLeaveOpen );
err = DmGetLastErr();
if (!err)
iconRef = BarInfoBitmap + resID;
}
if (iconRef)
bitmapID = iconRef;
else
bitmapID = BarCopyBitmap;
err = MenuCmdBarAddButton (menuCmdBarOnLeft , bitmapID ,
menuCmdBarResultNotify, popMeNotifyEvent, "PopMe!");
return false; //To let others handle this event
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/