2 * Unit test suite for cursors and icons.
4 * Copyright 2006 Michael Kaufmann
5 * Copyright 2007 Dmitry Timoshkov
6 * Copyright 2007-2008 Andrew Riedi
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.
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.
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
27 #include "wine/test.h"
46 } CURSORICONFILEDIRENTRY;
53 CURSORICONFILEDIRENTRY idEntries[1];
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 ) )
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')
69 #define ANI_FLAG_ICON 0x1
70 #define ANI_FLAG_SEQUENCE 0x2
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 */
95 DWORD chunk_id; /* ANI_anih_ID */
96 DWORD chunk_size; /* actual size of data */
97 ani_header header; /* animated cursor header */
101 DWORD chunk_id; /* ANI_LIST_ID */
102 DWORD chunk_size; /* actual size of data */
103 DWORD chunk_type; /* ANI_fram_ID */
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;
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 */
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 */
131 DWORD chunk_id; /* ANI_rate_ID */
132 DWORD chunk_size; /* actual size of data */
133 DWORD rate[3]; /* animated cursor rate data */
137 DWORD chunk_id; /* ANI_seq__ID */
138 DWORD chunk_size; /* actual size of data */
139 DWORD order[3]; /* animated cursor sequence data */
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;
153 #define EMPTY_ICON32 \
156 sizeof(ani_frame32x32x32), \
159 0x0, /* reserved */ \
160 0, /* type: icon(1), cursor(2) */ \
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 */ \
176 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
178 32*2, /* actual height times two */ \
181 BI_RGB, /* compression */ \
182 0, /* image size */ \
183 0, /* biXPelsPerMeter */ \
184 0, /* biYPelsPerMeter */ \
186 0 /* biClrImportant */ \
188 /* DIB data: left uninitialized */ \
192 riff_cursor1_t empty_anicursor = {
194 sizeof(empty_anicursor) - sizeof(DWORD)*2,
207 10, /* display rate in jiffies */
208 ANI_FLAG_ICON /* flags */
213 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
221 riff_cursor3_t empty_anicursor3 = {
223 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
236 0xbeef, /* display rate in jiffies */
237 ANI_FLAG_ICON /* flags */
242 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
252 riff_cursor3_seq_t empty_anicursor3_seq = {
254 sizeof(empty_anicursor3_seq) - sizeof(DWORD)*2,
267 0xbeef, /* display rate in jiffies */
268 ANI_FLAG_ICON|ANI_FLAG_SEQUENCE /* flags */
273 sizeof(riff_seq3_t) - sizeof(DWORD)*2,
274 { 2, 0, 1} /* show frames in a uniquely identifiable order */
278 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
279 { 0xc0de, 0xcafe, 0xbabe}
283 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
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;
301 #define PROC_INIT (WM_USER+1)
303 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
304 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
305 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
307 static const int is_win64 = (sizeof(void *) > sizeof(int));
309 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
316 /* Destroy the cursor. */
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);
331 return DefWindowProc(hwnd, msg, wParam, lParam);
334 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
336 if (msg == PROC_INIT)
338 child = (HWND) wParam;
342 return DefWindowProc(hwnd, msg, wParam, lParam);
345 static void do_child(void)
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 = GetModuleHandle(NULL);
358 class.hCursor = NULL;
359 class.hbrBackground = NULL;
360 class.lpszMenuName = NULL;
361 class.lpszClassName = "cursor_child";
363 SetLastError(0xdeadbeef);
364 ret = RegisterClass(&class);
365 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
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());
372 /* Let the parent know our HWND. */
373 PostMessage(parent, PROC_INIT, (WPARAM) child, 0);
375 /* Receive messages. */
376 while ((ret = GetMessage(&msg, 0, 0, 0)))
378 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
379 TranslateMessage(&msg);
380 DispatchMessage(&msg);
384 static void do_parent(void)
386 char path_name[MAX_PATH];
387 PROCESS_INFORMATION info;
388 STARTUPINFOA startup;
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 = GetModuleHandle(NULL);
400 class.hCursor = NULL;
401 class.hbrBackground = NULL;
402 class.lpszMenuName = NULL;
403 class.lpszClassName = "cursor_parent";
405 SetLastError(0xdeadbeef);
406 ret = RegisterClass(&class);
407 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
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());
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;
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;
424 /* Wait for child window handle. */
425 while ((child == 0) && (ret = GetMessage(&msg, parent, 0, 0)))
427 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
428 TranslateMessage(&msg);
429 DispatchMessage(&msg);
433 static void finish_child_process(void)
435 SendMessage(child, WM_CLOSE, 0, 0);
436 winetest_wait_child_process( child_process );
437 CloseHandle(child_process);
440 static void test_child_process(void)
442 static const BYTE bmp_bits[4096];
448 /* Create and set a dummy cursor. */
450 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
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);
459 cursor = CreateIconIndirect(&cursorInfo);
460 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
464 /* Destroy the cursor. */
465 SendMessage(child, WM_USER+1, 0, (LPARAM) cursor);
468 static BOOL color_match(COLORREF a, COLORREF b)
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.
473 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
476 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
477 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
485 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
486 ok(copy != NULL, "CopyImage() failed\n");
489 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
490 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
491 orig_is_dib = (origBitmap.bmBits != NULL);
492 copy_is_dib = (copyBitmap.bmBits != NULL);
494 if (copy_is_dib && dibExpected
495 && copyBitmap.bmBitsPixel == 24
496 && (expectedDepth == 16 || expectedDepth == 32))
498 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
499 if (GetVersion() & 0x80000000)
505 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
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 */
512 expectedDepth = origBitmap.bmBitsPixel;
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);
529 static void test_CopyImage_Bitmap(int depth)
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;
547 for (i=0; i < 256; i++)
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;
555 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
557 /* Create a device-dependent bitmap (DDB) */
558 screenDC = GetDC(NULL);
559 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
560 if (depth == 1 || depth == screen_depth)
562 ddb = CreateBitmap(2, 2, 1, depth, NULL);
568 ReleaseDC(NULL, screenDC);
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);
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);
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);
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);
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);
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);
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);
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);
624 /* Special case: A monochrome DIB is converted to a monochrome DDB if
625 the colors in the color table are black and white.
627 Skip this test on Windows 95, it always creates a monochrome DDB
630 if (!(GetVersion() & 0x80000000))
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;
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);
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;
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);
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;
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);
679 HeapFree(GetProcessHeap(), 0, info);
682 static void test_initial_cursor(void)
684 HCURSOR cursor, cursor2;
687 cursor = GetCursor();
689 /* Check what handle GetCursor() returns if a cursor is not set yet. */
690 SetLastError(0xdeadbeef);
691 cursor2 = LoadCursor(NULL, IDC_WAIT);
693 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
695 error = GetLastError();
696 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
699 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_bpp, int line)
703 BITMAP bmMask, bmColor;
705 ret = GetIconInfo(hIcon, &info);
706 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
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");
713 ret = GetObject(info.hbmMask, sizeof(bmMask), &bmMask);
714 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
717 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
725 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
728 ret = GetObject(info.hbmColor, sizeof(bmColor), &bmColor);
729 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
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);
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_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
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_cy * 2, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
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());
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());
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());
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);
780 #define test_icon_info(a,b,c,d) test_icon_info_dbg((a),(b),(c),(d),__LINE__)
782 static void test_CreateIcon(void)
784 static const BYTE bmp_bits[1024];
786 HBITMAP hbmMask, hbmColor;
794 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
796 /* these crash under XP
797 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
798 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
801 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
802 ok(hIcon != 0, "CreateIcon failed\n");
803 test_icon_info(hIcon, 16, 16, 1);
806 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
807 ok(hIcon != 0, "CreateIcon failed\n");
808 test_icon_info(hIcon, 16, 16, display_bpp);
811 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
812 ok(hbmMask != 0, "CreateBitmap failed\n");
813 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
814 ok(hbmColor != 0, "CreateBitmap failed\n");
821 SetLastError(0xdeadbeaf);
822 hIcon = CreateIconIndirect(&info);
823 ok(!hIcon, "CreateIconIndirect should fail\n");
824 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
830 info.hbmColor = hbmColor;
831 SetLastError(0xdeadbeaf);
832 hIcon = CreateIconIndirect(&info);
833 ok(!hIcon, "CreateIconIndirect should fail\n");
834 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
839 info.hbmMask = hbmMask;
840 info.hbmColor = hbmColor;
841 hIcon = CreateIconIndirect(&info);
842 ok(hIcon != 0, "CreateIconIndirect failed\n");
843 test_icon_info(hIcon, 16, 16, display_bpp);
846 DeleteObject(hbmMask);
847 DeleteObject(hbmColor);
849 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
850 ok(hbmMask != 0, "CreateBitmap failed\n");
855 info.hbmMask = hbmMask;
857 SetLastError(0xdeadbeaf);
858 hIcon = CreateIconIndirect(&info);
859 ok(hIcon != 0, "CreateIconIndirect failed\n");
860 test_icon_info(hIcon, 16, 16, 1);
863 DeleteObject(hbmMask);
864 DeleteObject(hbmColor);
866 /* test creating an icon from a DIB section */
868 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
869 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
870 bmpinfo->bmiHeader.biWidth = 32;
871 bmpinfo->bmiHeader.biHeight = 32;
872 bmpinfo->bmiHeader.biPlanes = 1;
873 bmpinfo->bmiHeader.biBitCount = 8;
874 bmpinfo->bmiHeader.biCompression = BI_RGB;
875 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
876 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
878 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
879 bmpinfo->bmiHeader.biBitCount = 1;
880 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
881 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
883 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
888 info.hbmMask = hbmColor;
889 info.hbmColor = hbmMask;
890 SetLastError(0xdeadbeaf);
891 hIcon = CreateIconIndirect(&info);
892 ok(hIcon != 0, "CreateIconIndirect failed\n");
893 test_icon_info(hIcon, 32, 32, 8);
895 DeleteObject(hbmColor);
897 bmpinfo->bmiHeader.biBitCount = 16;
898 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
899 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
901 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
906 info.hbmMask = hbmColor;
907 info.hbmColor = hbmMask;
908 SetLastError(0xdeadbeaf);
909 hIcon = CreateIconIndirect(&info);
910 ok(hIcon != 0, "CreateIconIndirect failed\n");
911 test_icon_info(hIcon, 32, 32, 8);
913 DeleteObject(hbmColor);
915 bmpinfo->bmiHeader.biBitCount = 32;
916 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
917 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
919 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
924 info.hbmMask = hbmColor;
925 info.hbmColor = hbmMask;
926 SetLastError(0xdeadbeaf);
927 hIcon = CreateIconIndirect(&info);
928 ok(hIcon != 0, "CreateIconIndirect failed\n");
929 test_icon_info(hIcon, 32, 32, 8);
932 DeleteObject(hbmMask);
933 DeleteObject(hbmColor);
934 HeapFree( GetProcessHeap(), 0, bmpinfo );
939 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
941 static unsigned char gifimage[35] = {
942 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
943 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
948 static unsigned char jpgimage[285] = {
949 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
950 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
951 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
952 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
953 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
954 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
955 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
956 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
957 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
958 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
959 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
960 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
961 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
962 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
963 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
964 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
965 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
966 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
970 static unsigned char pngimage[285] = {
971 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
972 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
973 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
974 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
975 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
976 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
977 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
980 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
981 zeroes, gap is 0xFF. */
982 static unsigned char bmpimage[70] = {
983 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
984 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
985 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
986 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
987 0xFF,0xFF,0x00,0x00,0x00,0x00
990 /* 1x1 pixel bmp using BITMAPCOREHEADER */
991 static unsigned char bmpcoreimage[38] = {
992 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
993 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
994 0x55,0x00,0x00,0x00,0x00,0x00
998 static unsigned char gif4pixel[42] = {
999 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1000 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1001 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1004 static const DWORD biSize_tests[] = {
1006 sizeof(BITMAPCOREHEADER) - 1,
1007 sizeof(BITMAPCOREHEADER) + 1,
1008 sizeof(BITMAPINFOHEADER) - 1,
1009 sizeof(BITMAPINFOHEADER) + 1,
1010 sizeof(BITMAPV4HEADER) - 1,
1011 sizeof(BITMAPV4HEADER) + 1,
1012 sizeof(BITMAPV5HEADER) - 1,
1013 sizeof(BITMAPV5HEADER) + 1,
1014 (sizeof(BITMAPCOREHEADER) + sizeof(BITMAPINFOHEADER)) / 2,
1015 (sizeof(BITMAPV4HEADER) + sizeof(BITMAPV5HEADER)) / 2,
1020 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1022 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1026 DWORD ret, pixel = 0;
1027 HDC hdc = GetDC(NULL);
1029 ret = GetObject(hbm, sizeof(bm), &bm);
1030 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1032 memset(&bmi, 0, sizeof(bmi));
1033 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1034 bmi.bmiHeader.biWidth = bm.bmWidth;
1035 bmi.bmiHeader.biHeight = bm.bmHeight;
1036 bmi.bmiHeader.biPlanes = 1;
1037 bmi.bmiHeader.biBitCount= 24;
1038 bmi.bmiHeader.biCompression= BI_RGB;
1039 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
1040 ok(ret == bm.bmHeight, "%s: %d lines were converted, not %d\n", test_desc, ret, bm.bmHeight);
1042 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1045 static void test_LoadImageFile(const char * test_desc, unsigned char * image_data,
1046 unsigned int image_size, const char * ext, BOOL expect_success)
1050 DWORD error, bytes_written;
1053 strcpy(filename, "test.");
1054 strcat(filename, ext);
1056 /* Create the test image. */
1057 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1058 FILE_ATTRIBUTE_NORMAL, NULL);
1059 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1060 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
1061 ok(ret && bytes_written == image_size, "test file created improperly.\n");
1062 CloseHandle(handle);
1064 /* Load as cursor. For all tested formats, this should fail */
1065 SetLastError(0xdeadbeef);
1066 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1067 ok(handle == NULL, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc);
1068 error = GetLastError();
1070 broken(error == 0xdeadbeef) || /* Win9x */
1071 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1072 "Last error: %u\n", error);
1073 if (handle != NULL) DestroyCursor(handle);
1075 /* Load as icon. For all tested formats, this should fail */
1076 SetLastError(0xdeadbeef);
1077 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
1078 ok(handle == NULL, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc);
1079 error = GetLastError();
1081 broken(error == 0xdeadbeef) || /* Win9x */
1082 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1083 "Last error: %u\n", error);
1084 if (handle != NULL) DestroyIcon(handle);
1086 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1087 SetLastError(0xdeadbeef);
1088 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
1089 error = GetLastError();
1091 error == 0xdeadbeef, /* Win9x, WinMe */
1092 "Last error: %u\n", error);
1094 if (expect_success) {
1095 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1096 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1098 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1100 if (handle != NULL) DeleteObject(handle);
1101 DeleteFileA(filename);
1104 static void test_LoadImage(void)
1108 DWORD error, bytes_written;
1109 CURSORICONFILEDIR *icon_data;
1110 CURSORICONFILEDIRENTRY *icon_entry;
1111 BITMAPINFOHEADER *icon_header, *bitmap_header;
1115 #define ICON_WIDTH 32
1116 #define ICON_HEIGHT 32
1117 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1120 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1121 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1123 /* Set icon data. */
1124 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
1125 icon_data->idReserved = 0;
1126 icon_data->idType = 1;
1127 icon_data->idCount = 1;
1129 icon_entry = icon_data->idEntries;
1130 icon_entry->bWidth = ICON_WIDTH;
1131 icon_entry->bHeight = ICON_HEIGHT;
1132 icon_entry->bColorCount = 0;
1133 icon_entry->bReserved = 0;
1134 icon_entry->xHotspot = 1;
1135 icon_entry->yHotspot = 1;
1136 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
1137 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
1139 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
1140 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1141 icon_header->biWidth = ICON_WIDTH;
1142 icon_header->biHeight = ICON_HEIGHT*2;
1143 icon_header->biPlanes = 1;
1144 icon_header->biBitCount = ICON_BPP;
1145 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1147 /* Create the icon. */
1148 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1149 FILE_ATTRIBUTE_NORMAL, NULL);
1150 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1151 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
1152 ok(ret && bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
1153 CloseHandle(handle);
1155 /* Test loading an icon as a cursor. */
1156 SetLastError(0xdeadbeef);
1157 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1158 ok(handle != NULL, "LoadImage() failed.\n");
1159 error = GetLastError();
1161 broken(error == 0xdeadbeef) || /* Win9x */
1162 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1163 "Last error: %u\n", error);
1165 /* Test the icon information. */
1166 SetLastError(0xdeadbeef);
1167 ret = GetIconInfo(handle, &icon_info);
1168 ok(ret, "GetIconInfo() failed.\n");
1169 error = GetLastError();
1170 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1174 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1175 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
1176 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
1177 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1179 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1182 if (pGetIconInfoExA)
1185 infoex.cbSize = sizeof(infoex);
1186 ret = pGetIconInfoExA( handle, &infoex );
1187 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1188 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1189 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1190 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1192 else win_skip( "GetIconInfoEx not available\n" );
1195 SetLastError(0xdeadbeef);
1196 ret = DestroyCursor(handle);
1197 ok(ret, "DestroyCursor() failed.\n");
1198 error = GetLastError();
1199 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1201 HeapFree(GetProcessHeap(), 0, icon_data);
1202 DeleteFileA("icon.ico");
1204 /* Test a system icon */
1205 handle = LoadIcon( 0, IDI_HAND );
1206 ok(handle != NULL, "LoadImage() failed.\n");
1207 if (pGetIconInfoExA)
1209 ICONINFOEXA infoexA;
1210 ICONINFOEXW infoexW;
1211 infoexA.cbSize = sizeof(infoexA);
1212 ret = pGetIconInfoExA( handle, &infoexA );
1213 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1214 ok( infoexA.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexA.wResID );
1215 /* the A version is broken on 64-bit, it truncates the string after the first char */
1216 if (is_win64 && infoexA.szModName[0] && infoexA.szModName[1] == 0)
1217 trace( "GetIconInfoExA broken on Win64\n" );
1219 ok( GetModuleHandleA(infoexA.szModName) == GetModuleHandleA("user32.dll"),
1220 "GetIconInfoEx wrong module %s\n", infoexA.szModName );
1221 ok( infoexA.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA.szResName );
1222 infoexW.cbSize = sizeof(infoexW);
1223 ret = pGetIconInfoExW( handle, &infoexW );
1224 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1225 ok( infoexW.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexW.wResID );
1226 ok( GetModuleHandleW(infoexW.szModName) == GetModuleHandleA("user32.dll"),
1227 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW.szModName) );
1228 ok( infoexW.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW.szResName) );
1230 SetLastError(0xdeadbeef);
1231 DestroyIcon(handle);
1233 test_LoadImageFile("BMP", bmpimage, sizeof(bmpimage), "bmp", 1);
1234 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage, sizeof(bmpcoreimage), "bmp", 1);
1235 test_LoadImageFile("GIF", gifimage, sizeof(gifimage), "gif", 0);
1236 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel, sizeof(gif4pixel), "gif", 0);
1237 test_LoadImageFile("JPG", jpgimage, sizeof(jpgimage), "jpg", 0);
1238 test_LoadImageFile("PNG", pngimage, sizeof(pngimage), "png", 0);
1240 /* Check failure for broken BMP images */
1241 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1243 bitmap_header->biHeight = 65536;
1244 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1245 bitmap_header->biHeight = 1;
1247 bitmap_header->biWidth = 65536;
1248 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1249 bitmap_header->biWidth = 1;
1251 for (i = 0; i < ARRAY_SIZE(biSize_tests); i++) {
1252 bitmap_header->biSize = biSize_tests[i];
1253 test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
1255 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1260 static void test_CreateIconFromResource(void)
1265 BITMAPINFOHEADER *icon_header;
1269 #define ICON_RES_WIDTH 32
1270 #define ICON_RES_HEIGHT 32
1271 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1272 #define ICON_RES_BPP 32
1273 #define ICON_RES_SIZE \
1274 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1275 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1277 /* Set icon data. */
1278 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1280 /* Cursor resources have an extra hotspot, icon resources not. */
1284 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1285 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1286 icon_header->biWidth = ICON_WIDTH;
1287 icon_header->biHeight = ICON_HEIGHT*2;
1288 icon_header->biPlanes = 1;
1289 icon_header->biBitCount = ICON_BPP;
1290 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1292 /* Test creating a cursor. */
1293 SetLastError(0xdeadbeef);
1294 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1295 ok(handle != NULL, "Create cursor failed.\n");
1297 /* Test the icon information. */
1298 SetLastError(0xdeadbeef);
1299 ret = GetIconInfo(handle, &icon_info);
1300 ok(ret, "GetIconInfo() failed.\n");
1301 error = GetLastError();
1302 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1306 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1307 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1308 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1309 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1311 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1314 if (pGetIconInfoExA)
1317 infoex.cbSize = sizeof(infoex);
1318 ret = pGetIconInfoExA( handle, &infoex );
1319 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1320 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1321 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1322 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1326 SetLastError(0xdeadbeef);
1327 ret = DestroyCursor(handle);
1328 ok(ret, "DestroyCursor() failed.\n");
1329 error = GetLastError();
1330 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1332 /* Test creating an icon. */
1333 SetLastError(0xdeadbeef);
1334 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1336 ok(handle != NULL, "Create icon failed.\n");
1338 /* Test the icon information. */
1339 SetLastError(0xdeadbeef);
1340 ret = GetIconInfo(handle, &icon_info);
1341 ok(ret, "GetIconInfo() failed.\n");
1342 error = GetLastError();
1343 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1347 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
1348 /* Icons always have hotspot in the middle */
1349 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
1350 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
1351 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
1352 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1356 SetLastError(0xdeadbeef);
1357 ret = DestroyCursor(handle);
1358 ok(ret, "DestroyCursor() failed.\n");
1359 error = GetLastError();
1360 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1362 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1364 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1365 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1367 HeapFree(GetProcessHeap(), 0, hotspot);
1369 /* Test creating an animated cursor. */
1370 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1371 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1372 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1373 handle = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1374 ok(handle != NULL, "Create cursor failed.\n");
1376 /* Test the animated cursor's information. */
1377 SetLastError(0xdeadbeef);
1378 ret = GetIconInfo(handle, &icon_info);
1379 ok(ret, "GetIconInfo() failed.\n");
1380 error = GetLastError();
1381 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1385 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1386 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1387 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1388 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1390 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1394 SetLastError(0xdeadbeef);
1395 ret = DestroyCursor(handle);
1396 ok(ret, "DestroyCursor() failed.\n");
1397 error = GetLastError();
1398 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1401 static int check_cursor_data( HDC hdc, HCURSOR hCursor, void *data, int length)
1409 ret = GetIconInfo( hCursor, &iinfo );
1410 ok(ret, "GetIconInfo() failed\n");
1413 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ));
1414 ok(info != NULL, "HeapAlloc() failed\n");
1415 if (!info) return 0;
1417 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1418 info->bmiHeader.biWidth = 32;
1419 info->bmiHeader.biHeight = 32;
1420 info->bmiHeader.biPlanes = 1;
1421 info->bmiHeader.biBitCount = 32;
1422 info->bmiHeader.biCompression = BI_RGB;
1423 info->bmiHeader.biSizeImage = 32 * 32 * 4;
1424 info->bmiHeader.biXPelsPerMeter = 0;
1425 info->bmiHeader.biYPelsPerMeter = 0;
1426 info->bmiHeader.biClrUsed = 0;
1427 info->bmiHeader.biClrImportant = 0;
1428 image = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage );
1429 ok(image != NULL, "HeapAlloc() failed\n");
1430 if (!image) goto cleanup;
1431 ret = GetDIBits( hdc, iinfo.hbmColor, 0, 32, image, info, DIB_RGB_COLORS );
1432 ok(ret, "GetDIBits() failed\n");
1433 for (i = 0; ret && i < length / sizeof(COLORREF); i++)
1435 ret = color_match( ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1436 ok(ret, "%04x: Expected 0x%x, actually 0x%x\n", i, ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1439 HeapFree( GetProcessHeap(), 0, image );
1440 HeapFree( GetProcessHeap(), 0, info );
1444 static HCURSOR (WINAPI *pGetCursorFrameInfo)(HCURSOR hCursor, DWORD unk1, DWORD istep, DWORD *rate, DWORD *steps);
1445 static void test_GetCursorFrameInfo(void)
1447 DWORD frame_identifier[] = { 0x10Ad, 0xc001, 0x1c05 };
1448 HBITMAP bmp = NULL, bmpOld = NULL;
1450 BITMAPINFOHEADER *icon_header;
1451 BITMAPINFO bitmapInfo;
1459 if (!pGetCursorFrameInfo)
1461 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1465 hdc = CreateCompatibleDC(0);
1466 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1470 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1471 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1472 bitmapInfo.bmiHeader.biWidth = 3;
1473 bitmapInfo.bmiHeader.biHeight = 3;
1474 bitmapInfo.bmiHeader.biBitCount = 32;
1475 bitmapInfo.bmiHeader.biPlanes = 1;
1476 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1477 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1478 bmp = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1479 ok (bmp && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1482 bmpOld = SelectObject(hdc, bmp);
1484 #define ICON_RES_WIDTH 32
1485 #define ICON_RES_HEIGHT 32
1486 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1487 #define ICON_RES_BPP 32
1488 #define ICON_RES_SIZE \
1489 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1490 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1492 /* Set icon data. */
1493 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1495 /* Cursor resources have an extra hotspot, icon resources not. */
1499 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1500 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1501 icon_header->biWidth = ICON_WIDTH;
1502 icon_header->biHeight = ICON_HEIGHT*2;
1503 icon_header->biPlanes = 1;
1504 icon_header->biBitCount = ICON_BPP;
1505 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1507 /* Creating a static cursor. */
1508 SetLastError(0xdeadbeef);
1509 h1 = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1510 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1512 /* Check GetCursorFrameInfo behavior on a static cursor */
1513 rate = steps = 0xdead;
1514 h2 = pGetCursorFrameInfo(h1, 0xdead, 0xdead, &rate, &steps);
1515 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1516 ok(rate == 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1517 ok(steps == 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1519 /* Clean up static cursor. */
1520 SetLastError(0xdeadbeef);
1521 ret = DestroyCursor(h1);
1522 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1524 /* Creating a single-frame animated cursor. */
1525 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1526 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1527 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1528 memcpy( &empty_anicursor.frames[0].data.bmi_data.data[0], &frame_identifier[0], sizeof(DWORD) );
1529 SetLastError(0xdeadbeef);
1530 h1 = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1531 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1533 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1534 rate = steps = 0xdead;
1535 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1536 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1537 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1538 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1539 ok(rate == 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1540 ok(steps == empty_anicursor.header.header.num_steps,
1541 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1543 /* Clean up single-frame animated cursor. */
1544 SetLastError(0xdeadbeef);
1545 ret = DestroyCursor(h1);
1546 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1548 /* Creating a multi-frame animated cursor. */
1549 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1551 empty_anicursor3.frames[i].data.icon_info.idType = 2; /* type: cursor */
1552 empty_anicursor3.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1553 empty_anicursor3.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1554 memcpy( &empty_anicursor3.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1556 SetLastError(0xdeadbeef);
1557 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1558 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1560 /* Check number of steps in multi-frame animated cursor */
1562 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1564 ok(i == empty_anicursor3.header.header.num_steps,
1565 "Unexpected number of steps in cursor (%d != %d)\n",
1566 i, empty_anicursor3.header.header.num_steps);
1568 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1569 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1571 rate = steps = 0xdead;
1572 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1573 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1574 ret = check_cursor_data( hdc, h2, &frame_identifier[i], sizeof(DWORD) );
1575 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1576 ok(rate == empty_anicursor3.header.header.display_rate,
1577 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1578 rate, empty_anicursor3.header.header.display_rate);
1579 ok(steps == empty_anicursor3.header.header.num_steps,
1580 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1581 steps, empty_anicursor3.header.header.num_steps);
1584 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1585 rate = steps = 0xdead;
1586 h2 = pGetCursorFrameInfo(h1, 0xdead, 3, &rate, &steps);
1587 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1588 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1589 || broken(rate == ~0) /*win2k (sporadic)*/,
1590 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1591 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1592 || broken(steps == 0) /*win2k (sporadic)*/,
1593 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps);
1595 /* Clean up multi-frame animated cursor. */
1596 SetLastError(0xdeadbeef);
1597 ret = DestroyCursor(h1);
1598 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1600 /* Create a multi-frame animated cursor with num_steps == 1 */
1601 empty_anicursor3.header.header.num_steps = 1;
1602 SetLastError(0xdeadbeef);
1603 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1604 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1606 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1608 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1610 ok(i == empty_anicursor3.header.header.num_steps,
1611 "Unexpected number of steps in cursor (%d != %d)\n",
1612 i, empty_anicursor3.header.header.num_steps);
1614 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1615 rate = steps = 0xdead;
1616 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1617 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1618 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1619 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1620 ok(rate == empty_anicursor3.header.header.display_rate,
1621 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1622 rate, empty_anicursor3.header.header.display_rate);
1623 ok(steps == ~0 || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/,
1624 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps);
1626 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1627 rate = steps = 0xdead;
1628 h2 = pGetCursorFrameInfo(h1, 0xdead, 1, &rate, &steps);
1629 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1630 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1631 || broken(rate == ~0) /*win2k (sporadic)*/,
1632 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1633 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1634 || broken(steps == 0) /*win2k (sporadic)*/,
1635 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps);
1637 /* Clean up multi-frame animated cursor. */
1638 SetLastError(0xdeadbeef);
1639 ret = DestroyCursor(h1);
1640 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1642 /* Creating a multi-frame animated cursor with rate data. */
1643 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1645 empty_anicursor3_seq.frames[i].data.icon_info.idType = 2; /* type: cursor */
1646 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1647 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1648 memcpy( &empty_anicursor3_seq.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1650 SetLastError(0xdeadbeef);
1651 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3_seq, sizeof(empty_anicursor3_seq), FALSE, 0x00030000);
1652 ok(h1 != NULL, "Create cursor failed (error = %x).\n", GetLastError());
1654 /* Check number of steps in multi-frame animated cursor with rate data */
1656 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1658 ok(i == empty_anicursor3_seq.header.header.num_steps,
1659 "Unexpected number of steps in cursor (%d != %d)\n",
1660 i, empty_anicursor3_seq.header.header.num_steps);
1662 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1663 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1665 int frame_id = empty_anicursor3_seq.seq.order[i];
1667 rate = steps = 0xdead;
1668 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1669 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1670 ret = check_cursor_data( hdc, h2, &frame_identifier[frame_id], sizeof(DWORD) );
1671 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1672 ok(rate == empty_anicursor3_seq.rates.rate[i],
1673 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1674 rate, empty_anicursor3_seq.rates.rate[i]);
1675 ok(steps == empty_anicursor3_seq.header.header.num_steps,
1676 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1677 steps, empty_anicursor3_seq.header.header.num_steps);
1680 /* Clean up multi-frame animated cursor with rate data. */
1681 SetLastError(0xdeadbeef);
1682 ret = DestroyCursor(h1);
1683 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1686 if(bmpOld) SelectObject(hdc, bmpOld);
1687 if(bmp) DeleteObject(bmp);
1688 if(hdc) DeleteDC(hdc);
1691 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1692 BOOL maskvalue, UINT32 *color, int colorSize)
1695 BITMAPINFO bitmapInfo;
1696 void *buffer = NULL;
1697 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1699 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1700 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1701 bitmapInfo.bmiHeader.biWidth = width;
1702 bitmapInfo.bmiHeader.biHeight = height;
1703 bitmapInfo.bmiHeader.biPlanes = 1;
1704 bitmapInfo.bmiHeader.biBitCount = bpp;
1705 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1706 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1708 iconInfo.fIcon = TRUE;
1709 iconInfo.xHotspot = 0;
1710 iconInfo.yHotspot = 0;
1712 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1713 if(!iconInfo.hbmMask) return NULL;
1715 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1716 if(!iconInfo.hbmColor || !buffer)
1718 DeleteObject(iconInfo.hbmMask);
1722 memcpy(buffer, color, colorSize);
1724 return CreateIconIndirect(&iconInfo);
1727 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1731 COLORREF modern_expected, legacy_expected, result;
1733 color[0] = 0x00A0B0C0;
1734 color[1] = alpha ? 0xFF000000 : 0x00000000;
1735 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1736 legacy_expected = 0x00C0B0A0;
1738 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1741 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1744 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1746 DrawIcon(hdc, 0, 0, hicon);
1748 result = GetPixel(hdc, 0, 0);
1749 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1750 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1751 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1752 "Got %06X from line %d\n",
1753 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1754 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1757 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1758 COLORREF modern_expected, COLORREF legacy_expected, int line)
1761 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1763 SetPixelV(hdc, 0, 0, background);
1764 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1765 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1766 DrawIcon(hdc, 0, 0, hicon);
1767 result = GetPixel(hdc, 0, 0);
1769 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1770 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1771 "Overlaying Mask %d on Color %06X with DrawIcon. "
1772 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1773 maskvalue, color, modern_expected, legacy_expected, result, line);
1775 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1777 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1778 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1779 "Overlaying Mask %d on Color %06X with DrawIcon. "
1780 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1781 maskvalue, color, modern_expected, legacy_expected, result, line);
1783 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1785 ok (color_match(result, background),
1786 "Overlaying Mask %d on Color %06X with DrawIcon. "
1787 "Expected unchanged background color %06X. Got %06X from line %d\n",
1788 maskvalue, color, background, result, line);
1791 static void test_DrawIcon(void)
1793 BITMAPINFO bitmapInfo;
1795 HBITMAP bmpDst = NULL;
1796 HBITMAP bmpOld = NULL;
1799 hdcDst = CreateCompatibleDC(0);
1800 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1804 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1806 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1810 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1811 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1812 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1813 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1814 bitmapInfo.bmiHeader.biBitCount = 32;
1815 bitmapInfo.bmiHeader.biPlanes = 1;
1816 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1817 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1819 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1820 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1821 if (!bmpDst || !bits)
1823 bmpOld = SelectObject(hdcDst, bmpDst);
1825 /* Mask is only heeded if alpha channel is always zero */
1826 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1827 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1829 /* Test alpha blending */
1830 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1831 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1832 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1834 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1835 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1836 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1837 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1839 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1840 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1842 /* Test detecting of alpha channel */
1843 /* If a single pixel's alpha channel is non-zero, the icon
1844 will be alpha blended, otherwise it will be draw with
1846 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1847 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1851 SelectObject(hdcDst, bmpOld);
1853 DeleteObject(bmpDst);
1858 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1859 COLORREF modern_expected, COLORREF legacy_expected, int line)
1862 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1864 SetPixelV(hdc, 0, 0, background);
1865 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1866 result = GetPixel(hdc, 0, 0);
1868 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1869 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1870 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1871 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1872 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1875 static void test_DrawIconEx(void)
1877 BITMAPINFO bitmapInfo;
1879 HBITMAP bmpDst = NULL;
1880 HBITMAP bmpOld = NULL;
1883 hdcDst = CreateCompatibleDC(0);
1884 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1888 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1890 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1894 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1895 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1896 bitmapInfo.bmiHeader.biWidth = 1;
1897 bitmapInfo.bmiHeader.biHeight = 1;
1898 bitmapInfo.bmiHeader.biBitCount = 32;
1899 bitmapInfo.bmiHeader.biPlanes = 1;
1900 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1901 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1902 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1903 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1904 if (!bmpDst || !bits)
1906 bmpOld = SelectObject(hdcDst, bmpDst);
1908 /* Test null, image only, and mask only drawing */
1909 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1910 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1912 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00000000, 0x00000000, __LINE__);
1913 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1915 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1916 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1918 /* Test normal drawing */
1919 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1920 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1921 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1923 /* Test alpha blending */
1924 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1925 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1927 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1928 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1929 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1930 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1932 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1933 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1935 /* Test detecting of alpha channel */
1936 /* If a single pixel's alpha channel is non-zero, the icon
1937 will be alpha blended, otherwise it will be draw with
1939 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1940 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1944 SelectObject(hdcDst, bmpOld);
1946 DeleteObject(bmpDst);
1951 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1953 COLORREF result, background;
1955 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1956 background = 0x00FFFFFF;
1957 /* Set color of the 2 pixels that will be checked afterwards */
1958 SetPixelV(hdc, 0, 0, background);
1959 SetPixelV(hdc, 2, 2, background);
1961 /* Let DrawState calculate the size of the icon (it's 1x1) */
1962 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1964 result = GetPixel(hdc, 0, 0);
1965 passed[0] = color_match(result, background);
1966 result = GetPixel(hdc, 2, 2);
1967 passed[0] = passed[0] & color_match(result, background);
1969 /* Check if manually specifying the icon size DOESN'T work */
1971 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1972 * size in which it should be ultimately drawn. Therefore giving
1973 * width/height 2x2 if the icon is only 1x1 pixels in size should
1974 * result in drawing it with size 1x1. The size parameters must be
1975 * ignored if a Icon has to be drawn! */
1976 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1978 result = GetPixel(hdc, 0, 0);
1979 passed[1] = color_match(result, background);
1980 result = GetPixel(hdc, 2, 2);
1981 passed[1] = passed[0] & color_match(result, background);
1983 if(!passed[0]&&!passed[1])
1985 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
1986 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
1987 "Color %06X with flags %08X. Line %d\n",
1988 maskvalue, color, (DST_ICON | flags), line);
1991 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1992 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
1993 "Mask %d on Color %06X with flags %08X. Line %d\n",
1994 maskvalue, color, (DST_ICON | flags), line);
1997 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1998 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
1999 "Color %06X with flags %08X. Line %d\n",
2000 maskvalue, color, (DST_ICON | flags), line);
2003 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
2004 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
2007 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2009 /* Set color of the pixel that will be checked afterwards */
2010 SetPixelV(hdc, 1, 1, background);
2012 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
2014 /* Check the color of the pixel is correct */
2015 result = GetPixel(hdc, 1, 1);
2017 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
2018 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
2019 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2020 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2021 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
2024 static void test_DrawState(void)
2026 BITMAPINFO bitmapInfo;
2028 HBITMAP bmpDst = NULL;
2029 HBITMAP bmpOld = NULL;
2032 hdcDst = CreateCompatibleDC(0);
2033 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2037 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
2039 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2043 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
2044 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2045 bitmapInfo.bmiHeader.biWidth = 3;
2046 bitmapInfo.bmiHeader.biHeight = 3;
2047 bitmapInfo.bmiHeader.biBitCount = 32;
2048 bitmapInfo.bmiHeader.biPlanes = 1;
2049 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2050 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2051 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
2052 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2053 if (!bmpDst || !bits)
2055 bmpOld = SelectObject(hdcDst, bmpDst);
2057 /* potential flags to test with DrawState are: */
2058 /* DSS_DISABLED embosses the icon */
2059 /* DSS_MONO draw Icon using a brush as parameter 5 */
2060 /* DSS_NORMAL draw Icon without any modifications */
2061 /* DSS_UNION draw the Icon dithered */
2063 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
2064 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
2068 SelectObject(hdcDst, bmpOld);
2070 DeleteObject(bmpDst);
2075 static DWORD parent_id;
2077 static DWORD CALLBACK set_cursor_thread( void *arg )
2081 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2084 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2085 ok( ret, "AttachThreadInput failed\n" );
2087 if (arg) ret = SetCursor( (HCURSOR)arg );
2088 else ret = GetCursor();
2089 return (DWORD_PTR)ret;
2092 static void test_SetCursor(void)
2094 static const BYTE bmp_bits[4096];
2095 ICONINFO cursorInfo;
2096 HCURSOR cursor, old_cursor, global_cursor = 0;
2097 DWORD error, id, result;
2105 memset( &info, 0, sizeof(info) );
2106 info.cbSize = sizeof(info);
2107 if (!pGetCursorInfo( &info ))
2109 win_skip( "GetCursorInfo not working\n" );
2110 pGetCursorInfo = NULL;
2112 else global_cursor = info.hCursor;
2114 cursor = GetCursor();
2115 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2116 WaitForSingleObject( thread, 1000 );
2117 GetExitCodeThread( thread, &result );
2118 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
2121 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2124 cursorInfo.fIcon = FALSE;
2125 cursorInfo.xHotspot = 0;
2126 cursorInfo.yHotspot = 0;
2127 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2128 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2130 cursor = CreateIconIndirect(&cursorInfo);
2131 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2132 old_cursor = SetCursor( cursor );
2136 info.cbSize = sizeof(info);
2137 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2138 /* global cursor doesn't change since we don't have a window */
2139 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2140 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2142 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2143 WaitForSingleObject( thread, 1000 );
2144 GetExitCodeThread( thread, &result );
2145 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2148 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2149 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2150 WaitForSingleObject( thread, 1000 );
2151 GetExitCodeThread( thread, &result );
2152 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2154 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2155 WaitForSingleObject( thread, 1000 );
2156 GetExitCodeThread( thread, &result );
2157 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2158 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2160 parent_id = GetCurrentThreadId();
2161 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2162 WaitForSingleObject( thread, 1000 );
2163 GetExitCodeThread( thread, &result );
2164 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2165 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
2169 info.cbSize = sizeof(info);
2170 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2171 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2172 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2174 SetCursor( old_cursor );
2175 DestroyCursor( cursor );
2177 SetLastError( 0xdeadbeef );
2178 cursor = SetCursor( (HCURSOR)0xbadbad );
2179 error = GetLastError();
2180 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
2181 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
2182 "wrong error %u\n", error );
2186 info.cbSize = sizeof(info);
2187 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2188 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2189 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2193 static HANDLE event_start, event_next;
2195 static DWORD CALLBACK show_cursor_thread( void *arg )
2197 DWORD count = (DWORD_PTR)arg;
2200 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2203 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2204 ok( ret, "AttachThreadInput failed\n" );
2206 if (!count) ret = ShowCursor( FALSE );
2207 else while (count--) ret = ShowCursor( TRUE );
2208 SetEvent( event_start );
2209 WaitForSingleObject( event_next, 2000 );
2213 static void test_ShowCursor(void)
2222 memset( &info, 0, sizeof(info) );
2223 info.cbSize = sizeof(info);
2224 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2225 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2228 event_start = CreateEvent( NULL, FALSE, FALSE, NULL );
2229 event_next = CreateEvent( NULL, FALSE, FALSE, NULL );
2231 count = ShowCursor( TRUE );
2232 ok( count == 1, "wrong count %d\n", count );
2233 count = ShowCursor( TRUE );
2234 ok( count == 2, "wrong count %d\n", count );
2235 count = ShowCursor( FALSE );
2236 ok( count == 1, "wrong count %d\n", count );
2237 count = ShowCursor( FALSE );
2238 ok( count == 0, "wrong count %d\n", count );
2239 count = ShowCursor( FALSE );
2240 ok( count == -1, "wrong count %d\n", count );
2241 count = ShowCursor( FALSE );
2242 ok( count == -2, "wrong count %d\n", count );
2246 info.cbSize = sizeof(info);
2247 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2248 /* global show count is not affected since we don't have a window */
2249 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2253 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2254 WaitForSingleObject( event_start, 1000 );
2255 count = ShowCursor( FALSE );
2256 ok( count == -3, "wrong count %d\n", count );
2257 SetEvent( event_next );
2258 WaitForSingleObject( thread, 1000 );
2259 GetExitCodeThread( thread, &result );
2260 ok( result == -1, "wrong thread count %d\n", result );
2261 count = ShowCursor( FALSE );
2262 ok( count == -4, "wrong count %d\n", count );
2264 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
2265 WaitForSingleObject( event_start, 1000 );
2266 count = ShowCursor( TRUE );
2267 ok( count == -3, "wrong count %d\n", count );
2268 SetEvent( event_next );
2269 WaitForSingleObject( thread, 1000 );
2270 GetExitCodeThread( thread, &result );
2271 ok( result == 1, "wrong thread count %d\n", result );
2272 count = ShowCursor( TRUE );
2273 ok( count == -2, "wrong count %d\n", count );
2275 parent_id = GetCurrentThreadId();
2276 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2277 WaitForSingleObject( event_start, 1000 );
2278 count = ShowCursor( TRUE );
2279 ok( count == -2, "wrong count %d\n", count );
2280 SetEvent( event_next );
2281 WaitForSingleObject( thread, 1000 );
2282 GetExitCodeThread( thread, &result );
2283 ok( result == -3, "wrong thread count %d\n", result );
2284 count = ShowCursor( FALSE );
2285 ok( count == -2, "wrong count %d\n", count );
2287 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
2288 WaitForSingleObject( event_start, 1000 );
2289 count = ShowCursor( TRUE );
2290 ok( count == 2, "wrong count %d\n", count );
2291 SetEvent( event_next );
2292 WaitForSingleObject( thread, 1000 );
2293 GetExitCodeThread( thread, &result );
2294 ok( result == 1, "wrong thread count %d\n", result );
2295 count = ShowCursor( FALSE );
2296 ok( count == -2, "wrong count %d\n", count );
2300 info.cbSize = sizeof(info);
2301 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2302 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2305 count = ShowCursor( TRUE );
2306 ok( count == -1, "wrong count %d\n", count );
2307 count = ShowCursor( TRUE );
2308 ok( count == 0, "wrong count %d\n", count );
2312 info.cbSize = sizeof(info);
2313 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2314 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2319 static void test_DestroyCursor(void)
2321 static const BYTE bmp_bits[4096];
2322 ICONINFO cursorInfo, new_info;
2323 HCURSOR cursor, cursor2, new_cursor;
2330 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2333 cursorInfo.fIcon = FALSE;
2334 cursorInfo.xHotspot = 0;
2335 cursorInfo.yHotspot = 0;
2336 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2337 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2339 cursor = CreateIconIndirect(&cursorInfo);
2340 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2346 SetLastError(0xdeadbeef);
2347 ret = DestroyCursor(cursor);
2348 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2349 error = GetLastError();
2350 ok(error == 0xdeadbeef, "Last error: %u\n", error);
2352 new_cursor = GetCursor();
2353 if (ret) /* win9x replaces cursor by another one on destroy */
2354 ok(new_cursor != cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2356 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2358 SetLastError(0xdeadbeef);
2359 ret = GetIconInfo( cursor, &new_info );
2360 ok( !ret || broken(ret), /* nt4 */ "GetIconInfo succeeded\n" );
2361 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2362 broken(GetLastError() == 0xdeadbeef), /* win9x */
2363 "wrong error %u\n", GetLastError() );
2365 if (ret) /* nt4 delays destruction until cursor changes */
2367 DeleteObject( new_info.hbmColor );
2368 DeleteObject( new_info.hbmMask );
2370 SetLastError(0xdeadbeef);
2371 ret = DestroyCursor( cursor );
2372 ok( !ret, "DestroyCursor succeeded\n" );
2373 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2374 "wrong error %u\n", GetLastError() );
2376 SetLastError(0xdeadbeef);
2377 cursor2 = SetCursor( cursor );
2378 ok( cursor2 == cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2379 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2380 "wrong error %u\n", GetLastError() );
2384 SetLastError(0xdeadbeef);
2385 cursor2 = CopyCursor( cursor );
2386 ok(!cursor2, "CopyCursor succeeded\n" );
2387 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2388 broken(GetLastError() == 0xdeadbeef), /* win9x */
2389 "wrong error %u\n", GetLastError() );
2391 SetLastError(0xdeadbeef);
2392 ret = DestroyCursor( cursor );
2393 if (new_cursor != cursor) /* win9x */
2394 ok( ret, "DestroyCursor succeeded\n" );
2396 ok( !ret, "DestroyCursor succeeded\n" );
2397 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2398 "wrong error %u\n", GetLastError() );
2400 SetLastError(0xdeadbeef);
2401 cursor2 = SetCursor( cursor );
2402 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2403 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2404 "wrong error %u\n", GetLastError() );
2407 cursor2 = GetCursor();
2408 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2410 SetLastError(0xdeadbeef);
2411 cursor2 = SetCursor( 0 );
2412 if (new_cursor != cursor) /* win9x */
2413 ok(cursor2 == new_cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2415 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2416 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2418 cursor2 = GetCursor();
2419 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2421 SetLastError(0xdeadbeef);
2422 ret = DestroyCursor(cursor);
2423 if (new_cursor != cursor) /* win9x */
2424 ok( ret, "DestroyCursor succeeded\n" );
2426 ok( !ret, "DestroyCursor succeeded\n" );
2427 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2428 "wrong error %u\n", GetLastError() );
2430 DeleteObject(cursorInfo.hbmMask);
2431 DeleteObject(cursorInfo.hbmColor);
2433 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2434 cursor = LoadCursor(NULL, IDC_ARROW);
2436 SetLastError(0xdeadbeef);
2437 ret = DestroyCursor(cursor);
2438 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2439 error = GetLastError();
2440 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2442 /* Try setting the cursor to a destroyed OEM cursor. */
2443 SetLastError(0xdeadbeef);
2445 error = GetLastError();
2446 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2448 /* Check if LoadCursor() returns the same handle with the same icon. */
2449 cursor2 = LoadCursor(NULL, IDC_ARROW);
2450 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2452 /* Check if LoadCursor() returns the same handle with a different icon. */
2453 cursor2 = LoadCursor(NULL, IDC_WAIT);
2454 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2457 START_TEST(cursoricon)
2459 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2460 pGetIconInfoExA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2461 pGetIconInfoExW = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2462 pGetCursorFrameInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2463 test_argc = winetest_get_mainargs(&test_argv);
2467 /* Child process. */
2468 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2470 ok(parent != NULL, "Parent not found.\n");
2478 test_CopyImage_Bitmap(1);
2479 test_CopyImage_Bitmap(4);
2480 test_CopyImage_Bitmap(8);
2481 test_CopyImage_Bitmap(16);
2482 test_CopyImage_Bitmap(24);
2483 test_CopyImage_Bitmap(32);
2484 test_initial_cursor();
2487 test_CreateIconFromResource();
2488 test_GetCursorFrameInfo();
2494 test_DestroyCursor();
2496 test_child_process();
2497 finish_child_process();