[USER32_WINETEST]
[reactos.git] / rostests / winetests / user32 / cursoricon.c
1 /*
2 * Unit test suite for cursors and icons.
3 *
4 * Copyright 2006 Michael Kaufmann
5 * Copyright 2007 Dmitry Timoshkov
6 * Copyright 2007-2008 Andrew Riedi
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "wine/test.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33
34 #include "pshpack1.h"
35
36 typedef struct
37 {
38 BYTE bWidth;
39 BYTE bHeight;
40 BYTE bColorCount;
41 BYTE bReserved;
42 WORD xHotspot;
43 WORD yHotspot;
44 DWORD dwDIBSize;
45 DWORD dwDIBOffset;
46 } CURSORICONFILEDIRENTRY;
47
48 typedef struct
49 {
50 WORD idReserved;
51 WORD idType;
52 WORD idCount;
53 CURSORICONFILEDIRENTRY idEntries[1];
54 } CURSORICONFILEDIR;
55
56 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
57 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
58 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
59
60 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
61 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
62 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
63 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
64 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
65 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
66 #define ANI_icon_ID RIFF_FOURCC('i', 'c', 'o', 'n')
67 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
68
69 #define ANI_FLAG_ICON 0x1
70 #define ANI_FLAG_SEQUENCE 0x2
71
72 typedef struct {
73 DWORD header_size;
74 DWORD num_frames;
75 DWORD num_steps;
76 DWORD width;
77 DWORD height;
78 DWORD bpp;
79 DWORD num_planes;
80 DWORD display_rate;
81 DWORD flags;
82 } ani_header;
83
84 typedef struct {
85 BYTE data[32*32*4];
86 } ani_data32x32x32;
87
88 typedef struct {
89 CURSORICONFILEDIR icon_info; /* animated cursor frame information */
90 BITMAPINFOHEADER bmi_header; /* animated cursor frame header */
91 ani_data32x32x32 bmi_data; /* animated cursor frame DIB data */
92 } ani_frame32x32x32;
93
94 typedef struct {
95 DWORD chunk_id; /* ANI_anih_ID */
96 DWORD chunk_size; /* actual size of data */
97 ani_header header; /* animated cursor header */
98 } riff_header_t;
99
100 typedef struct {
101 DWORD chunk_id; /* ANI_LIST_ID */
102 DWORD chunk_size; /* actual size of data */
103 DWORD chunk_type; /* ANI_fram_ID */
104 } riff_list_t;
105
106 typedef struct {
107 DWORD chunk_id; /* ANI_icon_ID */
108 DWORD chunk_size; /* actual size of data */
109 ani_frame32x32x32 data; /* animated cursor frame */
110 } riff_icon32x32x32_t;
111
112 typedef struct {
113 DWORD chunk_id; /* ANI_RIFF_ID */
114 DWORD chunk_size; /* actual size of data */
115 DWORD chunk_type; /* ANI_ACON_ID */
116 riff_header_t header; /* RIFF animated cursor header */
117 riff_list_t frame_list; /* RIFF animated cursor frame list info */
118 riff_icon32x32x32_t frames[1]; /* array of animated cursor frames */
119 } riff_cursor1_t;
120
121 typedef struct {
122 DWORD chunk_id; /* ANI_RIFF_ID */
123 DWORD chunk_size; /* actual size of data */
124 DWORD chunk_type; /* ANI_ACON_ID */
125 riff_header_t header; /* RIFF animated cursor header */
126 riff_list_t frame_list; /* RIFF animated cursor frame list info */
127 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
128 } riff_cursor3_t;
129
130 typedef struct {
131 DWORD chunk_id; /* ANI_rate_ID */
132 DWORD chunk_size; /* actual size of data */
133 DWORD rate[3]; /* animated cursor rate data */
134 } riff_rate3_t;
135
136 typedef struct {
137 DWORD chunk_id; /* ANI_seq__ID */
138 DWORD chunk_size; /* actual size of data */
139 DWORD order[3]; /* animated cursor sequence data */
140 } riff_seq3_t;
141
142 typedef struct {
143 DWORD chunk_id; /* ANI_RIFF_ID */
144 DWORD chunk_size; /* actual size of data */
145 DWORD chunk_type; /* ANI_ACON_ID */
146 riff_header_t header; /* RIFF animated cursor header */
147 riff_seq3_t seq; /* sequence data for three cursor frames */
148 riff_rate3_t rates; /* rate data for three cursor frames */
149 riff_list_t frame_list; /* RIFF animated cursor frame list info */
150 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
151 } riff_cursor3_seq_t;
152
153 #define EMPTY_ICON32 \
154 { \
155 ANI_icon_ID, \
156 sizeof(ani_frame32x32x32), \
157 { \
158 { \
159 0x0, /* reserved */ \
160 0, /* type: icon(1), cursor(2) */ \
161 1, /* count */ \
162 { \
163 { \
164 32, /* width */ \
165 32, /* height */ \
166 0, /* color count */ \
167 0x0, /* reserved */ \
168 16, /* x hotspot */ \
169 16, /* y hotspot */ \
170 sizeof(ani_data32x32x32), /* DIB size */ \
171 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
172 } \
173 } \
174 }, \
175 { \
176 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
177 32, /* width */ \
178 32*2, /* actual height times two */ \
179 1, /* planes */ \
180 32, /* bpp */ \
181 BI_RGB, /* compression */ \
182 0, /* image size */ \
183 0, /* biXPelsPerMeter */ \
184 0, /* biYPelsPerMeter */ \
185 0, /* biClrUsed */ \
186 0 /* biClrImportant */ \
187 } \
188 /* DIB data: left uninitialized */ \
189 } \
190 }
191
192 riff_cursor1_t empty_anicursor = {
193 ANI_RIFF_ID,
194 sizeof(empty_anicursor) - sizeof(DWORD)*2,
195 ANI_ACON_ID,
196 {
197 ANI_anih_ID,
198 sizeof(ani_header),
199 {
200 sizeof(ani_header),
201 1, /* frames */
202 1, /* steps */
203 32, /* width */
204 32, /* height */
205 32, /* depth */
206 1, /* planes */
207 10, /* display rate in jiffies */
208 ANI_FLAG_ICON /* flags */
209 }
210 },
211 {
212 ANI_LIST_ID,
213 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
214 ANI_fram_ID,
215 },
216 {
217 EMPTY_ICON32
218 }
219 };
220
221 riff_cursor3_t empty_anicursor3 = {
222 ANI_RIFF_ID,
223 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
224 ANI_ACON_ID,
225 {
226 ANI_anih_ID,
227 sizeof(ani_header),
228 {
229 sizeof(ani_header),
230 3, /* frames */
231 3, /* steps */
232 32, /* width */
233 32, /* height */
234 32, /* depth */
235 1, /* planes */
236 0xbeef, /* display rate in jiffies */
237 ANI_FLAG_ICON /* flags */
238 }
239 },
240 {
241 ANI_LIST_ID,
242 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
243 ANI_fram_ID,
244 },
245 {
246 EMPTY_ICON32,
247 EMPTY_ICON32,
248 EMPTY_ICON32
249 }
250 };
251
252 riff_cursor3_seq_t empty_anicursor3_seq = {
253 ANI_RIFF_ID,
254 sizeof(empty_anicursor3_seq) - sizeof(DWORD)*2,
255 ANI_ACON_ID,
256 {
257 ANI_anih_ID,
258 sizeof(ani_header),
259 {
260 sizeof(ani_header),
261 3, /* frames */
262 3, /* steps */
263 32, /* width */
264 32, /* height */
265 32, /* depth */
266 1, /* planes */
267 0xbeef, /* display rate in jiffies */
268 ANI_FLAG_ICON|ANI_FLAG_SEQUENCE /* flags */
269 }
270 },
271 {
272 ANI_seq__ID,
273 sizeof(riff_seq3_t) - sizeof(DWORD)*2,
274 { 2, 0, 1} /* show frames in a uniquely identifiable order */
275 },
276 {
277 ANI_rate_ID,
278 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
279 { 0xc0de, 0xcafe, 0xbabe}
280 },
281 {
282 ANI_LIST_ID,
283 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
284 ANI_fram_ID,
285 },
286 {
287 EMPTY_ICON32,
288 EMPTY_ICON32,
289 EMPTY_ICON32
290 }
291 };
292
293 #include "poppack.h"
294
295 static char **test_argv;
296 static int test_argc;
297 static HWND child = 0;
298 static HWND parent = 0;
299 static HANDLE child_process;
300
301 #define PROC_INIT (WM_USER+1)
302
303 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
304 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
305 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
306
307 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
308
309 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
310 {
311 BOOL ret;
312 DWORD error;
313
314 switch (msg)
315 {
316 /* Destroy the cursor. */
317 case WM_USER+1:
318 SetLastError(0xdeadbeef);
319 ret = DestroyCursor((HCURSOR) lParam);
320 error = GetLastError();
321 ok(!ret || broken(ret) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
322 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD ||
323 error == 0xdeadbeef, /* vista */
324 "Last error: %u\n", error);
325 return TRUE;
326 case WM_DESTROY:
327 PostQuitMessage(0);
328 return 0;
329 }
330
331 return DefWindowProcA(hwnd, msg, wParam, lParam);
332 }
333
334 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
335 {
336 if (msg == PROC_INIT)
337 {
338 child = (HWND) wParam;
339 return TRUE;
340 }
341
342 return DefWindowProcA(hwnd, msg, wParam, lParam);
343 }
344
345 static void do_child(void)
346 {
347 WNDCLASSA class;
348 MSG msg;
349 BOOL ret;
350
351 /* Register a new class. */
352 class.style = CS_GLOBALCLASS;
353 class.lpfnWndProc = callback_child;
354 class.cbClsExtra = 0;
355 class.cbWndExtra = 0;
356 class.hInstance = GetModuleHandleA(NULL);
357 class.hIcon = NULL;
358 class.hCursor = NULL;
359 class.hbrBackground = NULL;
360 class.lpszMenuName = NULL;
361 class.lpszClassName = "cursor_child";
362
363 SetLastError(0xdeadbeef);
364 ret = RegisterClassA(&class);
365 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
366
367 /* Create a window. */
368 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
369 0, 0, 200, 200, 0, 0, 0, NULL);
370 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
371
372 /* Let the parent know our HWND. */
373 PostMessageA(parent, PROC_INIT, (WPARAM) child, 0);
374
375 /* Receive messages. */
376 while ((ret = GetMessageA(&msg, 0, 0, 0)))
377 {
378 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
379 TranslateMessage(&msg);
380 DispatchMessageA(&msg);
381 }
382 }
383
384 static void do_parent(void)
385 {
386 char path_name[MAX_PATH];
387 PROCESS_INFORMATION info;
388 STARTUPINFOA startup;
389 WNDCLASSA class;
390 MSG msg;
391 BOOL ret;
392
393 /* Register a new class. */
394 class.style = CS_GLOBALCLASS;
395 class.lpfnWndProc = callback_parent;
396 class.cbClsExtra = 0;
397 class.cbWndExtra = 0;
398 class.hInstance = GetModuleHandleA(NULL);
399 class.hIcon = NULL;
400 class.hCursor = NULL;
401 class.hbrBackground = NULL;
402 class.lpszMenuName = NULL;
403 class.lpszClassName = "cursor_parent";
404
405 SetLastError(0xdeadbeef);
406 ret = RegisterClassA(&class);
407 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
408
409 /* Create a window. */
410 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
411 0, 0, 200, 200, 0, 0, 0, NULL);
412 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
413
414 /* Start child process. */
415 memset(&startup, 0, sizeof(startup));
416 startup.cb = sizeof(startup);
417 startup.dwFlags = STARTF_USESHOWWINDOW;
418 startup.wShowWindow = SW_SHOWNORMAL;
419
420 sprintf(path_name, "%s cursoricon %lx", test_argv[0], (INT_PTR)parent);
421 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
422 child_process = info.hProcess;
423
424 /* Wait for child window handle. */
425 while ((child == 0) && (ret = GetMessageA(&msg, parent, 0, 0)))
426 {
427 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
428 TranslateMessage(&msg);
429 DispatchMessageA(&msg);
430 }
431 }
432
433 static void finish_child_process(void)
434 {
435 SendMessageA(child, WM_CLOSE, 0, 0);
436 winetest_wait_child_process( child_process );
437 CloseHandle(child_process);
438 }
439
440 static void test_child_process(void)
441 {
442 static const BYTE bmp_bits[4096];
443 HCURSOR cursor;
444 ICONINFO cursorInfo;
445 UINT display_bpp;
446 HDC hdc;
447
448 /* Create and set a dummy cursor. */
449 hdc = GetDC(0);
450 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
451 ReleaseDC(0, hdc);
452
453 cursorInfo.fIcon = FALSE;
454 cursorInfo.xHotspot = 0;
455 cursorInfo.yHotspot = 0;
456 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
457 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
458
459 cursor = CreateIconIndirect(&cursorInfo);
460 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
461
462 SetCursor(cursor);
463
464 /* Destroy the cursor. */
465 SendMessageA(child, WM_USER+1, 0, (LPARAM) cursor);
466 }
467
468 static BOOL color_match(COLORREF a, COLORREF b)
469 {
470 /* 5-bit accuracy is a sufficient test. This will match as long as
471 * colors are never truncated to less that 3x5-bit accuracy i.e.
472 * palettized. */
473 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
474 }
475
476 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
477 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
478 {
479 HBITMAP copy;
480 BITMAP origBitmap;
481 BITMAP copyBitmap;
482 BOOL orig_is_dib;
483 BOOL copy_is_dib;
484
485 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
486 ok(copy != NULL, "CopyImage() failed\n");
487 if (copy != NULL)
488 {
489 GetObjectA(bitmap, sizeof(origBitmap), &origBitmap);
490 GetObjectA(copy, sizeof(copyBitmap), &copyBitmap);
491 orig_is_dib = (origBitmap.bmBits != NULL);
492 copy_is_dib = (copyBitmap.bmBits != NULL);
493
494 if (copy_is_dib && dibExpected
495 && copyBitmap.bmBitsPixel == 24
496 && (expectedDepth == 16 || expectedDepth == 32))
497 {
498 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
499 if (GetVersion() & 0x80000000)
500 {
501 expectedDepth = 24;
502 }
503 }
504
505 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
506 {
507 /* It's not forbidden to create a DIB section if the flag
508 LR_CREATEDIBSECTION is absent.
509 Windows 9x does this if the bitmap has a depth that doesn't
510 match the screen depth, Windows NT doesn't */
511 dibExpected = TRUE;
512 expectedDepth = origBitmap.bmBitsPixel;
513 }
514
515 ok((!(dibExpected ^ copy_is_dib)
516 && (copyBitmap.bmWidth == expectedWidth)
517 && (copyBitmap.bmHeight == expectedHeight)
518 && (copyBitmap.bmBitsPixel == expectedDepth)),
519 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
520 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
521 copyWidth, copyHeight, flags,
522 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
523 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
524
525 DeleteObject(copy);
526 }
527 }
528
529 static void test_CopyImage_Bitmap(int depth)
530 {
531 HBITMAP ddb, dib;
532 HDC screenDC;
533 BITMAPINFO * info;
534 VOID * bits;
535 int screen_depth;
536 unsigned int i;
537
538 /* Create a device-independent bitmap (DIB) */
539 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
540 info->bmiHeader.biSize = sizeof(info->bmiHeader);
541 info->bmiHeader.biWidth = 2;
542 info->bmiHeader.biHeight = 2;
543 info->bmiHeader.biPlanes = 1;
544 info->bmiHeader.biBitCount = depth;
545 info->bmiHeader.biCompression = BI_RGB;
546
547 for (i=0; i < 256; i++)
548 {
549 info->bmiColors[i].rgbRed = i;
550 info->bmiColors[i].rgbGreen = i;
551 info->bmiColors[i].rgbBlue = 255 - i;
552 info->bmiColors[i].rgbReserved = 0;
553 }
554
555 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
556
557 /* Create a device-dependent bitmap (DDB) */
558 screenDC = GetDC(NULL);
559 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
560 if (depth == 1 || depth == screen_depth)
561 {
562 ddb = CreateBitmap(2, 2, 1, depth, NULL);
563 }
564 else
565 {
566 ddb = NULL;
567 }
568 ReleaseDC(NULL, screenDC);
569
570 if (ddb != NULL)
571 {
572 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
573 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
574 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
575 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
576
577 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
578 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
579 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
580 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
581
582 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
583 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
584 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
585 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
586
587 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
588 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
589 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
590 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
591 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
592
593 DeleteObject(ddb);
594 }
595
596 if (depth != 1)
597 {
598 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
599 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
600 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
601 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
602 }
603
604 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
605 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
606 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
607 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
608
609 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
610 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
611 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
612 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
613
614 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
615 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
616 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
617 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
618 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
619
620 DeleteObject(dib);
621
622 if (depth == 1)
623 {
624 /* Special case: A monochrome DIB is converted to a monochrome DDB if
625 the colors in the color table are black and white.
626
627 Skip this test on Windows 95, it always creates a monochrome DDB
628 in this case */
629
630 if (!(GetVersion() & 0x80000000))
631 {
632 info->bmiHeader.biBitCount = 1;
633 info->bmiColors[0].rgbRed = 0xFF;
634 info->bmiColors[0].rgbGreen = 0;
635 info->bmiColors[0].rgbBlue = 0;
636 info->bmiColors[1].rgbRed = 0;
637 info->bmiColors[1].rgbGreen = 0xFF;
638 info->bmiColors[1].rgbBlue = 0;
639
640 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
641 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
642 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
643 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
644 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
645 DeleteObject(dib);
646
647 info->bmiHeader.biBitCount = 1;
648 info->bmiColors[0].rgbRed = 0;
649 info->bmiColors[0].rgbGreen = 0;
650 info->bmiColors[0].rgbBlue = 0;
651 info->bmiColors[1].rgbRed = 0xFF;
652 info->bmiColors[1].rgbGreen = 0xFF;
653 info->bmiColors[1].rgbBlue = 0xFF;
654
655 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
656 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
657 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
658 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
659 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
660 DeleteObject(dib);
661
662 info->bmiHeader.biBitCount = 1;
663 info->bmiColors[0].rgbRed = 0xFF;
664 info->bmiColors[0].rgbGreen = 0xFF;
665 info->bmiColors[0].rgbBlue = 0xFF;
666 info->bmiColors[1].rgbRed = 0;
667 info->bmiColors[1].rgbGreen = 0;
668 info->bmiColors[1].rgbBlue = 0;
669
670 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
671 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
672 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
673 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
674 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
675 DeleteObject(dib);
676 }
677 }
678
679 HeapFree(GetProcessHeap(), 0, info);
680 }
681
682 static void test_initial_cursor(void)
683 {
684 HCURSOR cursor, cursor2;
685 DWORD error;
686
687 cursor = GetCursor();
688
689 /* Check what handle GetCursor() returns if a cursor is not set yet. */
690 SetLastError(0xdeadbeef);
691 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_WAIT);
692 todo_wine {
693 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
694 }
695 error = GetLastError();
696 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
697 }
698
699 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_mask_cy, UINT exp_bpp, int line)
700 {
701 ICONINFO info;
702 DWORD ret;
703 BITMAP bmMask, bmColor;
704
705 ret = GetIconInfo(hIcon, &info);
706 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
707
708 /* CreateIcon under XP causes info.fIcon to be 0 */
709 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
710 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
711 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
712
713 ret = GetObjectA(info.hbmMask, sizeof(bmMask), &bmMask);
714 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
715
716 if (exp_bpp == 1)
717 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
718
719 if (info.hbmColor)
720 {
721 HDC hdc;
722 UINT display_bpp;
723
724 hdc = GetDC(0);
725 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
726 ReleaseDC(0, hdc);
727
728 ret = GetObjectA(info.hbmColor, sizeof(bmColor), &bmColor);
729 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
730
731 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
732 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
733 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
734 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
735 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
736
737 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
738 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
739 ok_(__FILE__, line)(bmMask.bmHeight == exp_mask_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
740 }
741 else
742 {
743 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
744 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
745 ok_(__FILE__, line)(bmMask.bmHeight == exp_mask_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
746 }
747 if (pGetIconInfoExA)
748 {
749 ICONINFOEXA infoex;
750
751 memset( &infoex, 0xcc, sizeof(infoex) );
752 SetLastError( 0xdeadbeef );
753 infoex.cbSize = sizeof(infoex) - 1;
754 ret = pGetIconInfoExA( hIcon, &infoex );
755 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
756 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
757
758 SetLastError( 0xdeadbeef );
759 infoex.cbSize = sizeof(infoex) + 1;
760 ret = pGetIconInfoExA( hIcon, &infoex );
761 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
762 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
763
764 SetLastError( 0xdeadbeef );
765 infoex.cbSize = sizeof(infoex);
766 ret = pGetIconInfoExA( (HICON)0xdeadbabe, &infoex );
767 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
768 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE,
769 "wrong error %d\n", GetLastError());
770
771 infoex.cbSize = sizeof(infoex);
772 ret = pGetIconInfoExA( hIcon, &infoex );
773 ok_(__FILE__, line)(ret, "GetIconInfoEx failed err %d\n", GetLastError());
774 ok_(__FILE__, line)(infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID);
775 ok_(__FILE__, line)(infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName);
776 ok_(__FILE__, line)(infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName);
777 }
778 }
779
780 #define test_icon_info(a,b,c,d,e) test_icon_info_dbg((a),(b),(c),(d),(e),__LINE__)
781
782 static void test_CreateIcon(void)
783 {
784 static const BYTE bmp_bits[1024];
785 HICON hIcon;
786 HBITMAP hbmMask, hbmColor;
787 BITMAPINFO *bmpinfo;
788 ICONINFO info;
789 HDC hdc;
790 void *bits;
791 UINT display_bpp;
792 int i;
793
794 hdc = GetDC(0);
795 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
796
797 /* these crash under XP
798 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
799 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
800 */
801
802 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
803 ok(hIcon != 0, "CreateIcon failed\n");
804 test_icon_info(hIcon, 16, 16, 32, 1);
805 DestroyIcon(hIcon);
806
807 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
808 ok(hIcon != 0, "CreateIcon failed\n");
809 test_icon_info(hIcon, 16, 16, 16, display_bpp);
810 DestroyIcon(hIcon);
811
812 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
813 ok(hbmMask != 0, "CreateBitmap failed\n");
814 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
815 ok(hbmColor != 0, "CreateBitmap failed\n");
816
817 info.fIcon = TRUE;
818 info.xHotspot = 8;
819 info.yHotspot = 8;
820 info.hbmMask = 0;
821 info.hbmColor = 0;
822 SetLastError(0xdeadbeaf);
823 hIcon = CreateIconIndirect(&info);
824 ok(!hIcon, "CreateIconIndirect should fail\n");
825 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
826
827 info.fIcon = TRUE;
828 info.xHotspot = 8;
829 info.yHotspot = 8;
830 info.hbmMask = 0;
831 info.hbmColor = hbmColor;
832 SetLastError(0xdeadbeaf);
833 hIcon = CreateIconIndirect(&info);
834 ok(!hIcon, "CreateIconIndirect should fail\n");
835 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
836
837 info.fIcon = TRUE;
838 info.xHotspot = 8;
839 info.yHotspot = 8;
840 info.hbmMask = hbmMask;
841 info.hbmColor = hbmColor;
842 hIcon = CreateIconIndirect(&info);
843 ok(hIcon != 0, "CreateIconIndirect failed\n");
844 test_icon_info(hIcon, 16, 16, 16, display_bpp);
845 DestroyIcon(hIcon);
846
847 DeleteObject(hbmMask);
848 DeleteObject(hbmColor);
849
850 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
851 ok(hbmMask != 0, "CreateBitmap failed\n");
852
853 info.fIcon = TRUE;
854 info.xHotspot = 8;
855 info.yHotspot = 8;
856 info.hbmMask = hbmMask;
857 info.hbmColor = 0;
858 SetLastError(0xdeadbeaf);
859 hIcon = CreateIconIndirect(&info);
860 ok(hIcon != 0, "CreateIconIndirect failed\n");
861 test_icon_info(hIcon, 16, 16, 32, 1);
862 DestroyIcon(hIcon);
863 DeleteObject(hbmMask);
864
865 for (i = 0; i <= 4; i++)
866 {
867 hbmMask = CreateBitmap(1, i, 1, 1, bmp_bits);
868 ok(hbmMask != 0, "CreateBitmap failed\n");
869
870 info.fIcon = TRUE;
871 info.xHotspot = 0;
872 info.yHotspot = 0;
873 info.hbmMask = hbmMask;
874 info.hbmColor = 0;
875 SetLastError(0xdeadbeaf);
876 hIcon = CreateIconIndirect(&info);
877 ok(hIcon != 0, "CreateIconIndirect failed\n");
878 test_icon_info(hIcon, 1, i / 2, max(i,1), 1);
879 DestroyIcon(hIcon);
880 DeleteObject(hbmMask);
881 }
882
883 /* test creating an icon from a DIB section */
884
885 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
886 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
887 bmpinfo->bmiHeader.biWidth = 32;
888 bmpinfo->bmiHeader.biHeight = 32;
889 bmpinfo->bmiHeader.biPlanes = 1;
890 bmpinfo->bmiHeader.biBitCount = 8;
891 bmpinfo->bmiHeader.biCompression = BI_RGB;
892 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
893 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
894 if (bits)
895 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
896 bmpinfo->bmiHeader.biBitCount = 1;
897 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
898 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
899 if (bits)
900 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
901
902 info.fIcon = TRUE;
903 info.xHotspot = 8;
904 info.yHotspot = 8;
905 info.hbmMask = hbmColor;
906 info.hbmColor = hbmMask;
907 SetLastError(0xdeadbeaf);
908 hIcon = CreateIconIndirect(&info);
909 ok(hIcon != 0, "CreateIconIndirect failed\n");
910 test_icon_info(hIcon, 32, 32, 32, 8);
911 DestroyIcon(hIcon);
912 DeleteObject(hbmColor);
913
914 bmpinfo->bmiHeader.biBitCount = 16;
915 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
916 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
917 if (bits)
918 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
919
920 info.fIcon = TRUE;
921 info.xHotspot = 8;
922 info.yHotspot = 8;
923 info.hbmMask = hbmColor;
924 info.hbmColor = hbmMask;
925 SetLastError(0xdeadbeaf);
926 hIcon = CreateIconIndirect(&info);
927 ok(hIcon != 0, "CreateIconIndirect failed\n");
928 test_icon_info(hIcon, 32, 32, 32, 8);
929 DestroyIcon(hIcon);
930 DeleteObject(hbmColor);
931
932 bmpinfo->bmiHeader.biBitCount = 32;
933 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
934 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
935 if (bits)
936 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
937
938 info.fIcon = TRUE;
939 info.xHotspot = 8;
940 info.yHotspot = 8;
941 info.hbmMask = hbmColor;
942 info.hbmColor = hbmMask;
943 SetLastError(0xdeadbeaf);
944 hIcon = CreateIconIndirect(&info);
945 ok(hIcon != 0, "CreateIconIndirect failed\n");
946 test_icon_info(hIcon, 32, 32, 32, 8);
947 DestroyIcon(hIcon);
948
949 DeleteObject(hbmMask);
950 DeleteObject(hbmColor);
951 HeapFree( GetProcessHeap(), 0, bmpinfo );
952
953 ReleaseDC(0, hdc);
954 }
955
956 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
957 /* 1x1 pixel gif */
958 static const unsigned char gifimage[35] = {
959 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
960 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
961 0x01,0x00,0x3b
962 };
963
964 /* 1x1 pixel jpg */
965 static const unsigned char jpgimage[285] = {
966 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
967 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
968 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
969 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
970 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
971 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
972 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
973 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
974 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
975 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
976 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
977 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
978 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
979 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
980 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
981 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
982 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
983 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
984 };
985
986 /* 1x1 pixel png */
987 static const unsigned char pngimage[285] = {
988 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
989 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
990 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
991 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
992 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
993 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
994 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
995 };
996
997 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
998 zeroes, gap is 0xFF. */
999 static unsigned char bmpimage[70] = {
1000 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
1001 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1002 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1003 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
1004 0xFF,0xFF,0x00,0x00,0x00,0x00
1005 };
1006
1007 /* 1x1 pixel bmp using BITMAPCOREHEADER */
1008 static const unsigned char bmpcoreimage[38] = {
1009 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
1010 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
1011 0x55,0x00,0x00,0x00,0x00,0x00
1012 };
1013
1014 /* 2x2 pixel gif */
1015 static const unsigned char gif4pixel[42] = {
1016 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1017 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1018 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1019 };
1020
1021 static const DWORD biSize_tests[] = {
1022 0,
1023 sizeof(BITMAPCOREHEADER) - 1,
1024 sizeof(BITMAPCOREHEADER) + 1,
1025 sizeof(BITMAPINFOHEADER) - 1,
1026 sizeof(BITMAPINFOHEADER) + 1,
1027 sizeof(BITMAPV4HEADER) - 1,
1028 sizeof(BITMAPV4HEADER) + 1,
1029 sizeof(BITMAPV5HEADER) - 1,
1030 sizeof(BITMAPV5HEADER) + 1,
1031 (sizeof(BITMAPCOREHEADER) + sizeof(BITMAPINFOHEADER)) / 2,
1032 (sizeof(BITMAPV4HEADER) + sizeof(BITMAPV5HEADER)) / 2,
1033 0xdeadbeef,
1034 0xffffffff
1035 };
1036
1037 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1038
1039 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1040 {
1041 BITMAP bm;
1042 BITMAPINFO bmi;
1043 DWORD ret, pixel = 0;
1044 HDC hdc = GetDC(NULL);
1045
1046 ret = GetObjectA(hbm, sizeof(bm), &bm);
1047 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1048
1049 memset(&bmi, 0, sizeof(bmi));
1050 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1051 bmi.bmiHeader.biWidth = bm.bmWidth;
1052 bmi.bmiHeader.biHeight = bm.bmHeight;
1053 bmi.bmiHeader.biPlanes = 1;
1054 bmi.bmiHeader.biBitCount= 24;
1055 bmi.bmiHeader.biCompression= BI_RGB;
1056 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
1057 ok(ret == bm.bmHeight, "%s: %d lines were converted, not %d\n", test_desc, ret, bm.bmHeight);
1058
1059 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1060 }
1061
1062 static void test_LoadImageFile(const char * test_desc, const unsigned char * image_data,
1063 unsigned int image_size, const char * ext, BOOL expect_success)
1064 {
1065 HANDLE handle;
1066 BOOL ret;
1067 DWORD error, bytes_written;
1068 char filename[64];
1069
1070 strcpy(filename, "test.");
1071 strcat(filename, ext);
1072
1073 /* Create the test image. */
1074 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1075 FILE_ATTRIBUTE_NORMAL, NULL);
1076 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1077 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
1078 ok(ret && bytes_written == image_size, "test file created improperly.\n");
1079 CloseHandle(handle);
1080
1081 /* Load as cursor. For all tested formats, this should fail */
1082 SetLastError(0xdeadbeef);
1083 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1084 ok(handle == NULL, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc);
1085 error = GetLastError();
1086 ok(error == 0 ||
1087 broken(error == 0xdeadbeef) || /* Win9x */
1088 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1089 "Last error: %u\n", error);
1090 if (handle != NULL) DestroyCursor(handle);
1091
1092 /* Load as icon. For all tested formats, this should fail */
1093 SetLastError(0xdeadbeef);
1094 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
1095 ok(handle == NULL, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc);
1096 error = GetLastError();
1097 ok(error == 0 ||
1098 broken(error == 0xdeadbeef) || /* Win9x */
1099 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1100 "Last error: %u\n", error);
1101 if (handle != NULL) DestroyIcon(handle);
1102
1103 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1104 SetLastError(0xdeadbeef);
1105 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
1106 error = GetLastError();
1107 ok(error == 0 ||
1108 error == 0xdeadbeef, /* Win9x, WinMe */
1109 "Last error: %u\n", error);
1110
1111 if (expect_success) {
1112 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1113 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1114 }
1115 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1116
1117 if (handle != NULL) DeleteObject(handle);
1118 DeleteFileA(filename);
1119 }
1120
1121 static void test_LoadImage(void)
1122 {
1123 HANDLE handle;
1124 BOOL ret;
1125 DWORD error, bytes_written;
1126 CURSORICONFILEDIR *icon_data;
1127 CURSORICONFILEDIRENTRY *icon_entry;
1128 BITMAPINFOHEADER *icon_header, *bitmap_header;
1129 ICONINFO icon_info;
1130 int i;
1131
1132 #define ICON_WIDTH 32
1133 #define ICON_HEIGHT 32
1134 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1135 #define ICON_BPP 32
1136 #define ICON_SIZE \
1137 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1138 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1139
1140 /* Set icon data. */
1141 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
1142 icon_data->idReserved = 0;
1143 icon_data->idType = 1;
1144 icon_data->idCount = 1;
1145
1146 icon_entry = icon_data->idEntries;
1147 icon_entry->bWidth = ICON_WIDTH;
1148 icon_entry->bHeight = ICON_HEIGHT;
1149 icon_entry->bColorCount = 0;
1150 icon_entry->bReserved = 0;
1151 icon_entry->xHotspot = 1;
1152 icon_entry->yHotspot = 1;
1153 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
1154 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
1155
1156 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
1157 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1158 icon_header->biWidth = ICON_WIDTH;
1159 icon_header->biHeight = ICON_HEIGHT*2;
1160 icon_header->biPlanes = 1;
1161 icon_header->biBitCount = ICON_BPP;
1162 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1163
1164 /* Create the icon. */
1165 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1166 FILE_ATTRIBUTE_NORMAL, NULL);
1167 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1168 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
1169 ok(ret && bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
1170 CloseHandle(handle);
1171
1172 /* Test loading an icon as a cursor. */
1173 SetLastError(0xdeadbeef);
1174 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1175 ok(handle != NULL, "LoadImage() failed.\n");
1176 error = GetLastError();
1177 ok(error == 0 ||
1178 broken(error == 0xdeadbeef) || /* Win9x */
1179 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1180 "Last error: %u\n", error);
1181
1182 /* Test the icon information. */
1183 SetLastError(0xdeadbeef);
1184 ret = GetIconInfo(handle, &icon_info);
1185 ok(ret, "GetIconInfo() failed.\n");
1186 error = GetLastError();
1187 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1188
1189 if (ret)
1190 {
1191 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1192 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
1193 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
1194 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1195 "No hbmColor!\n");
1196 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1197 }
1198
1199 if (pGetIconInfoExA)
1200 {
1201 ICONINFOEXA infoex;
1202 infoex.cbSize = sizeof(infoex);
1203 ret = pGetIconInfoExA( handle, &infoex );
1204 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1205 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1206 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1207 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1208 }
1209 else win_skip( "GetIconInfoEx not available\n" );
1210
1211 /* Clean up. */
1212 SetLastError(0xdeadbeef);
1213 ret = DestroyCursor(handle);
1214 ok(ret, "DestroyCursor() failed.\n");
1215 error = GetLastError();
1216 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1217
1218 HeapFree(GetProcessHeap(), 0, icon_data);
1219 DeleteFileA("icon.ico");
1220
1221 /* Test a system icon */
1222 handle = LoadIconA( 0, (LPCSTR)IDI_HAND );
1223 ok(handle != NULL, "LoadImage() failed.\n");
1224 if (pGetIconInfoExA)
1225 {
1226 ICONINFOEXA infoexA;
1227 ICONINFOEXW infoexW;
1228 infoexA.cbSize = sizeof(infoexA);
1229 ret = pGetIconInfoExA( handle, &infoexA );
1230 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1231 ok( infoexA.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexA.wResID );
1232 /* the A version is broken on 64-bit, it truncates the string after the first char */
1233 if (is_win64 && infoexA.szModName[0] && infoexA.szModName[1] == 0)
1234 trace( "GetIconInfoExA broken on Win64\n" );
1235 else
1236 ok( GetModuleHandleA(infoexA.szModName) == GetModuleHandleA("user32.dll"),
1237 "GetIconInfoEx wrong module %s\n", infoexA.szModName );
1238 ok( infoexA.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA.szResName );
1239 infoexW.cbSize = sizeof(infoexW);
1240 ret = pGetIconInfoExW( handle, &infoexW );
1241 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1242 ok( infoexW.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexW.wResID );
1243 ok( GetModuleHandleW(infoexW.szModName) == GetModuleHandleA("user32.dll"),
1244 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW.szModName) );
1245 ok( infoexW.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW.szResName) );
1246 }
1247 SetLastError(0xdeadbeef);
1248 DestroyIcon(handle);
1249
1250 test_LoadImageFile("BMP", bmpimage, sizeof(bmpimage), "bmp", 1);
1251 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage, sizeof(bmpcoreimage), "bmp", 1);
1252 test_LoadImageFile("GIF", gifimage, sizeof(gifimage), "gif", 0);
1253 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel, sizeof(gif4pixel), "gif", 0);
1254 test_LoadImageFile("JPG", jpgimage, sizeof(jpgimage), "jpg", 0);
1255 test_LoadImageFile("PNG", pngimage, sizeof(pngimage), "png", 0);
1256
1257 /* Check failure for broken BMP images */
1258 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1259
1260 bitmap_header->biHeight = 65536;
1261 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1262 bitmap_header->biHeight = 1;
1263
1264 bitmap_header->biWidth = 65536;
1265 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1266 bitmap_header->biWidth = 1;
1267
1268 for (i = 0; i < ARRAY_SIZE(biSize_tests); i++) {
1269 bitmap_header->biSize = biSize_tests[i];
1270 test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
1271 }
1272 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1273 }
1274
1275 #undef ARRAY_SIZE
1276
1277 static void test_CreateIconFromResource(void)
1278 {
1279 HANDLE handle;
1280 BOOL ret;
1281 DWORD error;
1282 BITMAPINFOHEADER *icon_header;
1283 INT16 *hotspot;
1284 ICONINFO icon_info;
1285
1286 #define ICON_RES_WIDTH 32
1287 #define ICON_RES_HEIGHT 32
1288 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1289 #define ICON_RES_BPP 32
1290 #define ICON_RES_SIZE \
1291 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1292 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1293
1294 /* Set icon data. */
1295 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1296
1297 /* Cursor resources have an extra hotspot, icon resources not. */
1298 hotspot[0] = 3;
1299 hotspot[1] = 3;
1300
1301 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1302 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1303 icon_header->biWidth = ICON_WIDTH;
1304 icon_header->biHeight = ICON_HEIGHT*2;
1305 icon_header->biPlanes = 1;
1306 icon_header->biBitCount = ICON_BPP;
1307 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1308
1309 /* Test creating a cursor. */
1310 SetLastError(0xdeadbeef);
1311 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1312 ok(handle != NULL, "Create cursor failed.\n");
1313
1314 /* Test the icon information. */
1315 SetLastError(0xdeadbeef);
1316 ret = GetIconInfo(handle, &icon_info);
1317 ok(ret, "GetIconInfo() failed.\n");
1318 error = GetLastError();
1319 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1320
1321 if (ret)
1322 {
1323 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1324 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1325 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1326 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1327 "No hbmColor!\n");
1328 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1329 }
1330
1331 if (pGetIconInfoExA)
1332 {
1333 ICONINFOEXA infoex;
1334 infoex.cbSize = sizeof(infoex);
1335 ret = pGetIconInfoExA( handle, &infoex );
1336 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1337 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1338 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1339 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1340 }
1341
1342 /* Clean up. */
1343 SetLastError(0xdeadbeef);
1344 ret = DestroyCursor(handle);
1345 ok(ret, "DestroyCursor() failed.\n");
1346 error = GetLastError();
1347 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1348
1349 /* Test creating an icon. */
1350 SetLastError(0xdeadbeef);
1351 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1352 0x00030000);
1353 ok(handle != NULL, "Create icon failed.\n");
1354
1355 /* Test the icon information. */
1356 SetLastError(0xdeadbeef);
1357 ret = GetIconInfo(handle, &icon_info);
1358 ok(ret, "GetIconInfo() failed.\n");
1359 error = GetLastError();
1360 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1361
1362 if (ret)
1363 {
1364 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
1365 /* Icons always have hotspot in the middle */
1366 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
1367 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
1368 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
1369 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1370 }
1371
1372 /* Clean up. */
1373 SetLastError(0xdeadbeef);
1374 ret = DestroyCursor(handle);
1375 ok(ret, "DestroyCursor() failed.\n");
1376 error = GetLastError();
1377 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1378
1379 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1380 *
1381 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1382 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1383 */
1384 HeapFree(GetProcessHeap(), 0, hotspot);
1385
1386 /* Test creating an animated cursor. */
1387 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1388 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1389 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1390 handle = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1391 ok(handle != NULL, "Create cursor failed.\n");
1392
1393 /* Test the animated cursor's information. */
1394 SetLastError(0xdeadbeef);
1395 ret = GetIconInfo(handle, &icon_info);
1396 ok(ret, "GetIconInfo() failed.\n");
1397 error = GetLastError();
1398 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1399
1400 if (ret)
1401 {
1402 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1403 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1404 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1405 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1406 "No hbmColor!\n");
1407 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1408 }
1409
1410 /* Clean up. */
1411 SetLastError(0xdeadbeef);
1412 ret = DestroyCursor(handle);
1413 ok(ret, "DestroyCursor() failed.\n");
1414 error = GetLastError();
1415 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1416 }
1417
1418 static int check_cursor_data( HDC hdc, HCURSOR hCursor, void *data, int length)
1419 {
1420 char *image = NULL;
1421 BITMAPINFO *info;
1422 ICONINFO iinfo;
1423 DWORD ret;
1424 int i;
1425
1426 ret = GetIconInfo( hCursor, &iinfo );
1427 ok(ret, "GetIconInfo() failed\n");
1428 if (!ret) return 0;
1429 ret = 0;
1430 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ));
1431 ok(info != NULL, "HeapAlloc() failed\n");
1432 if (!info) return 0;
1433
1434 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1435 info->bmiHeader.biWidth = 32;
1436 info->bmiHeader.biHeight = 32;
1437 info->bmiHeader.biPlanes = 1;
1438 info->bmiHeader.biBitCount = 32;
1439 info->bmiHeader.biCompression = BI_RGB;
1440 info->bmiHeader.biSizeImage = 32 * 32 * 4;
1441 info->bmiHeader.biXPelsPerMeter = 0;
1442 info->bmiHeader.biYPelsPerMeter = 0;
1443 info->bmiHeader.biClrUsed = 0;
1444 info->bmiHeader.biClrImportant = 0;
1445 image = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage );
1446 ok(image != NULL, "HeapAlloc() failed\n");
1447 if (!image) goto cleanup;
1448 ret = GetDIBits( hdc, iinfo.hbmColor, 0, 32, image, info, DIB_RGB_COLORS );
1449 ok(ret, "GetDIBits() failed\n");
1450 for (i = 0; ret && i < length / sizeof(COLORREF); i++)
1451 {
1452 ret = color_match( ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1453 ok(ret, "%04x: Expected 0x%x, actually 0x%x\n", i, ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1454 }
1455 cleanup:
1456 HeapFree( GetProcessHeap(), 0, image );
1457 HeapFree( GetProcessHeap(), 0, info );
1458 return ret;
1459 }
1460
1461 static HCURSOR (WINAPI *pGetCursorFrameInfo)(HCURSOR hCursor, DWORD unk1, DWORD istep, DWORD *rate, DWORD *steps);
1462 static void test_GetCursorFrameInfo(void)
1463 {
1464 DWORD frame_identifier[] = { 0x10Ad, 0xc001, 0x1c05 };
1465 HBITMAP bmp = NULL, bmpOld = NULL;
1466 DWORD rate, steps;
1467 BITMAPINFOHEADER *icon_header;
1468 BITMAPINFO bitmapInfo;
1469 HDC hdc = NULL;
1470 void *bits = 0;
1471 INT16 *hotspot;
1472 HANDLE h1, h2;
1473 BOOL ret;
1474 int i;
1475
1476 if (!pGetCursorFrameInfo)
1477 {
1478 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1479 return;
1480 }
1481
1482 hdc = CreateCompatibleDC(0);
1483 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1484 if (!hdc)
1485 return;
1486
1487 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1488 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1489 bitmapInfo.bmiHeader.biWidth = 3;
1490 bitmapInfo.bmiHeader.biHeight = 3;
1491 bitmapInfo.bmiHeader.biBitCount = 32;
1492 bitmapInfo.bmiHeader.biPlanes = 1;
1493 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1494 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1495 bmp = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1496 ok (bmp && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1497 if (!bmp || !bits)
1498 goto cleanup;
1499 bmpOld = SelectObject(hdc, bmp);
1500
1501 #define ICON_RES_WIDTH 32
1502 #define ICON_RES_HEIGHT 32
1503 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1504 #define ICON_RES_BPP 32
1505 #define ICON_RES_SIZE \
1506 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1507 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1508
1509 /* Set icon data. */
1510 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1511
1512 /* Cursor resources have an extra hotspot, icon resources not. */
1513 hotspot[0] = 3;
1514 hotspot[1] = 3;
1515
1516 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1517 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1518 icon_header->biWidth = ICON_WIDTH;
1519 icon_header->biHeight = ICON_HEIGHT*2;
1520 icon_header->biPlanes = 1;
1521 icon_header->biBitCount = ICON_BPP;
1522 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1523
1524 /* Creating a static cursor. */
1525 SetLastError(0xdeadbeef);
1526 h1 = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1527 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1528
1529 /* Check GetCursorFrameInfo behavior on a static cursor */
1530 rate = steps = 0xdead;
1531 h2 = pGetCursorFrameInfo(h1, 0xdead, 0xdead, &rate, &steps);
1532 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1533 ok(rate == 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1534 ok(steps == 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1535
1536 /* Clean up static cursor. */
1537 SetLastError(0xdeadbeef);
1538 ret = DestroyCursor(h1);
1539 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1540
1541 /* Creating a single-frame animated cursor. */
1542 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1543 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1544 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1545 memcpy( &empty_anicursor.frames[0].data.bmi_data.data[0], &frame_identifier[0], sizeof(DWORD) );
1546 SetLastError(0xdeadbeef);
1547 h1 = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1548 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1549
1550 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1551 rate = steps = 0xdead;
1552 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1553 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1554 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1555 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1556 ok(rate == 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1557 ok(steps == empty_anicursor.header.header.num_steps,
1558 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1559
1560 /* Clean up single-frame animated cursor. */
1561 SetLastError(0xdeadbeef);
1562 ret = DestroyCursor(h1);
1563 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1564
1565 /* Creating a multi-frame animated cursor. */
1566 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1567 {
1568 empty_anicursor3.frames[i].data.icon_info.idType = 2; /* type: cursor */
1569 empty_anicursor3.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1570 empty_anicursor3.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1571 memcpy( &empty_anicursor3.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1572 }
1573 SetLastError(0xdeadbeef);
1574 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1575 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1576
1577 /* Check number of steps in multi-frame animated cursor */
1578 i=0;
1579 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1580 i++;
1581 ok(i == empty_anicursor3.header.header.num_steps,
1582 "Unexpected number of steps in cursor (%d != %d)\n",
1583 i, empty_anicursor3.header.header.num_steps);
1584
1585 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1586 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1587 {
1588 rate = steps = 0xdead;
1589 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1590 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1591 ret = check_cursor_data( hdc, h2, &frame_identifier[i], sizeof(DWORD) );
1592 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1593 ok(rate == empty_anicursor3.header.header.display_rate,
1594 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1595 rate, empty_anicursor3.header.header.display_rate);
1596 ok(steps == empty_anicursor3.header.header.num_steps,
1597 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1598 steps, empty_anicursor3.header.header.num_steps);
1599 }
1600
1601 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1602 rate = steps = 0xdead;
1603 h2 = pGetCursorFrameInfo(h1, 0xdead, 3, &rate, &steps);
1604 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1605 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1606 || broken(rate == ~0) /*win2k (sporadic)*/,
1607 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1608 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1609 || broken(steps == 0) /*win2k (sporadic)*/,
1610 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps);
1611
1612 /* Clean up multi-frame animated cursor. */
1613 SetLastError(0xdeadbeef);
1614 ret = DestroyCursor(h1);
1615 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1616
1617 /* Create a multi-frame animated cursor with num_steps == 1 */
1618 empty_anicursor3.header.header.num_steps = 1;
1619 SetLastError(0xdeadbeef);
1620 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1621 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1622
1623 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1624 i=0;
1625 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1626 i++;
1627 ok(i == empty_anicursor3.header.header.num_steps,
1628 "Unexpected number of steps in cursor (%d != %d)\n",
1629 i, empty_anicursor3.header.header.num_steps);
1630
1631 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1632 rate = steps = 0xdead;
1633 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1634 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1635 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1636 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1637 ok(rate == empty_anicursor3.header.header.display_rate,
1638 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1639 rate, empty_anicursor3.header.header.display_rate);
1640 ok(steps == ~0 || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/,
1641 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps);
1642
1643 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1644 rate = steps = 0xdead;
1645 h2 = pGetCursorFrameInfo(h1, 0xdead, 1, &rate, &steps);
1646 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1647 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1648 || broken(rate == ~0) /*win2k (sporadic)*/,
1649 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1650 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1651 || broken(steps == 0) /*win2k (sporadic)*/,
1652 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps);
1653
1654 /* Clean up multi-frame animated cursor. */
1655 SetLastError(0xdeadbeef);
1656 ret = DestroyCursor(h1);
1657 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1658
1659 /* Creating a multi-frame animated cursor with rate data. */
1660 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1661 {
1662 empty_anicursor3_seq.frames[i].data.icon_info.idType = 2; /* type: cursor */
1663 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1664 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1665 memcpy( &empty_anicursor3_seq.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1666 }
1667 SetLastError(0xdeadbeef);
1668 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3_seq, sizeof(empty_anicursor3_seq), FALSE, 0x00030000);
1669 ok(h1 != NULL, "Create cursor failed (error = %x).\n", GetLastError());
1670
1671 /* Check number of steps in multi-frame animated cursor with rate data */
1672 i=0;
1673 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1674 i++;
1675 ok(i == empty_anicursor3_seq.header.header.num_steps,
1676 "Unexpected number of steps in cursor (%d != %d)\n",
1677 i, empty_anicursor3_seq.header.header.num_steps);
1678
1679 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1680 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1681 {
1682 int frame_id = empty_anicursor3_seq.seq.order[i];
1683
1684 rate = steps = 0xdead;
1685 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1686 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1687 ret = check_cursor_data( hdc, h2, &frame_identifier[frame_id], sizeof(DWORD) );
1688 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1689 ok(rate == empty_anicursor3_seq.rates.rate[i],
1690 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1691 rate, empty_anicursor3_seq.rates.rate[i]);
1692 ok(steps == empty_anicursor3_seq.header.header.num_steps,
1693 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1694 steps, empty_anicursor3_seq.header.header.num_steps);
1695 }
1696
1697 /* Clean up multi-frame animated cursor with rate data. */
1698 SetLastError(0xdeadbeef);
1699 ret = DestroyCursor(h1);
1700 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1701
1702 HeapFree(GetProcessHeap(), 0, hotspot);
1703 cleanup:
1704 if(bmpOld) SelectObject(hdc, bmpOld);
1705 if(bmp) DeleteObject(bmp);
1706 if(hdc) DeleteDC(hdc);
1707 }
1708
1709 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1710 BOOL maskvalue, UINT32 *color, int colorSize)
1711 {
1712 ICONINFO iconInfo;
1713 BITMAPINFO bitmapInfo;
1714 void *buffer = NULL;
1715 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1716
1717 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1718 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1719 bitmapInfo.bmiHeader.biWidth = width;
1720 bitmapInfo.bmiHeader.biHeight = height;
1721 bitmapInfo.bmiHeader.biPlanes = 1;
1722 bitmapInfo.bmiHeader.biBitCount = bpp;
1723 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1724 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1725
1726 iconInfo.fIcon = TRUE;
1727 iconInfo.xHotspot = 0;
1728 iconInfo.yHotspot = 0;
1729
1730 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1731 if(!iconInfo.hbmMask) return NULL;
1732
1733 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1734 if(!iconInfo.hbmColor || !buffer)
1735 {
1736 DeleteObject(iconInfo.hbmMask);
1737 return NULL;
1738 }
1739
1740 memcpy(buffer, color, colorSize);
1741
1742 return CreateIconIndirect(&iconInfo);
1743 }
1744
1745 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1746 {
1747 HICON hicon;
1748 UINT32 color[2];
1749 COLORREF modern_expected, legacy_expected, result;
1750
1751 color[0] = 0x00A0B0C0;
1752 color[1] = alpha ? 0xFF000000 : 0x00000000;
1753 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1754 legacy_expected = 0x00C0B0A0;
1755
1756 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1757 if (!hicon) return;
1758
1759 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1760
1761 if(drawiconex)
1762 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1763 else
1764 DrawIcon(hdc, 0, 0, hicon);
1765
1766 result = GetPixel(hdc, 0, 0);
1767 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1768 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1769 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1770 "Got %06X from line %d\n",
1771 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1772 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1773 }
1774
1775 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1776 COLORREF modern_expected, COLORREF legacy_expected, int line)
1777 {
1778 COLORREF result;
1779 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1780 if (!hicon) return;
1781 SetPixelV(hdc, 0, 0, background);
1782 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1783 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1784 DrawIcon(hdc, 0, 0, hicon);
1785 result = GetPixel(hdc, 0, 0);
1786
1787 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1788 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1789 "Overlaying Mask %d on Color %06X with DrawIcon. "
1790 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1791 maskvalue, color, modern_expected, legacy_expected, result, line);
1792
1793 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1794
1795 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1796 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1797 "Overlaying Mask %d on Color %06X with DrawIcon. "
1798 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1799 maskvalue, color, modern_expected, legacy_expected, result, line);
1800
1801 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1802
1803 ok (color_match(result, background),
1804 "Overlaying Mask %d on Color %06X with DrawIcon. "
1805 "Expected unchanged background color %06X. Got %06X from line %d\n",
1806 maskvalue, color, background, result, line);
1807 }
1808
1809 static void test_DrawIcon(void)
1810 {
1811 BITMAPINFO bitmapInfo;
1812 HDC hdcDst = NULL;
1813 HBITMAP bmpDst = NULL;
1814 HBITMAP bmpOld = NULL;
1815 void *bits = 0;
1816
1817 hdcDst = CreateCompatibleDC(0);
1818 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1819 if (!hdcDst)
1820 return;
1821
1822 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1823 {
1824 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1825 goto cleanup;
1826 }
1827
1828 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1829 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1830 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1831 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1832 bitmapInfo.bmiHeader.biBitCount = 32;
1833 bitmapInfo.bmiHeader.biPlanes = 1;
1834 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1835 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1836
1837 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1838 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1839 if (!bmpDst || !bits)
1840 goto cleanup;
1841 bmpOld = SelectObject(hdcDst, bmpDst);
1842
1843 /* Mask is only heeded if alpha channel is always zero */
1844 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1845 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1846
1847 /* Test alpha blending */
1848 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1849 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1850 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1851
1852 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1853 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1854 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1855 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1856
1857 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1858 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1859
1860 /* Test detecting of alpha channel */
1861 /* If a single pixel's alpha channel is non-zero, the icon
1862 will be alpha blended, otherwise it will be draw with
1863 and + xor blts. */
1864 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1865 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1866
1867 cleanup:
1868 if(bmpOld)
1869 SelectObject(hdcDst, bmpOld);
1870 if(bmpDst)
1871 DeleteObject(bmpDst);
1872 if(hdcDst)
1873 DeleteDC(hdcDst);
1874 }
1875
1876 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1877 COLORREF modern_expected, COLORREF legacy_expected, int line)
1878 {
1879 COLORREF result;
1880 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1881 if (!hicon) return;
1882 SetPixelV(hdc, 0, 0, background);
1883 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1884 result = GetPixel(hdc, 0, 0);
1885
1886 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1887 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1888 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1889 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1890 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1891 }
1892
1893 static void test_DrawIconEx(void)
1894 {
1895 BITMAPINFO bitmapInfo;
1896 HDC hdcDst = NULL;
1897 HBITMAP bmpDst = NULL;
1898 HBITMAP bmpOld = NULL;
1899 void *bits = 0;
1900
1901 hdcDst = CreateCompatibleDC(0);
1902 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1903 if (!hdcDst)
1904 return;
1905
1906 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1907 {
1908 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1909 goto cleanup;
1910 }
1911
1912 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1913 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1914 bitmapInfo.bmiHeader.biWidth = 1;
1915 bitmapInfo.bmiHeader.biHeight = 1;
1916 bitmapInfo.bmiHeader.biBitCount = 32;
1917 bitmapInfo.bmiHeader.biPlanes = 1;
1918 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1919 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1920 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1921 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1922 if (!bmpDst || !bits)
1923 goto cleanup;
1924 bmpOld = SelectObject(hdcDst, bmpDst);
1925
1926 /* Test null, image only, and mask only drawing */
1927 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1928 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1929
1930 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00123456, 0x00000000, 0x00000000, __LINE__);
1931 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00123456, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1932
1933 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1934 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1935
1936 /* Test normal drawing */
1937 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1938 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1939 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1940
1941 /* Test alpha blending */
1942 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1943 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1944
1945 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1946 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1947 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1948 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1949
1950 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1951 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1952
1953 /* Test detecting of alpha channel */
1954 /* If a single pixel's alpha channel is non-zero, the icon
1955 will be alpha blended, otherwise it will be draw with
1956 and + xor blts. */
1957 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1958 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1959
1960 cleanup:
1961 if(bmpOld)
1962 SelectObject(hdcDst, bmpOld);
1963 if(bmpDst)
1964 DeleteObject(bmpDst);
1965 if(hdcDst)
1966 DeleteDC(hdcDst);
1967 }
1968
1969 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1970 {
1971 COLORREF result, background;
1972 BOOL passed[2];
1973 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1974 background = 0x00FFFFFF;
1975 /* Set color of the 2 pixels that will be checked afterwards */
1976 SetPixelV(hdc, 0, 0, background);
1977 SetPixelV(hdc, 2, 2, background);
1978
1979 /* Let DrawState calculate the size of the icon (it's 1x1) */
1980 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1981
1982 result = GetPixel(hdc, 0, 0);
1983 passed[0] = color_match(result, background);
1984 result = GetPixel(hdc, 2, 2);
1985 passed[0] = passed[0] & color_match(result, background);
1986
1987 /* Check if manually specifying the icon size DOESN'T work */
1988
1989 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1990 * size in which it should be ultimately drawn. Therefore giving
1991 * width/height 2x2 if the icon is only 1x1 pixels in size should
1992 * result in drawing it with size 1x1. The size parameters must be
1993 * ignored if a Icon has to be drawn! */
1994 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1995
1996 result = GetPixel(hdc, 0, 0);
1997 passed[1] = color_match(result, background);
1998 result = GetPixel(hdc, 2, 2);
1999 passed[1] = passed[0] & color_match(result, background);
2000
2001 if(!passed[0]&&!passed[1])
2002 ok (passed[1],
2003 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
2004 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
2005 "Color %06X with flags %08X. Line %d\n",
2006 maskvalue, color, (DST_ICON | flags), line);
2007 else if(!passed[1])
2008 ok (passed[1],
2009 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2010 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
2011 "Mask %d on Color %06X with flags %08X. Line %d\n",
2012 maskvalue, color, (DST_ICON | flags), line);
2013 else
2014 ok (passed[0],
2015 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2016 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
2017 "Color %06X with flags %08X. Line %d\n",
2018 maskvalue, color, (DST_ICON | flags), line);
2019 }
2020
2021 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
2022 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
2023 {
2024 COLORREF result;
2025 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2026 if (!hicon) return;
2027 /* Set color of the pixel that will be checked afterwards */
2028 SetPixelV(hdc, 1, 1, background);
2029
2030 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
2031
2032 /* Check the color of the pixel is correct */
2033 result = GetPixel(hdc, 1, 1);
2034
2035 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
2036 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
2037 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2038 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2039 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
2040 }
2041
2042 static void test_DrawState(void)
2043 {
2044 BITMAPINFO bitmapInfo;
2045 HDC hdcDst = NULL;
2046 HBITMAP bmpDst = NULL;
2047 HBITMAP bmpOld = NULL;
2048 void *bits = 0;
2049
2050 hdcDst = CreateCompatibleDC(0);
2051 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2052 if (!hdcDst)
2053 return;
2054
2055 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
2056 {
2057 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2058 goto cleanup;
2059 }
2060
2061 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
2062 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2063 bitmapInfo.bmiHeader.biWidth = 3;
2064 bitmapInfo.bmiHeader.biHeight = 3;
2065 bitmapInfo.bmiHeader.biBitCount = 32;
2066 bitmapInfo.bmiHeader.biPlanes = 1;
2067 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2068 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2069 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
2070 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2071 if (!bmpDst || !bits)
2072 goto cleanup;
2073 bmpOld = SelectObject(hdcDst, bmpDst);
2074
2075 /* potential flags to test with DrawState are: */
2076 /* DSS_DISABLED embosses the icon */
2077 /* DSS_MONO draw Icon using a brush as parameter 5 */
2078 /* DSS_NORMAL draw Icon without any modifications */
2079 /* DSS_UNION draw the Icon dithered */
2080
2081 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
2082 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
2083
2084 cleanup:
2085 if(bmpOld)
2086 SelectObject(hdcDst, bmpOld);
2087 if(bmpDst)
2088 DeleteObject(bmpDst);
2089 if(hdcDst)
2090 DeleteDC(hdcDst);
2091 }
2092
2093 static DWORD parent_id;
2094
2095 static DWORD CALLBACK set_cursor_thread( void *arg )
2096 {
2097 HCURSOR ret;
2098
2099 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2100 if (parent_id)
2101 {
2102 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2103 ok( ret, "AttachThreadInput failed\n" );
2104 }
2105 if (arg) ret = SetCursor( (HCURSOR)arg );
2106 else ret = GetCursor();
2107 return (DWORD_PTR)ret;
2108 }
2109
2110 static void test_SetCursor(void)
2111 {
2112 static const BYTE bmp_bits[4096];
2113 ICONINFO cursorInfo;
2114 HCURSOR cursor, old_cursor, global_cursor = 0;
2115 DWORD error, id, result;
2116 UINT display_bpp;
2117 HDC hdc;
2118 HANDLE thread;
2119 CURSORINFO info;
2120
2121 if (pGetCursorInfo)
2122 {
2123 memset( &info, 0, sizeof(info) );
2124 info.cbSize = sizeof(info);
2125 if (!pGetCursorInfo( &info ))
2126 {
2127 win_skip( "GetCursorInfo not working\n" );
2128 pGetCursorInfo = NULL;
2129 }
2130 else global_cursor = info.hCursor;
2131 }
2132 cursor = GetCursor();
2133 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2134 WaitForSingleObject( thread, 1000 );
2135 GetExitCodeThread( thread, &result );
2136 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
2137
2138 hdc = GetDC(0);
2139 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2140 ReleaseDC(0, hdc);
2141
2142 cursorInfo.fIcon = FALSE;
2143 cursorInfo.xHotspot = 0;
2144 cursorInfo.yHotspot = 0;
2145 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2146 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2147
2148 cursor = CreateIconIndirect(&cursorInfo);
2149 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2150 old_cursor = SetCursor( cursor );
2151
2152 if (pGetCursorInfo)
2153 {
2154 info.cbSize = sizeof(info);
2155 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2156 /* global cursor doesn't change since we don't have a window */
2157 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2158 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2159 }
2160 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2161 WaitForSingleObject( thread, 1000 );
2162 GetExitCodeThread( thread, &result );
2163 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2164
2165 SetCursor( 0 );
2166 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2167 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2168 WaitForSingleObject( thread, 1000 );
2169 GetExitCodeThread( thread, &result );
2170 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2171
2172 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2173 WaitForSingleObject( thread, 1000 );
2174 GetExitCodeThread( thread, &result );
2175 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2176 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2177
2178 parent_id = GetCurrentThreadId();
2179 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2180 WaitForSingleObject( thread, 1000 );
2181 GetExitCodeThread( thread, &result );
2182 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2183 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
2184
2185 if (pGetCursorInfo)
2186 {
2187 info.cbSize = sizeof(info);
2188 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2189 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2190 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2191 }
2192 SetCursor( old_cursor );
2193 DestroyCursor( cursor );
2194
2195 SetLastError( 0xdeadbeef );
2196 cursor = SetCursor( (HCURSOR)0xbadbad );
2197 error = GetLastError();
2198 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
2199 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
2200 "wrong error %u\n", error );
2201
2202 if (pGetCursorInfo)
2203 {
2204 info.cbSize = sizeof(info);
2205 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2206 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2207 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2208 }
2209 }
2210
2211 static HANDLE event_start, event_next;
2212
2213 static DWORD CALLBACK show_cursor_thread( void *arg )
2214 {
2215 DWORD count = (DWORD_PTR)arg;
2216 int ret;
2217
2218 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2219 if (parent_id)
2220 {
2221 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2222 ok( ret, "AttachThreadInput failed\n" );
2223 }
2224 if (!count) ret = ShowCursor( FALSE );
2225 else while (count--) ret = ShowCursor( TRUE );
2226 SetEvent( event_start );
2227 WaitForSingleObject( event_next, 2000 );
2228 return ret;
2229 }
2230
2231 static void test_ShowCursor(void)
2232 {
2233 int count;
2234 DWORD id, result;
2235 HANDLE thread;
2236 CURSORINFO info;
2237
2238 if (pGetCursorInfo)
2239 {
2240 memset( &info, 0, sizeof(info) );
2241 info.cbSize = sizeof(info);
2242 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2243 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2244 }
2245
2246 event_start = CreateEventW( NULL, FALSE, FALSE, NULL );
2247 event_next = CreateEventW( NULL, FALSE, FALSE, NULL );
2248
2249 count = ShowCursor( TRUE );
2250 ok( count == 1, "wrong count %d\n", count );
2251 count = ShowCursor( TRUE );
2252 ok( count == 2, "wrong count %d\n", count );
2253 count = ShowCursor( FALSE );
2254 ok( count == 1, "wrong count %d\n", count );
2255 count = ShowCursor( FALSE );
2256 ok( count == 0, "wrong count %d\n", count );
2257 count = ShowCursor( FALSE );
2258 ok( count == -1, "wrong count %d\n", count );
2259 count = ShowCursor( FALSE );
2260 ok( count == -2, "wrong count %d\n", count );
2261
2262 if (pGetCursorInfo)
2263 {
2264 info.cbSize = sizeof(info);
2265 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2266 /* global show count is not affected since we don't have a window */
2267 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2268 }
2269
2270 parent_id = 0;
2271 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2272 WaitForSingleObject( event_start, 1000 );
2273 count = ShowCursor( FALSE );
2274 ok( count == -3, "wrong count %d\n", count );
2275 SetEvent( event_next );
2276 WaitForSingleObject( thread, 1000 );
2277 GetExitCodeThread( thread, &result );
2278 ok( result == -1, "wrong thread count %d\n", result );
2279 count = ShowCursor( FALSE );
2280 ok( count == -4, "wrong count %d\n", count );
2281
2282 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
2283 WaitForSingleObject( event_start, 1000 );
2284 count = ShowCursor( TRUE );
2285 ok( count == -3, "wrong count %d\n", count );
2286 SetEvent( event_next );
2287 WaitForSingleObject( thread, 1000 );
2288 GetExitCodeThread( thread, &result );
2289 ok( result == 1, "wrong thread count %d\n", result );
2290 count = ShowCursor( TRUE );
2291 ok( count == -2, "wrong count %d\n", count );
2292
2293 parent_id = GetCurrentThreadId();
2294 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2295 WaitForSingleObject( event_start, 1000 );
2296 count = ShowCursor( TRUE );
2297 ok( count == -2, "wrong count %d\n", count );
2298 SetEvent( event_next );
2299 WaitForSingleObject( thread, 1000 );
2300 GetExitCodeThread( thread, &result );
2301 ok( result == -3, "wrong thread count %d\n", result );
2302 count = ShowCursor( FALSE );
2303 ok( count == -2, "wrong count %d\n", count );
2304
2305 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
2306 WaitForSingleObject( event_start, 1000 );
2307 count = ShowCursor( TRUE );
2308 ok( count == 2, "wrong count %d\n", count );
2309 SetEvent( event_next );
2310 WaitForSingleObject( thread, 1000 );
2311 GetExitCodeThread( thread, &result );
2312 ok( result == 1, "wrong thread count %d\n", result );
2313 count = ShowCursor( FALSE );
2314 ok( count == -2, "wrong count %d\n", count );
2315
2316 if (pGetCursorInfo)
2317 {
2318 info.cbSize = sizeof(info);
2319 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2320 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2321 }
2322
2323 count = ShowCursor( TRUE );
2324 ok( count == -1, "wrong count %d\n", count );
2325 count = ShowCursor( TRUE );
2326 ok( count == 0, "wrong count %d\n", count );
2327
2328 if (pGetCursorInfo)
2329 {
2330 info.cbSize = sizeof(info);
2331 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2332 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2333 }
2334 }
2335
2336
2337 static void test_DestroyCursor(void)
2338 {
2339 static const BYTE bmp_bits[4096];
2340 ICONINFO cursorInfo, new_info;
2341 HCURSOR cursor, cursor2, new_cursor;
2342 BOOL ret;
2343 DWORD error;
2344 UINT display_bpp;
2345 HDC hdc;
2346
2347 hdc = GetDC(0);
2348 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2349 ReleaseDC(0, hdc);
2350
2351 cursorInfo.fIcon = FALSE;
2352 cursorInfo.xHotspot = 0;
2353 cursorInfo.yHotspot = 0;
2354 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2355 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2356
2357 cursor = CreateIconIndirect(&cursorInfo);
2358 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2359 if(!cursor) {
2360 return;
2361 }
2362 SetCursor(cursor);
2363
2364 SetLastError(0xdeadbeef);
2365 ret = DestroyCursor(cursor);
2366 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2367 error = GetLastError();
2368 ok(error == 0xdeadbeef, "Last error: %u\n", error);
2369
2370 new_cursor = GetCursor();
2371 if (ret) /* win9x replaces cursor by another one on destroy */
2372 ok(new_cursor != cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2373 else
2374 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2375
2376 SetLastError(0xdeadbeef);
2377 ret = GetIconInfo( cursor, &new_info );
2378 ok( !ret || broken(ret), /* nt4 */ "GetIconInfo succeeded\n" );
2379 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2380 broken(GetLastError() == 0xdeadbeef), /* win9x */
2381 "wrong error %u\n", GetLastError() );
2382
2383 if (ret) /* nt4 delays destruction until cursor changes */
2384 {
2385 DeleteObject( new_info.hbmColor );
2386 DeleteObject( new_info.hbmMask );
2387
2388 SetLastError(0xdeadbeef);
2389 ret = DestroyCursor( cursor );
2390 ok( !ret, "DestroyCursor succeeded\n" );
2391 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2392 "wrong error %u\n", GetLastError() );
2393
2394 SetLastError(0xdeadbeef);
2395 cursor2 = SetCursor( cursor );
2396 ok( cursor2 == cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2397 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2398 "wrong error %u\n", GetLastError() );
2399 }
2400 else
2401 {
2402 SetLastError(0xdeadbeef);
2403 cursor2 = CopyCursor( cursor );
2404 ok(!cursor2, "CopyCursor succeeded\n" );
2405 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2406 broken(GetLastError() == 0xdeadbeef), /* win9x */
2407 "wrong error %u\n", GetLastError() );
2408
2409 SetLastError(0xdeadbeef);
2410 ret = DestroyCursor( cursor );
2411 if (new_cursor != cursor) /* win9x */
2412 ok( ret, "DestroyCursor succeeded\n" );
2413 else
2414 ok( !ret, "DestroyCursor succeeded\n" );
2415 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2416 "wrong error %u\n", GetLastError() );
2417
2418 SetLastError(0xdeadbeef);
2419 cursor2 = SetCursor( cursor );
2420 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2421 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2422 "wrong error %u\n", GetLastError() );
2423 }
2424
2425 cursor2 = GetCursor();
2426 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2427
2428 SetLastError(0xdeadbeef);
2429 cursor2 = SetCursor( 0 );
2430 if (new_cursor != cursor) /* win9x */
2431 ok(cursor2 == new_cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2432 else
2433 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2434 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2435
2436 cursor2 = GetCursor();
2437 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2438
2439 SetLastError(0xdeadbeef);
2440 ret = DestroyCursor(cursor);
2441 if (new_cursor != cursor) /* win9x */
2442 ok( ret, "DestroyCursor succeeded\n" );
2443 else
2444 ok( !ret, "DestroyCursor succeeded\n" );
2445 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2446 "wrong error %u\n", GetLastError() );
2447
2448 DeleteObject(cursorInfo.hbmMask);
2449 DeleteObject(cursorInfo.hbmColor);
2450
2451 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2452 cursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
2453
2454 SetLastError(0xdeadbeef);
2455 ret = DestroyCursor(cursor);
2456 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2457 error = GetLastError();
2458 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2459
2460 /* Try setting the cursor to a destroyed OEM cursor. */
2461 SetLastError(0xdeadbeef);
2462 SetCursor(cursor);
2463 error = GetLastError();
2464 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2465
2466 /* Check if LoadCursor() returns the same handle with the same icon. */
2467 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
2468 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2469
2470 /* Check if LoadCursor() returns the same handle with a different icon. */
2471 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_WAIT);
2472 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2473 }
2474
2475 START_TEST(cursoricon)
2476 {
2477 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2478 pGetIconInfoExA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2479 pGetIconInfoExW = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2480 pGetCursorFrameInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2481 test_argc = winetest_get_mainargs(&test_argv);
2482
2483 if (test_argc >= 3)
2484 {
2485 /* Child process. */
2486 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2487
2488 ok(parent != NULL, "Parent not found.\n");
2489 if (parent == NULL)
2490 ExitProcess(1);
2491
2492 do_child();
2493 return;
2494 }
2495
2496 test_CopyImage_Bitmap(1);
2497 test_CopyImage_Bitmap(4);
2498 test_CopyImage_Bitmap(8);
2499 test_CopyImage_Bitmap(16);
2500 test_CopyImage_Bitmap(24);
2501 test_CopyImage_Bitmap(32);
2502 test_initial_cursor();
2503 test_CreateIcon();
2504 test_LoadImage();
2505 test_CreateIconFromResource();
2506 test_GetCursorFrameInfo();
2507 test_DrawIcon();
2508 test_DrawIconEx();
2509 test_DrawState();
2510 test_SetCursor();
2511 test_ShowCursor();
2512 test_DestroyCursor();
2513 do_parent();
2514 test_child_process();
2515 finish_child_process();
2516 }