ReactOS  0.4.15-dev-1150-g593bcce
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 
12 TCHAR szWindowClass[] = _T("testclass");
13 
14 static 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;
31  BITMAP bitmap;
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);
129  DeleteDC(hdcMem);
130  EndPaint(hWnd, &ps);
131  break;
132  }
133 
134  case WM_DESTROY:
135  PostQuitMessage(0);
136  break;
137  default:
139  }
140  return 0;
141 }
142 
143 
144 static 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;
157  wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
158  wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
159  wcex.lpszMenuName = NULL;
161  wcex.hIconSm = NULL;
162 
163  return RegisterClassEx(&wcex);
164 }
165 
166 
167 static BOOL
169 {
170  HWND hWnd;
171 
172  hInst = hInstance;
173 
174  hWnd = CreateWindowEx(0,
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 
199 int 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 SRCPAINT
Definition: wingdi.h:333
UINT style
Definition: winuser.h:3177
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
Definition: tftpd.h:59
LPCSTR lpszMenuName
Definition: winuser.h:3185
#define PATINVERT
Definition: wingdi.h:327
#define RegisterClassEx
Definition: winuser.h:5812
HBRUSH WINAPI CreateHatchBrush(_In_ int, _In_ COLORREF)
HCURSOR hCursor
Definition: winuser.h:3183
WNDPROC lpfnWndProc
Definition: winuser.h:3178
#define RGB(r, g, b)
Definition: precomp.h:62
LPCSTR lpszClassName
Definition: winuser.h:3186
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
#define NOTSRCERASE
Definition: wingdi.h:323
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define HS_HORIZONTAL
Definition: wingdi.h:579
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WPARAM
Definition: windef.h:207
HICON hIconSm
Definition: winuser.h:3187
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define COLOR_WINDOW
Definition: winuser.h:908
int32_t INT
Definition: typedefs.h:58
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)
WPARAM wParam
Definition: combotst.c:138
#define MERGECOPY
Definition: wingdi.h:331
CHAR * LPTSTR
Definition: xmlstorage.h:192
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Definition: bltrop.c:200
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:977
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
HINSTANCE hInstance
Definition: winuser.h:3181
unsigned int BOOL
Definition: ntddk_ex.h:94
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
HINSTANCE hInst
Definition: bltrop.c:11
#define CreateWindowEx
Definition: winuser.h:5730
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT cbSize
Definition: winuser.h:3176
#define NOTSRCCOPY
Definition: wingdi.h:324
TCHAR szWindowClass[]
Definition: bltrop.c:12
HBRUSH hbrBackground
Definition: winuser.h:3184
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define DSTINVERT
Definition: wingdi.h:326
r l[0]
Definition: byte_order.h:167
Definition: uimain.c:88
#define CS_VREDRAW
Definition: winuser.h:653
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define WINAPI
Definition: msvc.h:6
int cbWndExtra
Definition: winuser.h:3180
#define GetObject
Definition: wingdi.h:4467
#define WM_PAINT
Definition: winuser.h:1602
#define HS_BDIAGONAL
Definition: wingdi.h:575
HICON hIcon
Definition: winuser.h:3182
HDC hdc
Definition: main.c:9
#define WHITENESS
Definition: wingdi.h:336
#define LoadCursor
Definition: winuser.h:5787
#define PATCOPY
Definition: wingdi.h:334
static ATOM MyRegisterClass(HINSTANCE hInstance)
Definition: bltrop.c:145
int cbClsExtra
Definition: winuser.h:3179
#define SRCERASE
Definition: wingdi.h:325
#define BLACKNESS
Definition: wingdi.h:322
BOOL WINAPI DeleteDC(_In_ HDC)
#define HS_FDIAGONAL
Definition: wingdi.h:578
static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: bltrop.c:168
Definition: bl.h:1331
#define HS_CROSS
Definition: wingdi.h:576
#define HS_DIAGCROSS
Definition: wingdi.h:577
#define SRCAND
Definition: wingdi.h:329
unsigned int UINT
Definition: ndis.h:50
#define IMAGE_BITMAP
Definition: winuser.h:211
#define MERGEPAINT
Definition: wingdi.h:330
#define GetMessage
Definition: winuser.h:5765
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define HS_VERTICAL
Definition: wingdi.h:580
#define WM_CREATE
Definition: winuser.h:1590
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
#define LoadImage
Definition: winuser.h:5790
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5694
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: bltrop.c:15
LONG_PTR LRESULT
Definition: windef.h:209
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SRCCOPY
Definition: wingdi.h:332
HDC hdcMem
Definition: welcome.c:104
#define SRCINVERT
Definition: wingdi.h:328
static VOID NTAPI 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:49
#define PATPAINT
Definition: wingdi.h:335