Display a bitmap, basic has the following three forms:
I. Display of bitmap resources (set the resources ID to IDB - Bitmap1 program as follows)
{
CBitmap Bitmap;
CBITMAP * POLDBITMAP;
CDC MEMDC;
Memdc.createCompatibleDC (& DC); // / Establishing a memory device farming with display device compatible
Bitmap.LoadBitmap (idb_bitmap1); /// Remove the bitmap resources
PoldbitMap = MEMDC.SelectObject (& Bitmap); /// select the bitmap to the memory site
DC.Bitblt (50, 50, 48, 48, & memdc, 0, 0, srcopy); /// shows it
MEMDC.SELECTOBJECT (POLDBITMAP);
}
Second, create a bitmap, then draw a graphic inside, then display it
{
CBitmap Bitmap;
CBITMAP * POLDBITMAP;
CDC MEMDC;
INT I;
CPEN Pen;
CPEN * Oldpen;
Memdc.createCompatibleDC (& DC); // / Establishing a memory device farming with display device compatible
Bitmap.createCompaPaTmap (& DC, 100, 100); //// Establishing a bitmap compatible with display device
PoldbitMap = MEMDC.SelectObject (& Bitmap); /// select the bitmap to the memory site
For (i = 0; i <100; i )
{/// draw 100 wire
Pen.createpen (PS_SOLID, 1, RGB (0, 0, I * 2 55);
Oldpen = MEMDC.SELECTOBJECT (& PEN);
MEMDC.MOVETO (0, i);
MEMDC.LINETO (100, i);
MEMDC.SELECTOBJECT (OLDPEN);
Pen.deleteObject ();
}
DC.Bitblt (50, 50, 100, 100, & memdc, 0, 0, srcopy); /// shows it
MEMDC.SELECTOBJECT (POLDBITMAP);
}
Third, display the external BMP file on disk
{
Hbitmap bitmap;
/ Read bitmap file Sample.BMP
Bitmap = (Hbitmap) loadImage (AfxGetInstanceHandle (), "Sample.BMP", Image_bitmap, 0, 0, Lr_LoadFromFile | LR_CREATEDIBSECTION;
ASSERT (Bitmap);
Hbitmap oldbitmap;
CDC MEMDC; CRECT RECT;
Memdc.createCompatibleDC (& DC);
GetClientRect (Rect);
Oldbitmap = (hbitmap) MEMDC.SELECTOBJECT (Bitmap);
/// shows it
DC.Bitblt (20, 20, Rect.width () - 20, Rect.height () - 20, & MEMDC, 0, 0, SRCCOPY;
MEMDC.SELECTOBJECT (OLDBITMAP);
}