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