I. bitblt
Copy a bitmap from one device scenario to another, that is, copy pixels. The first parameter is the target, and the latter is the source.
CaseWm_paint: hdcclient = beginpaint (hwnd, & PS); hdcwindow = getwindowdc (hwnd );For(Y = 0; y <cyclient; y + = cysource)For(X = 0; x <cxclient; x + = cxsource) {bitblt (hdcclient, X, Y, cxsource, cysource, hdcwindow, 0, 0, srccopy );} releasedc (hwnd, hdcwindow); endpaint (hwnd, & PS );Return0;
2. Stretch the bitmap (making the image unclear)
The stretchblt function has two more parameters than bitblt.
CaseWm_paint: hdcclient = beginpaint (hwnd, & PS); hdcwindow = getwindowdc (hwnd); stretchblt (hdcclient, 0, 0, cxclient, cyclient, hdcwindow, 0, 0, cxsource, cysource, mergecopy); releasedc (hwnd, hdcwindow); endpaint (hwnd, & PS );Return0;
3. Create a bitmap
3.1
Hbitmap = createcompatiblebitmap (HDC, CX, CY );// This function creates a device-compatible bitmap.
Hbitmap createbitmapindirect (& Bitmap );// Create a struct
- Load bitmap first
- Create createcompatibledc
- Bitblt copying pixels
Switch (Message ){ Case Wm_create: hinstance = (lpcreatestruct) lparam)-> hinstance; hbitmap = loadbitmap (hinstance, text ( "Bricks" ); GetObject (hbitmap, Sizeof (Bitmap), & Bitmap); cxsource = bitmap. bmwidth; cysource = bitmap. bmheight; Return 0; Case Wm_size: cxclient = loword (lparam); cyclient = hiword (lparam ); Return 0; Case Wm_paint: HDC = beginpaint (hwnd, & PS); hdcmem = createcompatibledc (HDC); SelectObject (hdcmem, hbitmap ); For (Y = 0; y <cyclient; y + = cysource)For (X = 0; x <cxclient; x + = cxsource) {bitblt (HDC, X, Y, cxsource, cysource, hdcmem, 0, 0, srccopy );} deletedc (hdcmem); endpaint (hwnd, & PS ); Return 0; Case Wm_destroy: deleteobject (hbitmap); postquitmessage (0 ); Return 0 ;}3.2 use bitmap to create a text, represented by 0 and 1, which is equivalent to the meaning of the pixel.
Fill in the bmbits field of Bitmap
StaticBitmap bitmap = {0, 8, 8, 2, 1, 1 };StaticByte bits [8] [2] = {0xff, 0, 0x0c, 0, 0x0c, 0, 0x0c, 0, 0xff, 0, 0xc0, 0, 0xc0, 0, 0xc0, 0 };StaticHbitmap;Static intCxclient, cyclient, cxsource, cysource; HDC, hdcmem;IntX, Y; paintstruct pS;Switch(Message ){CaseWm_create: bitmap. bmbits = bits; hbitmap = createbitmapindirect (& Bitmap); cxsource = bitmap. bmwidth; cysource = bitmap. bmheight;Return0;
3.3 Use bitmap to create a brush
Hbitmap = loadbitmap (hinstance, text ("Bricks"); Hbrush = createpatternbrush (hbitmap); deleteobject (hbitmap );
3.4 plotting in the in-place Graph
Use createcompatiblebitmap to create a bitmap related to device compatibility, and then select the bitmap, SelectObject (hdcmem, hbitmap)
HDC = getdc (hwnd); hdcmem = createcompatibledc (HDC); gettextextentpoint32 (HDC, sztext, lstrlen (sztext), & size); cxbitmap = size. CX; cybitmap = size. cy; hbitmap = createcompatiblebitmap (HDC, cxbitmap, cybitmap); releasedc (hwnd, HDC); SelectObject (hdcmem, hbitmap); textout (hdcmem, 0, 0, sztext, lstrlen (sztext ));
After creation, you can use bitblt or stretchblt to operate pixels in the same method as above.
Iv. Menu insert bitmap
hbitmap = stretchbitmap (loadbitmap (hinstance, text ( "bitmapfont" ))); appendmenu (hmenu, mf_bitmap | mf_popup, ( int ) hmenupopup, (ptstr) (long) hbitmap);