ReactOS 0.4.15-dev-7942-gd23573b
bltrop.c
Go to the documentation of this file.
1/*
2 * Shows the 15 well known BitBlt raster operations
3 * using src, dest, pattern, a background brush and color.
4 *
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
6*/
7
8#include <windows.h>
9#include <tchar.h>
10
12TCHAR szWindowClass[] = _T("testclass");
13
14static LRESULT CALLBACK
16{
17 static HBITMAP hBmpTest;
18
19 switch (message)
20 {
21 case WM_CREATE:
22 {
24 break;
25 }
26
27 case WM_PAINT:
28 {
29 PAINTSTRUCT ps;
30 HDC hdc, hdcMem;
32 HBRUSH brush, brush2;
33 INT l;
34
35 hdc = BeginPaint(hWnd, &ps);
37
38 GetObject(hBmpTest, sizeof(BITMAP), &bitmap);
39
40 /* fill destination with brush */
41 brush = CreateHatchBrush(HS_DIAGCROSS, RGB(255,0,0));
42 SelectObject(hdc, brush);
43 PatBlt(hdc, 30, 0, 4*bitmap.bmWidth*2, 4*bitmap.bmHeight, PATCOPY);
44
45 /* hatched brushes */
46 l = 66;
47 brush = CreateHatchBrush(HS_DIAGCROSS, RGB(255,0,0));
48 SelectObject(hdc, brush);
49 PatBlt(hdc, 0, 0, 30, l, PATCOPY);
50 DeleteObject(brush);
51
52 brush = CreateHatchBrush(HS_CROSS, RGB(255,0,0));
53 SelectObject(hdc, brush);
54 PatBlt(hdc, 0, 1*l, 30, l, PATCOPY);
55 DeleteObject(brush);
56
57 brush = CreateHatchBrush(HS_FDIAGONAL, RGB(255,0,0));
58 SelectObject(hdc, brush);
59 PatBlt(hdc, 0, 2*l, 30, l, PATCOPY);
60 DeleteObject(brush);
61
62 brush = CreateHatchBrush(HS_BDIAGONAL, RGB(255,0,0));
63 SelectObject(hdc, brush);
64 PatBlt(hdc, 0, 3*l, 30, l, PATCOPY);
65 DeleteObject(brush);
66
67 brush = CreateHatchBrush(HS_VERTICAL, RGB(255,0,0));
68 SelectObject(hdc, brush);
69 PatBlt(hdc, 0, 4*l, 30, l, PATCOPY);
70 DeleteObject(brush);
71
72 brush = CreateHatchBrush(HS_HORIZONTAL, RGB(255,0,0));
73 SelectObject(hdc, brush);
74 PatBlt(hdc, 0, 5*l, 30, l, PATCOPY);
75 DeleteObject(brush);
76
77 /* set up a second brush */
78 brush2 = CreateHatchBrush(HS_VERTICAL, RGB(127,127,127));
79
80 /* first select brush, then set bk color */
81 SelectObject(hdc, brush2);
82 SetBkColor(hdc, RGB(0, 255, 0));
83
84 /* 15 blt op's with bitblt */
85 SelectObject(hdcMem, hBmpTest);
86 /* offset coordinates */
87 SetWindowOrgEx(hdc, -10, -10, NULL);
88 BitBlt(hdc, 30, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
89 BitBlt(hdc, 130, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, DSTINVERT);
90 BitBlt(hdc, 230, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGECOPY);
91 BitBlt(hdc, 330, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGEPAINT);
92
93 BitBlt(hdc, 30, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCCOPY);
94 BitBlt(hdc, 130, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCERASE);
95 BitBlt(hdc, 230, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATCOPY);
96 BitBlt(hdc, 330, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATINVERT);
97
98 BitBlt(hdc, 30, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATPAINT);
99 BitBlt(hdc, 130, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCAND);
100 BitBlt(hdc, 230, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCERASE);
101 BitBlt(hdc, 330, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCINVERT);
102
103 BitBlt(hdc, 30, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, BLACKNESS);
104 BitBlt(hdc, 130, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCPAINT);
105 BitBlt(hdc, 230, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, WHITENESS);
106
107 /* 15 blt op's with stretchblt */
108 StretchBlt(hdc, 30+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
109 StretchBlt(hdc, 130+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, DSTINVERT);
110 StretchBlt(hdc, 230+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGECOPY);
111 StretchBlt(hdc, 330+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGEPAINT);
112
113 StretchBlt(hdc, 30+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NOTSRCCOPY);
114 StretchBlt(hdc, 130+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NOTSRCERASE);
115 StretchBlt(hdc, 230+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATCOPY);
116 StretchBlt(hdc, 330+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATINVERT);
117
118 StretchBlt(hdc, 30+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATPAINT);
119 StretchBlt(hdc, 130+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCAND);
120 StretchBlt(hdc, 230+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCERASE);
121 StretchBlt(hdc, 330+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCINVERT);
122
123 StretchBlt(hdc, 30+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, BLACKNESS);
124 StretchBlt(hdc, 130+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCPAINT);
125 StretchBlt(hdc, 230+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, WHITENESS);
126
127 DeleteObject(brush);
128 DeleteObject(brush2);
130 EndPaint(hWnd, &ps);
131 break;
132 }
133
134 case WM_DESTROY:
136 break;
137 default:
139 }
140 return 0;
141}
142
143
144static ATOM
146{
147 WNDCLASSEX wcex;
148
149 wcex.cbSize = sizeof(WNDCLASSEX);
150
151 wcex.style = CS_HREDRAW | CS_VREDRAW;
152 wcex.lpfnWndProc = WndProc;
153 wcex.cbClsExtra = 0;
154 wcex.cbWndExtra = 0;
155 wcex.hInstance = hInstance;
156 wcex.hIcon = NULL;
158 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
159 wcex.lpszMenuName = NULL;
161 wcex.hIconSm = NULL;
162
163 return RegisterClassEx(&wcex);
164}
165
166
167static BOOL
169{
170 HWND hWnd;
171
173
176 _T("BitBlt raster operation test"),
180 840,
181 440,
182 NULL,
183 NULL,
184 hInstance,
185 NULL);
186
187 if (!hWnd)
188 {
189 return FALSE;
190 }
191
192 ShowWindow(hWnd, nCmdShow);
194
195 return TRUE;
196}
197
198
199int WINAPI
201 HINSTANCE hPrevInstance,
202 LPTSTR lpCmdLine,
203 int nCmdShow)
204{
205 MSG msg;
206
208
209 if (!InitInstance(hInstance, nCmdShow))
210 {
211 return FALSE;
212 }
213
214 while (GetMessage(&msg, NULL, 0, 0))
215 {
218 }
219
220 return (int)msg.wParam;
221}
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
TCHAR szWindowClass[]
Definition: bltrop.c:12
HINSTANCE hInst
Definition: bltrop.c:11
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: bltrop.c:15
static ATOM MyRegisterClass(HINSTANCE hInstance)
Definition: bltrop.c:145
static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: bltrop.c:168
r l[0]
Definition: byte_order.h:168
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
#define RGB(r, g, b)
Definition: precomp.h:71
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
#define _tWinMain
Definition: tchar.h:498
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
unsigned int UINT
Definition: ndis.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define DefWindowProc
Definition: ros2win.h:31
Definition: bl.h:1331
int cbClsExtra
Definition: winuser.h:3204
HINSTANCE hInstance
Definition: winuser.h:3206
HCURSOR hCursor
Definition: winuser.h:3208
LPCSTR lpszMenuName
Definition: winuser.h:3210
HICON hIconSm
Definition: winuser.h:3212
UINT style
Definition: winuser.h:3202
int cbWndExtra
Definition: winuser.h:3205
UINT cbSize
Definition: winuser.h:3201
WNDPROC lpfnWndProc
Definition: winuser.h:3203
LPCSTR lpszClassName
Definition: winuser.h:3211
HICON hIcon
Definition: winuser.h:3207
HBRUSH hbrBackground
Definition: winuser.h:3209
Definition: uimain.c:89
Definition: tftpd.h:60
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
HDC hdcMem
Definition: welcome.c:104
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define BLACKNESS
Definition: wingdi.h:323
#define PATPAINT
Definition: wingdi.h:336
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:999
#define PATINVERT
Definition: wingdi.h:328
#define HS_DIAGCROSS
Definition: wingdi.h:578
#define WHITENESS
Definition: wingdi.h:337
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
HBRUSH WINAPI CreateHatchBrush(_In_ int, _In_ COLORREF)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCERASE
Definition: wingdi.h:326
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define HS_CROSS
Definition: wingdi.h:577
#define SRCINVERT
Definition: wingdi.h:329
#define SRCCOPY
Definition: wingdi.h:333
#define PATCOPY
Definition: wingdi.h:335
#define DSTINVERT
Definition: wingdi.h:327
#define HS_VERTICAL
Definition: wingdi.h:581
#define SRCPAINT
Definition: wingdi.h:334
#define HS_FDIAGONAL
Definition: wingdi.h:579
#define MERGEPAINT
Definition: wingdi.h:331
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define MERGECOPY
Definition: wingdi.h:332
#define NOTSRCCOPY
Definition: wingdi.h:325
#define HS_BDIAGONAL
Definition: wingdi.h:576
#define HS_HORIZONTAL
Definition: wingdi.h:580
#define GetObject
Definition: wingdi.h:4468
BOOL WINAPI DeleteDC(_In_ HDC)
#define NOTSRCERASE
Definition: wingdi.h:324
#define SRCAND
Definition: wingdi.h:330
#define WM_PAINT
Definition: winuser.h:1620
#define CS_VREDRAW
Definition: winuser.h:658
#define CreateWindowEx
Definition: winuser.h:5755
#define IMAGE_BITMAP
Definition: winuser.h:211
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:918
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define GetMessage
Definition: winuser.h:5790
#define RegisterClassEx
Definition: winuser.h:5837
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5719
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5815
#define LR_DEFAULTCOLOR
Definition: winuser.h:1087
#define WM_DESTROY
Definition: winuser.h:1609
#define DispatchMessage
Definition: winuser.h:5765
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192