
I am trying to display a bitmap
CMainView::OnDraw(CDC* pDC)
{
// Load the bitmap
CBitmap TempBitmap; TempBitmap.LoadBitmap(IDR_CHARIMAGE);
// Create a mem DC.
CDC dc; dc.CreateCompatibleDC(pDC);
// Select the bitmap into the mem dc.
CBitmap* pOldBitmap = dc.SelectObject(&TempBitmap);
// Copy the bitmap to the view.
pDC->StretchBlt(<x pos in view>, <y pos in view>, <width in view>, <height
in view>,
&dc, 0, 0, <original width>, <original height>, SRCCOPY);
// Select the old bitmap back into the mem dc (so no resource leak occurs).
dc.SelectObject(pOldBitmap);
Quote:
}
If you are working with 256-color bitmaps, and you're not running in true color
mode, then this won't work like you want, because it isn't doing palette stuff.
Look at the DIBLOOK sample that comes with VC for samples of how to do that, if
you want. Hope this helps - Doug S.
Quote:
> I have tried and tried and I can not get a bitmap to display on the screen.
> CAn You show me a better way?
> Thank you.
> HBITMAP aBMap;
> HBITMAP bBMap;
> HBITMAP holdbm;
> HBITMAP hnewbm;
> HDC hmemorydcNew;
> HDC hmemorydcOld;
> HDC hdc;
> // CDC* adc;
> // HBITMAP m_hbmpPodium;
> // HBITMAP m_hbmpScreen;
> // HBITMAP m_hbmpDoor;
> // HBITMAP m_hbmpDisplay;
> // HBITMAP m_hbmpChair;
> // HBITMAP m_hbmpAisle;
> // adc=GetDC();
> hdc=context->m_hDC;
> hmemorydcNew=CreateCompatibleDC(hdc);
> hmemorydcOld=CreateCompatibleDC(hdc);
> bBMap=CreateCompatibleBitmap(hdc,100,100);
> aBMap=(HBITMAP)::LoadBitmap(myInstance,"res\\wallindexi.bmp");
> holdbm=(HBITMAP)SelectObject(hmemorydcNew, bBMap);
> hnewbm=(HBITMAP)SelectObject(hmemorydcOld, aBMap);
> StretchBlt(hmemorydcNew,0,0,100,100,hmemorydcOld,0,0,32,32,SRCCOPY);
> SelectObject(hmemorydcNew,holdbm);
> SelectObject(hmemorydcOld,hnewbm);
> DeleteDC(hmemorydcNew);
> DeleteDC(hmemorydcOld);