🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2240

Bitmap GetObject

#2240
From: 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
Technical Details
Message-ID: <4613f4bc@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cc67b7c92694fec8,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "poojo hackma" <poojo.com/mail>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Bitmap GetObject
Date: Wed, 4 Apr 2007 13:55:56 -0500
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-RFC2646: Format=Flowed; Original
X-Antivirus: avast! (VPS 000730-3, 04/04/2007), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 12.191.89.68
Message-ID: <4613f4bc@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1175712956 12.191.89.68 (4 Apr 2007 11:55:56 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail