#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;
}