🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by poojo hackma Wed, 04 Apr 2007 18:55
Bitmap GetObject
#2240
Author: poojo hackma
Date: Wed, 04 Apr 2007 18:55
69 lines
3269 bytes
First, I must say that this is being done in eMbedded VC 4.0 for a Pocket 
PC, not in Borland; however, the techniques should be the same for native 
API usage, so I wanted to post the question here.

It has taken me a little time, but I have narrowed my problem down to 
CBitmap::GetObject.

My application loads many images. The frequently used ones have been 
converted to bitmaps and are loaded as resources, but the rest are still in 
JPEG format on the device's Compact Flash storage card.

To load a JPEG, I use SHLoadImageFile from the Pocket PC SDK. To load a 
resource bitmap, I use the LoadBitmap API (see code below).

The problem comes when I attempt to call GetObject on a jpeg file. The image 
displays correctly, but parts of my program get overwritten whenever it 
happens. (Currently, CStringList files is being overwritten, but if the 
declaration order gets changed around somewhat, it will go to something 
else.)

Could someone look at my use of GetObject and tell me what I am doing wrong? 
Could you suggest a way to fix it?

void CForm1Dlg::OnPaint()
{
  CBitmap bitmap, *pOldbmp;
  CPaintDC dc(this);
  BITMAP BMP;
  CDC mDC;
  DWORD ok;
  HBITMAP hBMP;
  if (bImageIsJpegFile)
    hBMP = SHLoadImageFile(szImageFile);
  else
    hBMP = LoadBitmap(AfxGetApp()->m_hInstance,
           MAKEINTRESOURCE(IDB_IMAGE2));
  if (hBMP == NULL)
    return;
  ok = bitmap.Attach(hBMP);
  if (!ok)
    return;
  // Help says if I pass NULL as param2, GetObject returns the
  // size needed to allocate for the bitmap object:
  ok = bitmap.GetObject(sizeof(BITMAP), NULL);
  // problem is, GetObject above always returns ok=84.
  // Any idea what that would mean?
  if (!ok)
    return;
  // In the GetObject below, if hBMP is to a JPEG file,
  // other areas of my application get overwritten.
  // Does anyone know why?
  ok = bitmap.GetObject(ok, &BMP);
  // CStringList files was 56, now it is 0.
  if (!ok)
    return;
  mDC.CreateCompatibleDC(&dc);
  pOldbmp = mDC.SelectObject(&bitmap);
  if (pOldbmp != NULL)
  {
    dc.StretchBlt(r.left, r.top, r.Width(), r.Height(), &mDC,
                  0, 0, BMP.bmWidth, BMP.bmHeight, SRCCOPY);
    mDC.SelectObject(pOldbmp);
    mDC.DeleteDC();
  }
  mDC.ReleaseAttribDC();
}

Thanks in advance!
~Joe
Re: Bitmap GetObject
#2241
Author: Thomas Maeder [TeamB]
Date: Wed, 04 Apr 2007 19:40
5 lines
1074 bytes
"poojo hackma" <poojo.com/mail> writes:

>   CBitmap bitmap, *pOldbmp;

What's CBitmap?
Re: Bitmap GetObject
#2242
Author: poojo hackma
Date: Wed, 04 Apr 2007 19:59
11 lines
1242 bytes
CBitmap is an MFC bitmap class that "encapsulates the functionality of a 
Windows CE graphics device interface (GDI) bitmap."

I suppose if no one here knows what a CBitmap is, I'm not going to be able 
to get much help.

Thanks anyway.

"Thomas Maeder [TeamB]" wrote:
>
> What's CBitmap? 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads