In WIN32, the steps to display a bitmap on a window have some complicated
Instead of drawing the image line directly on the window, it is displayed on the window by a memory handle call
To display a bitmap on a form, first move the bitmap into the resource view
load Bitmap resource: Load bitmap in Resource View
static Hbitmap hbitmap; Bitmap handle
static BITMAP BITMAP; Bitmap structure Body
The bitmap structure body is defined as follows:
typedef struct TAGBITMAP
{
LONG bmtype; Bitmap type
long bmwidth;//bitmap
width long bmheight; Bitmap height
LONG bmwidthbytes; Width of the byte
WORD bmplanes;
WORD bmbitspixel;//Pixel
lpvoid bmbits
} BITMAP, *pbitmap, NEAR *npbitmap, FAR *lpbitmap;
Load bitmap: Loading when the window is created
Case Wm_create:
{
hbitmap = LoadBitmap (hinst, Makeintresource (idb_future)); Get bitmap handle
GetObject (hbitmap, sizeof (BITMAP), &bitmap); Pass the bitmap handle to the bitmap structure
//Get the width and height of the bitmap
cxbitmap = bitmap.bmwidth;
Cybitmap = bitmap.bmheight;
} Break
To create a Memory environment device:
bitmaps, like windows, specifically require a handle that holds bitmaps, called Bitmap memory dc
HDC Hdcmem; Bitmap Memory DC
Select a bitmap into a memory DC for drawing on a form
SelectObject (Hdcmem, hbitmap); To select a bitmap into a memory DC
drawing using the BitBlt () function
Copy the bitmap in the memory DC to the window DC display
BITBLT (hdc, MB, Cxbitmap, Cybitmap, hdcmem,0,0,srccopy); Execute in a copy way
Parameter description: HDC is a window handle
200,200 indicates the starting coordinates of the drawn window (that is, from where the window is drawn)
Cxbitmap and Cybitmap are the size of the bitmap,
0,0 represents a coordinate on a bitmap on which the program will start drawing
Srccopy represents performing operations in a copy way
Effect: