#include <stdio.h> #include <Windows.h>
int main(void) { BITMAPINFOHEADER infoheader; HBITMAP hbmp; HDC hdc, hdcMem; PBYTE pBits; // 用于接收系统为位图分配的内存地址
hdc = GetDC(NULL); hdcMem = CreateCompatibleDC(hdc);
ZeroMemory(&infoheader, sizeof(infoheader)); infoheader.biSize = sizeof(infoheader); infoheader.biBitCount = 24; infoheader.biPlanes = 1; infoheader.biWidth = 100; infoheader.biHeight = 50;
hbmp = CreateDIBSection(hdc, (BITMAPINFO *)&infoheader, DIB_RGB_COLORS, (LPVOID *)&pBits, NULL, (DWORD)NULL); SelectObject(hdcMem, hbmp); // 可将创建的位图选入内存DC
memset(pBits, 0xee, 300); memset(pBits + 300, 0x99, 300);
SelectObject(hdcMem, GetStockObject(WHITE_BRUSH)); Rectangle(hdcMem, 10, 10, 40, 20);
BitBlt(hdc, 10, 10, infoheader.biWidth, infoheader.biHeight, hdcMem, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdc); DeleteDC(hdcMem); DeleteObject(hbmp); return 0; }
|