[SHLWAPI_APITEST]
[reactos.git] / rostests / dibtests / icontest / icontest.c
1 #include <windows.h>
2 #include "resource.h"
3 #include <string.h>
4 #include <stdio.h>
5
6 ULONG __cdecl DbgPrint(IN PCH Format, IN ...);
7
8 const char titleDrwIco[] = "DrawIcon Output";
9 const char titleMask[] = "Mask(AND image)";
10 const char titleXor[] = "XOR(color image)";
11 const char file[] = "Icon from file:";
12 const char res[] = "Icon from Resource:";
13 const char cursor[] = "Current Cursor:";
14 const char cursormask[] = "Cursor Mask Bitmap";
15 const char cursorcolor[] = "Cursor Color Bitmap";
16
17 HFONT tf;
18 HINSTANCE hInst;
19
20 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
21
22 int WINAPI
23 WinMain(HINSTANCE hInstance,
24 HINSTANCE hPrevInstance,
25 LPSTR lpszCmdLine,
26 int nCmdShow)
27 {
28 WNDCLASS wc;
29 MSG msg;
30 HWND hWnd;
31
32 hInst = hInstance;
33
34 #ifdef _GetCursorInfo
35 GetCursorInfo = (GETCURSORINFO)GetProcAddress(GetModuleHandleW(L"user32.dll"), "GetCursorInfo");
36 #endif
37
38 wc.lpszClassName = "IconTestClass";
39 wc.lpfnWndProc = MainWndProc;
40 wc.style = CS_VREDRAW | CS_HREDRAW;
41 wc.hInstance = hInstance;
42 wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
43 wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
44 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
45 wc.lpszMenuName = NULL;
46 wc.cbClsExtra = 0;
47 wc.cbWndExtra = 0;
48 if (RegisterClass(&wc) == 0)
49 {
50 DbgPrint("RegisterClass failed (last error 0x%X)\n", GetLastError());
51 return(1);
52 }
53
54 hWnd = CreateWindow("IconTestClass",
55 "Icon Test",
56 WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
57 CW_USEDEFAULT,
58 CW_USEDEFAULT,
59 480,
60 480,
61 NULL,
62 NULL,
63 hInstance,
64 NULL);
65 if (hWnd == NULL)
66 {
67 DbgPrint("CreateWindow failed (last error 0x%X)\n", GetLastError());
68 return(1);
69 }
70
71 tf = CreateFontA(14,0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
72 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
73 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
74
75 ShowWindow(hWnd, nCmdShow);
76
77 SetTimer(hWnd, 1, 1000, NULL);
78
79 while(GetMessage(&msg, NULL, 0, 0))
80 {
81 TranslateMessage(&msg);
82 DispatchMessage(&msg);
83 }
84
85 return msg.wParam;
86 }
87
88 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
89 {
90 PAINTSTRUCT ps;
91 HDC hDC;
92 HICON hIcon;
93 HGDIOBJ hOld;
94 HDC hMemDC;
95 CURSORINFO cursorinfo;
96 ICONINFO iconinfo;
97 BITMAP bmp;
98 RECT rc;
99 CHAR str[20];
100
101 switch(msg)
102 {
103 case WM_PAINT:
104 hDC = BeginPaint(hWnd, &ps);
105 SelectObject(hDC, tf);
106 SetBkMode(hDC, TRANSPARENT);
107
108 TextOut(hDC, 160, 10, file, strlen(file));
109 TextOut(hDC, 15, 85, titleDrwIco, strlen(titleDrwIco));
110 TextOut(hDC, 160, 85, titleMask, strlen(titleMask));
111 TextOut(hDC, 300, 85, titleXor, strlen(titleXor));
112
113 hIcon = LoadImage(NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
114 DrawIcon(hDC,50,50,hIcon);
115
116 hMemDC = CreateCompatibleDC(hDC);
117 GetIconInfo(hIcon, &iconinfo);
118 DestroyIcon(hIcon);
119
120 hOld = SelectObject(hMemDC, iconinfo.hbmMask);
121 BitBlt(hDC, 200, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
122 SelectObject(hMemDC, iconinfo.hbmColor);
123 BitBlt(hDC, 350, 50, 32, 32, hMemDC, 0, 0, SRCCOPY);
124
125 DeleteObject(iconinfo.hbmMask);
126 DeleteObject(iconinfo.hbmColor);
127
128 TextOut(hDC, 145, 150, res, strlen(res));
129 TextOut(hDC, 15, 225, titleDrwIco, strlen(titleDrwIco));
130 TextOut(hDC, 160, 225, titleMask, strlen(titleMask));
131 TextOut(hDC, 300, 225, titleXor, strlen(titleXor));
132
133 hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
134 DrawIcon(hDC,50,190,hIcon);
135
136 GetIconInfo(hIcon, &iconinfo);
137 DestroyIcon(hIcon);
138
139 SelectObject(hMemDC, iconinfo.hbmMask);
140 BitBlt(hDC, 200, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
141 SelectObject(hMemDC, iconinfo.hbmColor);
142 BitBlt(hDC, 350, 190, 32, 32, hMemDC, 0, 0, SRCCOPY);
143
144 DeleteObject(iconinfo.hbmMask);
145 DeleteObject(iconinfo.hbmColor);
146
147 cursorinfo.cbSize = sizeof(CURSORINFO);
148 if(GetCursorInfo(&cursorinfo))
149 {
150 if(cursorinfo.hCursor && cursorinfo.flags)
151 {
152 TextOut(hDC, 160, 290, cursor, strlen(cursor));
153 DrawIcon(hDC, 50, 330, cursorinfo.hCursor);
154 GetIconInfo(cursorinfo.hCursor, &iconinfo);
155 TextOut(hDC, 15, 365, titleDrwIco, strlen(titleDrwIco));
156
157 sprintf(str, "Hotspot: %ld; %ld", iconinfo.xHotspot, iconinfo.yHotspot);
158 TextOut(hDC, 15, 380, str, strlen(str));
159
160 if(iconinfo.hbmMask)
161 {
162 GetObjectW(iconinfo.hbmMask, sizeof(BITMAP), &bmp);
163 SelectObject(hMemDC, iconinfo.hbmMask);
164 BitBlt(hDC, 200, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
165 DeleteObject(iconinfo.hbmMask);
166 TextOut(hDC, 160, 365 - 32 + bmp.bmHeight, cursormask, strlen(cursormask));
167
168 sprintf(str, "%dBPP", bmp.bmBitsPixel);
169 TextOut(hDC, 160, 380 - 32 + bmp.bmHeight, str, strlen(str));
170 }
171
172 if(iconinfo.hbmColor)
173 {
174 GetObjectW(iconinfo.hbmColor, sizeof(BITMAP), &bmp);
175 SelectObject(hMemDC, iconinfo.hbmColor);
176 BitBlt(hDC, 350, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
177 DeleteObject(iconinfo.hbmColor);
178 TextOut(hDC, 300, 365 - 32 + bmp.bmHeight, cursorcolor, strlen(cursorcolor));
179
180 sprintf(str, "%dBPP", bmp.bmBitsPixel);
181 TextOut(hDC, 300, 380 - 32 + bmp.bmHeight, str, strlen(str));
182 }
183 }
184 }
185
186 SelectObject(hMemDC, hOld);
187
188 DeleteObject(hMemDC);
189 EndPaint(hWnd, &ps);
190 break;
191
192 case WM_TIMER:
193 rc.left = 0;
194 rc.top = 330;
195 rc.right = 480;
196 rc.bottom = 480;
197 InvalidateRect(hWnd, &rc, TRUE);
198 break;
199
200 case WM_DESTROY:
201 PostQuitMessage(0);
202 break;
203
204 default:
205 return DefWindowProc(hWnd, msg, wParam, lParam);
206 }
207 return 0;
208 }