2 * Tests various blit and blend operations with different src
3 * bit depths and scaling where possbile.
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
11 BOOL WINAPI
GdiAlphaBlend(
12 HDC hdcDst
, int xDst
, int yDst
, int wDst
, int hDst
,
13 HDC hdcSrc
, int xSrc
, int ySrc
, int wSrc
, int hSrc
,
14 BLENDFUNCTION blendFunction
);
16 BOOL WINAPI
GdiTransparentBlt(
17 HDC hdcDst
, int xDst
, int yDst
, int wDst
, int hDst
,
18 HDC hdcSrc
, int xSrc
, int ySrc
, int wSrc
, int hSrc
,
21 #define CURRENT_BMPS 4
22 #define CURRENT_ICONS 1
27 TCHAR szWindowClass
[] = _T("testclass");
29 static LRESULT CALLBACK
30 WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
32 static HBITMAP hbmList
[CURRENT_BMPS
];
33 static HICON hicList
[CURRENT_ICONS
];
39 hbmList
[0] = (HBITMAP
)LoadImage(hInst
, MAKEINTRESOURCE(100), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
40 hbmList
[1] = (HBITMAP
)LoadImage(hInst
, MAKEINTRESOURCE(400), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
41 hbmList
[2] = (HBITMAP
)LoadImage(hInst
, MAKEINTRESOURCE(800), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
42 hbmList
[3] = (HBITMAP
)LoadImage(hInst
, MAKEINTRESOURCE(2400), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
43 hicList
[0] = (HICON
)LoadIcon(hInst
, MAKEINTRESOURCE(3200));
54 hdc
= BeginPaint(hWnd
, &ps
);
55 hdcMem
= CreateCompatibleDC(hdc
);
57 bfunc
.AlphaFormat
= AC_SRC_ALPHA
;
59 bfunc
.BlendOp
= AC_SRC_OVER
;
60 bfunc
.SourceConstantAlpha
= 128;
63 for(i
= 0; i
< CURRENT_BMPS
; i
++)
66 SelectObject(hdcMem
, hbmList
[i
]);
67 GetObject(hbmList
[i
], sizeof(BITMAP
), &bitmap
);
70 BitBlt(hdc
, x
, y
, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCCOPY
);
71 y
+= bitmap
.bmHeight
+ OFFSET
;
73 /* stretch blt, org size */
74 StretchBlt(hdc
, x
, y
, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, SRCCOPY
);
75 y
+= bitmap
.bmHeight
+ OFFSET
;
77 /* stretch blt, scaled */
78 StretchBlt(hdc
, x
, y
, bitmap
.bmWidth
*SCALE
, bitmap
.bmHeight
*SCALE
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, SRCCOPY
);
79 y
+= bitmap
.bmHeight
*SCALE
+ OFFSET
;
81 /* transparent blt, transparency: grey */
82 GdiTransparentBlt(hdc
, x
, y
, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, 128*256*256+128*256+128);
83 y
+= bitmap
.bmHeight
+ OFFSET
;
85 /* transparent blt, transparency: grey, scaled */
86 GdiTransparentBlt(hdc
, x
, y
, bitmap
.bmWidth
*SCALE
, bitmap
.bmHeight
*SCALE
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, 128*256*256+128*256+128);
87 y
+= bitmap
.bmHeight
*SCALE
+ OFFSET
;
89 /* alpha blend, org size */
90 GdiAlphaBlend(hdc
, x
, y
, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, bfunc
);
91 y
+= bitmap
.bmHeight
+ OFFSET
;
93 /* alpha blend, scaled */
94 GdiAlphaBlend(hdc
, x
, y
, bitmap
.bmWidth
*SCALE
, bitmap
.bmHeight
*SCALE
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, bfunc
);
95 y
+= bitmap
.bmHeight
*SCALE
+ OFFSET
;
97 x
+= bitmap
.bmWidth
*SCALE
+ OFFSET
;
101 for(i
= 0; i
< CURRENT_ICONS
; i
++)
105 DrawIcon(hdc
, x
, y
, hicList
[i
]);
106 y
+= bitmap
.bmHeight
+ OFFSET
;
108 /* normal icon using Ex */
109 DrawIconEx(hdc
, x
, y
, hicList
[i
], 0, 0, 0, NULL
, DI_NORMAL
);
110 y
+= bitmap
.bmHeight
+ OFFSET
;
112 /* normal icon using Ex with bigger size */
113 DrawIconEx(hdc
, x
, y
, hicList
[i
], bitmap
.bmWidth
, bitmap
.bmHeight
, 0, NULL
, DI_NORMAL
);
114 y
+= bitmap
.bmHeight
+ OFFSET
;
116 /* only icon using Ex */
117 DrawIconEx(hdc
, x
, y
, hicList
[i
], 0, 0, 0, NULL
, DI_IMAGE
);
118 y
+= bitmap
.bmHeight
+ OFFSET
;
121 DrawIconEx(hdc
, x
, y
, hicList
[i
], 0, 0, 0, NULL
, DI_MASK
);
122 y
+= bitmap
.bmHeight
+ OFFSET
;
124 x
+= bitmap
.bmWidth
*SCALE
+ OFFSET
;
136 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
143 MyRegisterClass(HINSTANCE hInstance
)
147 wcex
.cbSize
= sizeof(WNDCLASSEX
);
149 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
150 wcex
.lpfnWndProc
= WndProc
;
153 wcex
.hInstance
= hInstance
;
155 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
156 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
157 wcex
.lpszMenuName
= NULL
;
158 wcex
.lpszClassName
= szWindowClass
;
161 return RegisterClassEx(&wcex
);
166 InitInstance(HINSTANCE hInstance
, int nCmdShow
)
172 hWnd
= CreateWindowEx(0,
174 _T("Various blit and blend operations"),
190 ShowWindow(hWnd
, nCmdShow
);
198 _tWinMain(HINSTANCE hInstance
,
199 HINSTANCE hPrevInstance
,
205 MyRegisterClass(hInstance
);
207 if (!InitInstance(hInstance
, nCmdShow
))
212 while (GetMessage(&msg
, NULL
, 0, 0))
214 TranslateMessage(&msg
);
215 DispatchMessage(&msg
);
218 return (int)msg
.wParam
;