I am trying to figure out how to create a brand new bitmap and replace an
existing resource that is on my form.  I know how to delete the existing bitmap
resource and replace it with another bitmap resource but I don't know how to
put a newly created bitmap in that resource.

Here is some test code that I am trying out.

Fred2 creates the bitmap and tries to draw a square.  Fred3 will delete the
existing bitmap resource and replace it with the new bitmap.  When I call
FrmDrawForm it crashes the Palm OS Simulator.  If I remove WinDrawRectangle
then it works but the bitmap is empty and I can't tell if it worked.

Any ideas?

Thanks,

Mike

static void Fred2(void)
{
   BitmapPtr pBitmap;
   WinHandle hWin;
   WinHandle hScreen;
   Err error;

   pBitmap = BmpCreate(30, 30, 8, NULL, &error);
   if(pBitmap) {
      hWin = WinCreateBitmapWindow(pBitmap, &error);
      if(hWin) {
         RectangleType fred = {{0, 0}, {10, 10}};

         hScreen = WinSetDrawWindow(hWin);
         WinSetForeColor(12);
         WinDrawRectangle(&fred, 0); // ??? remove this line and all is well
         WinSetDrawWindow(hScreen);
         WinDeleteWindow(hWin, false);
      }
   }
   Fred3(pBitmap);
   BmpDelete(pBitmap);
}


static void Fred3(BitmapPtr pOldBitmap)
{
   DmOpenRef dbApp;
   UInt16 index;
   MemHandle hRes;
   UInt32 oldBitmapSize;
   MemHandle hNewBitmap;
   BitmapPtr pNewBitmap;

   // open application database
   dbApp = DmOpenDatabaseByTypeCreator(APP_TYPE, APP_ID, dmModeReadWrite);

   // find and delete existing bitmap resource
   hRes = DmGet1Resource(bitmapRsc, bitmapID_colors);
   if(hRes) {
      index = DmFindResource(dbApp, bitmapRsc, bitmapID_colors, hRes);
      DmRemoveResource(dbApp, index);
   }

   // create new bitmap resource
   oldBitmapSize = BmpSize(pOldBitmap);
   hNewBitmap = DmNewResource(dbApp, bitmapRsc, bitmapID_colors,
oldBitmapSize);
   pNewBitmap = MemHandleLock(hNewBitmap);
   DmWrite(pNewBitmap, 0, BmpGetBits(pOldBitmap), oldBitmapSize);
   MemHandleUnlock(hNewBitmap);
   DmReleaseResource(hNewBitmap);

   // close application database
   DmCloseDatabase(dbApp);
}


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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

Reply via email to