2 * Shows the 15 well known BitBlt raster operations
3 * using src, dest, pattern, a background brush and color.
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
12 TCHAR szWindowClass
[] = _T("testclass");
14 static LRESULT CALLBACK
15 WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
17 static HBITMAP hBmpTest
;
23 hBmpTest
= (HBITMAP
)LoadImage(hInst
, MAKEINTRESOURCE(100), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
34 hdc
= BeginPaint(hWnd
, &ps
);
35 hdcMem
= CreateCompatibleDC(hdc
);
37 GetObject(hBmpTest
, sizeof(BITMAP
), &bitmap
);
39 /* fill destination with brush */
40 brush
= CreateHatchBrush(HS_DIAGCROSS
, RGB(255,0,0));
41 SelectObject(hdc
, brush
);
42 PatBlt(hdc
, 0, 0, 4*bitmap
.bmWidth
, 4*bitmap
.bmHeight
, PATCOPY
);
43 /* set up a second brush */
44 brush2
= CreateHatchBrush(HS_VERTICAL
, RGB(127,127,127));
46 /* first select brush, then set bk color */
47 SelectObject(hdc
, brush2
);
48 SetBkColor(hdc
, RGB(0, 255, 0));
51 SelectObject(hdcMem
, hBmpTest
);
52 BitBlt(hdc
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCCOPY
);
53 BitBlt(hdc
, 100, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, DSTINVERT
);
54 BitBlt(hdc
, 200, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, MERGECOPY
);
55 BitBlt(hdc
, 300, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, MERGEPAINT
);
57 BitBlt(hdc
, 0, 100, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, NOTSRCCOPY
);
58 BitBlt(hdc
, 100, 100, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, NOTSRCERASE
);
59 BitBlt(hdc
, 200, 100, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, PATCOPY
);
60 BitBlt(hdc
, 300, 100, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, PATINVERT
);
62 BitBlt(hdc
, 0, 200, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, PATPAINT
);
63 BitBlt(hdc
, 100, 200, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCAND
);
64 BitBlt(hdc
, 200, 200, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCERASE
);
65 BitBlt(hdc
, 300, 200, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCINVERT
);
67 BitBlt(hdc
, 0, 300, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, BLACKNESS
);
68 BitBlt(hdc
, 100, 300, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCPAINT
);
69 BitBlt(hdc
, 200, 300, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, WHITENESS
);
80 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
87 MyRegisterClass(HINSTANCE hInstance
)
91 wcex
.cbSize
= sizeof(WNDCLASSEX
);
93 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
94 wcex
.lpfnWndProc
= WndProc
;
97 wcex
.hInstance
= hInstance
;
99 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
100 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
101 wcex
.lpszMenuName
= NULL
;
102 wcex
.lpszClassName
= szWindowClass
;
105 return RegisterClassEx(&wcex
);
110 InitInstance(HINSTANCE hInstance
, int nCmdShow
)
116 hWnd
= CreateWindowEx(0,
118 _T("BitBlt raster operation test"),
134 ShowWindow(hWnd
, nCmdShow
);
142 _tWinMain(HINSTANCE hInstance
,
143 HINSTANCE hPrevInstance
,
149 MyRegisterClass(hInstance
);
151 if (!InitInstance(hInstance
, nCmdShow
))
156 while (GetMessage(&msg
, NULL
, 0, 0))
158 TranslateMessage(&msg
);
159 DispatchMessage(&msg
);
162 return (int)msg
.wParam
;