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
28 #include "wine/test.h"
47 } CURSORICONFILEDIRENTRY;
54 CURSORICONFILEDIRENTRY idEntries[1];
57 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
58 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
59 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
61 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
62 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
63 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
64 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
65 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
66 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
67 #define ANI_icon_ID RIFF_FOURCC('i', 'c', 'o', 'n')
68 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
70 #define ANI_FLAG_ICON 0x1
71 #define ANI_FLAG_SEQUENCE 0x2
90 CURSORICONFILEDIR icon_info; /* animated cursor frame information */
91 BITMAPINFOHEADER bmi_header; /* animated cursor frame header */
92 ani_data32x32x32 bmi_data; /* animated cursor frame DIB data */
96 DWORD chunk_id; /* ANI_anih_ID */
97 DWORD chunk_size; /* actual size of data */
98 ani_header header; /* animated cursor header */
102 DWORD chunk_id; /* ANI_LIST_ID */
103 DWORD chunk_size; /* actual size of data */
104 DWORD chunk_type; /* ANI_fram_ID */
108 DWORD chunk_id; /* ANI_icon_ID */
109 DWORD chunk_size; /* actual size of data */
110 ani_frame32x32x32 data; /* animated cursor frame */
111 } riff_icon32x32x32_t;
114 DWORD chunk_id; /* ANI_RIFF_ID */
115 DWORD chunk_size; /* actual size of data */
116 DWORD chunk_type; /* ANI_ACON_ID */
117 riff_header_t header; /* RIFF animated cursor header */
118 riff_list_t frame_list; /* RIFF animated cursor frame list info */
119 riff_icon32x32x32_t frames[1]; /* array of animated cursor frames */
123 DWORD chunk_id; /* ANI_RIFF_ID */
124 DWORD chunk_size; /* actual size of data */
125 DWORD chunk_type; /* ANI_ACON_ID */
126 riff_header_t header; /* RIFF animated cursor header */
127 riff_list_t frame_list; /* RIFF animated cursor frame list info */
128 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
132 DWORD chunk_id; /* ANI_rate_ID */
133 DWORD chunk_size; /* actual size of data */
134 DWORD rate[3]; /* animated cursor rate data */
138 DWORD chunk_id; /* ANI_seq__ID */
139 DWORD chunk_size; /* actual size of data */
140 DWORD order[3]; /* animated cursor sequence data */
144 DWORD chunk_id; /* ANI_RIFF_ID */
145 DWORD chunk_size; /* actual size of data */
146 DWORD chunk_type; /* ANI_ACON_ID */
147 riff_header_t header; /* RIFF animated cursor header */
148 riff_seq3_t seq; /* sequence data for three cursor frames */
149 riff_rate3_t rates; /* rate data for three cursor frames */
150 riff_list_t frame_list; /* RIFF animated cursor frame list info */
151 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
152 } riff_cursor3_seq_t;
154 #define EMPTY_ICON32 \
157 sizeof(ani_frame32x32x32), \
160 0x0, /* reserved */ \
161 0, /* type: icon(1), cursor(2) */ \
167 0, /* color count */ \
168 0x0, /* reserved */ \
169 16, /* x hotspot */ \
170 16, /* y hotspot */ \
171 sizeof(ani_data32x32x32), /* DIB size */ \
172 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
177 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
179 32*2, /* actual height times two */ \
182 BI_RGB, /* compression */ \
183 0, /* image size */ \
184 0, /* biXPelsPerMeter */ \
185 0, /* biYPelsPerMeter */ \
187 0 /* biClrImportant */ \
189 /* DIB data: left uninitialized */ \
193 riff_cursor1_t empty_anicursor = {
195 sizeof(empty_anicursor) - sizeof(DWORD)*2,
208 10, /* display rate in jiffies */
209 ANI_FLAG_ICON /* flags */
214 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
222 riff_cursor3_t empty_anicursor3 = {
224 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
237 0xbeef, /* display rate in jiffies */
238 ANI_FLAG_ICON /* flags */
243 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
253 riff_cursor3_seq_t empty_anicursor3_seq = {
255 sizeof(empty_anicursor3_seq) - sizeof(DWORD)*2,
268 0xbeef, /* display rate in jiffies */
269 ANI_FLAG_ICON|ANI_FLAG_SEQUENCE /* flags */
274 sizeof(riff_seq3_t) - sizeof(DWORD)*2,
275 { 2, 0, 1} /* show frames in a uniquely identifiable order */
279 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
280 { 0xc0de, 0xcafe, 0xbabe}
284 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
296 static char **test_argv;
297 static int test_argc;
298 static HWND child = 0;
299 static HWND parent = 0;
300 static HANDLE child_process;
302 #define PROC_INIT (WM_USER+1)
304 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
305 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
306 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
308 static const int is_win64 = (sizeof(void *) > sizeof(int));
310 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
317 /* Destroy the cursor. */
319 SetLastError(0xdeadbeef);
320 ret = DestroyCursor((HCURSOR) lParam);
321 error = GetLastError();
322 ok(!ret || broken(ret) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
323 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD ||
324 error == 0xdeadbeef, /* vista */
325 "Last error: %u\n", error);
332 return DefWindowProc(hwnd, msg, wParam, lParam);
335 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
337 if (msg == PROC_INIT)
339 child = (HWND) wParam;
343 return DefWindowProc(hwnd, msg, wParam, lParam);
346 static void do_child(void)
352 /* Register a new class. */
353 class.style = CS_GLOBALCLASS;
354 class.lpfnWndProc = callback_child;
355 class.cbClsExtra = 0;
356 class.cbWndExtra = 0;
357 class.hInstance = GetModuleHandle(NULL);
359 class.hCursor = NULL;
360 class.hbrBackground = NULL;
361 class.lpszMenuName = NULL;
362 class.lpszClassName = "cursor_child";
364 SetLastError(0xdeadbeef);
365 ret = RegisterClass(&class);
366 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
368 /* Create a window. */
369 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
370 0, 0, 200, 200, 0, 0, 0, NULL);
371 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
373 /* Let the parent know our HWND. */
374 PostMessage(parent, PROC_INIT, (WPARAM) child, 0);
376 /* Receive messages. */
377 while ((ret = GetMessage(&msg, 0, 0, 0)))
379 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
380 TranslateMessage(&msg);
381 DispatchMessage(&msg);
385 static void do_parent(void)
387 char path_name[MAX_PATH];
388 PROCESS_INFORMATION info;
389 STARTUPINFOA startup;
394 /* Register a new class. */
395 class.style = CS_GLOBALCLASS;
396 class.lpfnWndProc = callback_parent;
397 class.cbClsExtra = 0;
398 class.cbWndExtra = 0;
399 class.hInstance = GetModuleHandle(NULL);
401 class.hCursor = NULL;
402 class.hbrBackground = NULL;
403 class.lpszMenuName = NULL;
404 class.lpszClassName = "cursor_parent";
406 SetLastError(0xdeadbeef);
407 ret = RegisterClass(&class);
408 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
410 /* Create a window. */
411 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
412 0, 0, 200, 200, 0, 0, 0, NULL);
413 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
415 /* Start child process. */
416 memset(&startup, 0, sizeof(startup));
417 startup.cb = sizeof(startup);
418 startup.dwFlags = STARTF_USESHOWWINDOW;
419 startup.wShowWindow = SW_SHOWNORMAL;
421 sprintf(path_name, "%s cursoricon %lx", test_argv[0], (INT_PTR)parent);
422 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
423 child_process = info.hProcess;
425 /* Wait for child window handle. */
426 while ((child == 0) && (ret = GetMessage(&msg, parent, 0, 0)))
428 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
429 TranslateMessage(&msg);
430 DispatchMessage(&msg);
434 static void finish_child_process(void)
436 SendMessage(child, WM_CLOSE, 0, 0);
437 winetest_wait_child_process( child_process );
438 CloseHandle(child_process);
441 static void test_child_process(void)
443 static const BYTE bmp_bits[4096];
449 /* Create and set a dummy cursor. */
451 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
454 cursorInfo.fIcon = FALSE;
455 cursorInfo.xHotspot = 0;
456 cursorInfo.yHotspot = 0;
457 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
458 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
460 cursor = CreateIconIndirect(&cursorInfo);
461 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
465 /* Destroy the cursor. */
466 SendMessage(child, WM_USER+1, 0, (LPARAM) cursor);
469 static BOOL color_match(COLORREF a, COLORREF b)
471 /* 5-bit accuracy is a sufficient test. This will match as long as
472 * colors are never truncated to less that 3x5-bit accuracy i.e.
474 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
477 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
478 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
486 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
487 ok(copy != NULL, "CopyImage() failed\n");
490 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
491 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
492 orig_is_dib = (origBitmap.bmBits != NULL);
493 copy_is_dib = (copyBitmap.bmBits != NULL);
495 if (copy_is_dib && dibExpected
496 && copyBitmap.bmBitsPixel == 24
497 && (expectedDepth == 16 || expectedDepth == 32))
499 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
500 if (GetVersion() & 0x80000000)
506 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
508 /* It's not forbidden to create a DIB section if the flag
509 LR_CREATEDIBSECTION is absent.
510 Windows 9x does this if the bitmap has a depth that doesn't
511 match the screen depth, Windows NT doesn't */
513 expectedDepth = origBitmap.bmBitsPixel;
516 ok((!(dibExpected ^ copy_is_dib)
517 && (copyBitmap.bmWidth == expectedWidth)
518 && (copyBitmap.bmHeight == expectedHeight)
519 && (copyBitmap.bmBitsPixel == expectedDepth)),
520 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
521 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
522 copyWidth, copyHeight, flags,
523 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
524 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
530 static void test_CopyImage_Bitmap(int depth)
539 /* Create a device-independent bitmap (DIB) */
540 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
541 info->bmiHeader.biSize = sizeof(info->bmiHeader);
542 info->bmiHeader.biWidth = 2;
543 info->bmiHeader.biHeight = 2;
544 info->bmiHeader.biPlanes = 1;
545 info->bmiHeader.biBitCount = depth;
546 info->bmiHeader.biCompression = BI_RGB;
548 for (i=0; i < 256; i++)
550 info->bmiColors[i].rgbRed = i;
551 info->bmiColors[i].rgbGreen = i;
552 info->bmiColors[i].rgbBlue = 255 - i;
553 info->bmiColors[i].rgbReserved = 0;
556 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
558 /* Create a device-dependent bitmap (DDB) */
559 screenDC = GetDC(NULL);
560 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
561 if (depth == 1 || depth == screen_depth)
563 ddb = CreateBitmap(2, 2, 1, depth, NULL);
569 ReleaseDC(NULL, screenDC);
573 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
574 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
575 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
576 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
578 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
579 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
580 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
581 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
583 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
584 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
585 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
586 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
588 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
589 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
590 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
591 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
592 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
599 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
600 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
601 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
602 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
605 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
606 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
607 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
608 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
610 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
611 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
612 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
613 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
615 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
616 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
617 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
618 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
619 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
625 /* Special case: A monochrome DIB is converted to a monochrome DDB if
626 the colors in the color table are black and white.
628 Skip this test on Windows 95, it always creates a monochrome DDB
631 if (!(GetVersion() & 0x80000000))
633 info->bmiHeader.biBitCount = 1;
634 info->bmiColors[0].rgbRed = 0xFF;
635 info->bmiColors[0].rgbGreen = 0;
636 info->bmiColors[0].rgbBlue = 0;
637 info->bmiColors[1].rgbRed = 0;
638 info->bmiColors[1].rgbGreen = 0xFF;
639 info->bmiColors[1].rgbBlue = 0;
641 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
642 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
643 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
644 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
645 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
648 info->bmiHeader.biBitCount = 1;
649 info->bmiColors[0].rgbRed = 0;
650 info->bmiColors[0].rgbGreen = 0;
651 info->bmiColors[0].rgbBlue = 0;
652 info->bmiColors[1].rgbRed = 0xFF;
653 info->bmiColors[1].rgbGreen = 0xFF;
654 info->bmiColors[1].rgbBlue = 0xFF;
656 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
657 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
658 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
659 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
660 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
663 info->bmiHeader.biBitCount = 1;
664 info->bmiColors[0].rgbRed = 0xFF;
665 info->bmiColors[0].rgbGreen = 0xFF;
666 info->bmiColors[0].rgbBlue = 0xFF;
667 info->bmiColors[1].rgbRed = 0;
668 info->bmiColors[1].rgbGreen = 0;
669 info->bmiColors[1].rgbBlue = 0;
671 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
672 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
673 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
674 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
675 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
680 HeapFree(GetProcessHeap(), 0, info);
683 static void test_initial_cursor(void)
685 HCURSOR cursor, cursor2;
688 cursor = GetCursor();
690 /* Check what handle GetCursor() returns if a cursor is not set yet. */
691 SetLastError(0xdeadbeef);
692 cursor2 = LoadCursor(NULL, IDC_WAIT);
694 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
696 error = GetLastError();
697 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
700 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_bpp, int line)
704 BITMAP bmMask, bmColor;
706 ret = GetIconInfo(hIcon, &info);
707 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
709 /* CreateIcon under XP causes info.fIcon to be 0 */
710 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
711 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
712 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
714 ret = GetObject(info.hbmMask, sizeof(bmMask), &bmMask);
715 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
718 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
726 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
729 ret = GetObject(info.hbmColor, sizeof(bmColor), &bmColor);
730 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
732 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
733 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
734 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
735 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
736 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
738 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
739 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
740 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
744 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
745 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
746 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy * 2, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
752 memset( &infoex, 0xcc, sizeof(infoex) );
753 SetLastError( 0xdeadbeef );
754 infoex.cbSize = sizeof(infoex) - 1;
755 ret = pGetIconInfoExA( hIcon, &infoex );
756 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
757 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
759 SetLastError( 0xdeadbeef );
760 infoex.cbSize = sizeof(infoex) + 1;
761 ret = pGetIconInfoExA( hIcon, &infoex );
762 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
763 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
765 SetLastError( 0xdeadbeef );
766 infoex.cbSize = sizeof(infoex);
767 ret = pGetIconInfoExA( (HICON)0xdeadbabe, &infoex );
768 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
769 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE,
770 "wrong error %d\n", GetLastError());
772 infoex.cbSize = sizeof(infoex);
773 ret = pGetIconInfoExA( hIcon, &infoex );
774 ok_(__FILE__, line)(ret, "GetIconInfoEx failed err %d\n", GetLastError());
775 ok_(__FILE__, line)(infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID);
776 ok_(__FILE__, line)(infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName);
777 ok_(__FILE__, line)(infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName);
781 #define test_icon_info(a,b,c,d) test_icon_info_dbg((a),(b),(c),(d),__LINE__)
783 static void test_CreateIcon(void)
785 static const BYTE bmp_bits[1024];
787 HBITMAP hbmMask, hbmColor;
795 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
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);
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, 1);
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, display_bpp);
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");
822 SetLastError(0xdeadbeaf);
823 hIcon = CreateIconIndirect(&info);
824 ok(!hIcon, "CreateIconIndirect should fail\n");
825 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
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());
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, display_bpp);
847 DeleteObject(hbmMask);
848 DeleteObject(hbmColor);
850 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
851 ok(hbmMask != 0, "CreateBitmap failed\n");
856 info.hbmMask = hbmMask;
858 SetLastError(0xdeadbeaf);
859 hIcon = CreateIconIndirect(&info);
860 ok(hIcon != 0, "CreateIconIndirect failed\n");
861 test_icon_info(hIcon, 16, 16, 1);
864 DeleteObject(hbmMask);
865 DeleteObject(hbmColor);
867 /* test creating an icon from a DIB section */
869 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
870 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
871 bmpinfo->bmiHeader.biWidth = 32;
872 bmpinfo->bmiHeader.biHeight = 32;
873 bmpinfo->bmiHeader.biPlanes = 1;
874 bmpinfo->bmiHeader.biBitCount = 8;
875 bmpinfo->bmiHeader.biCompression = BI_RGB;
876 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
877 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
879 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
880 bmpinfo->bmiHeader.biBitCount = 1;
881 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
882 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
884 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
889 info.hbmMask = hbmColor;
890 info.hbmColor = hbmMask;
891 SetLastError(0xdeadbeaf);
892 hIcon = CreateIconIndirect(&info);
893 ok(hIcon != 0, "CreateIconIndirect failed\n");
894 test_icon_info(hIcon, 32, 32, 8);
896 DeleteObject(hbmColor);
898 bmpinfo->bmiHeader.biBitCount = 16;
899 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
900 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
902 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
907 info.hbmMask = hbmColor;
908 info.hbmColor = hbmMask;
909 SetLastError(0xdeadbeaf);
910 hIcon = CreateIconIndirect(&info);
911 ok(hIcon != 0, "CreateIconIndirect failed\n");
912 test_icon_info(hIcon, 32, 32, 8);
914 DeleteObject(hbmColor);
916 bmpinfo->bmiHeader.biBitCount = 32;
917 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
918 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
920 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
925 info.hbmMask = hbmColor;
926 info.hbmColor = hbmMask;
927 SetLastError(0xdeadbeaf);
928 hIcon = CreateIconIndirect(&info);
929 ok(hIcon != 0, "CreateIconIndirect failed\n");
930 test_icon_info(hIcon, 32, 32, 8);
933 DeleteObject(hbmMask);
934 DeleteObject(hbmColor);
935 HeapFree( GetProcessHeap(), 0, bmpinfo );
940 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
942 static unsigned char gifimage[35] = {
943 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
944 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
949 static unsigned char jpgimage[285] = {
950 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
951 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
952 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
953 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
954 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
955 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
956 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,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,0x1e,0x1e,
959 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
960 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
961 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
962 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
963 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
964 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
965 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
966 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
967 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
971 static unsigned char pngimage[285] = {
972 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
973 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
974 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
975 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
976 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
977 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
978 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
981 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
982 zeroes, gap is 0xFF. */
983 static unsigned char bmpimage[70] = {
984 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
985 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
986 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
987 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
988 0xFF,0xFF,0x00,0x00,0x00,0x00
991 /* 1x1 pixel bmp using BITMAPCOREHEADER */
992 static unsigned char bmpcoreimage[38] = {
993 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
994 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
995 0x55,0x00,0x00,0x00,0x00,0x00
999 static unsigned char gif4pixel[42] = {
1000 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1001 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1002 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1005 static const DWORD biSize_tests[] = {
1007 sizeof(BITMAPCOREHEADER) - 1,
1008 sizeof(BITMAPCOREHEADER) + 1,
1009 sizeof(BITMAPINFOHEADER) - 1,
1010 sizeof(BITMAPINFOHEADER) + 1,
1011 sizeof(BITMAPV4HEADER) - 1,
1012 sizeof(BITMAPV4HEADER) + 1,
1013 sizeof(BITMAPV5HEADER) - 1,
1014 sizeof(BITMAPV5HEADER) + 1,
1015 (sizeof(BITMAPCOREHEADER) + sizeof(BITMAPINFOHEADER)) / 2,
1016 (sizeof(BITMAPV4HEADER) + sizeof(BITMAPV5HEADER)) / 2,
1021 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1023 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1027 DWORD ret, pixel = 0;
1028 HDC hdc = GetDC(NULL);
1030 ret = GetObject(hbm, sizeof(bm), &bm);
1031 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1033 memset(&bmi, 0, sizeof(bmi));
1034 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1035 bmi.bmiHeader.biWidth = bm.bmWidth;
1036 bmi.bmiHeader.biHeight = bm.bmHeight;
1037 bmi.bmiHeader.biPlanes = 1;
1038 bmi.bmiHeader.biBitCount= 24;
1039 bmi.bmiHeader.biCompression= BI_RGB;
1040 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
1041 ok(ret == bm.bmHeight, "%s: %d lines were converted, not %d\n", test_desc, ret, bm.bmHeight);
1043 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1046 static void test_LoadImageFile(const char * test_desc, unsigned char * image_data,
1047 unsigned int image_size, const char * ext, BOOL expect_success)
1051 DWORD error, bytes_written;
1054 strcpy(filename, "test.");
1055 strcat(filename, ext);
1057 /* Create the test image. */
1058 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1059 FILE_ATTRIBUTE_NORMAL, NULL);
1060 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1061 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
1062 ok(ret && bytes_written == image_size, "test file created improperly.\n");
1063 CloseHandle(handle);
1065 /* Load as cursor. For all tested formats, this should fail */
1066 SetLastError(0xdeadbeef);
1067 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1068 ok(handle == NULL, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc);
1069 error = GetLastError();
1071 broken(error == 0xdeadbeef) || /* Win9x */
1072 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1073 "Last error: %u\n", error);
1074 if (handle != NULL) DestroyCursor(handle);
1076 /* Load as icon. For all tested formats, this should fail */
1077 SetLastError(0xdeadbeef);
1078 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
1079 ok(handle == NULL, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc);
1080 error = GetLastError();
1082 broken(error == 0xdeadbeef) || /* Win9x */
1083 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1084 "Last error: %u\n", error);
1085 if (handle != NULL) DestroyIcon(handle);
1087 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1088 SetLastError(0xdeadbeef);
1089 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
1090 error = GetLastError();
1092 error == 0xdeadbeef, /* Win9x, WinMe */
1093 "Last error: %u\n", error);
1095 if (expect_success) {
1096 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1097 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1099 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1101 if (handle != NULL) DeleteObject(handle);
1102 DeleteFileA(filename);
1105 static void test_LoadImage(void)
1109 DWORD error, bytes_written;
1110 CURSORICONFILEDIR *icon_data;
1111 CURSORICONFILEDIRENTRY *icon_entry;
1112 BITMAPINFOHEADER *icon_header, *bitmap_header;
1116 #define ICON_WIDTH 32
1117 #define ICON_HEIGHT 32
1118 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1121 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1122 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1124 /* Set icon data. */
1125 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
1126 icon_data->idReserved = 0;
1127 icon_data->idType = 1;
1128 icon_data->idCount = 1;
1130 icon_entry = icon_data->idEntries;
1131 icon_entry->bWidth = ICON_WIDTH;
1132 icon_entry->bHeight = ICON_HEIGHT;
1133 icon_entry->bColorCount = 0;
1134 icon_entry->bReserved = 0;
1135 icon_entry->xHotspot = 1;
1136 icon_entry->yHotspot = 1;
1137 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
1138 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
1140 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
1141 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1142 icon_header->biWidth = ICON_WIDTH;
1143 icon_header->biHeight = ICON_HEIGHT*2;
1144 icon_header->biPlanes = 1;
1145 icon_header->biBitCount = ICON_BPP;
1146 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1148 /* Create the icon. */
1149 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1150 FILE_ATTRIBUTE_NORMAL, NULL);
1151 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1152 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
1153 ok(ret && bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
1154 CloseHandle(handle);
1156 /* Test loading an icon as a cursor. */
1157 SetLastError(0xdeadbeef);
1158 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1159 ok(handle != NULL, "LoadImage() failed.\n");
1160 error = GetLastError();
1162 broken(error == 0xdeadbeef) || /* Win9x */
1163 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1164 "Last error: %u\n", error);
1166 /* Test the icon information. */
1167 SetLastError(0xdeadbeef);
1168 ret = GetIconInfo(handle, &icon_info);
1169 ok(ret, "GetIconInfo() failed.\n");
1170 error = GetLastError();
1171 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1175 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1176 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
1177 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
1178 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1180 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1183 if (pGetIconInfoExA)
1186 infoex.cbSize = sizeof(infoex);
1187 ret = pGetIconInfoExA( handle, &infoex );
1188 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1189 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1190 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1191 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1193 else win_skip( "GetIconInfoEx not available\n" );
1196 SetLastError(0xdeadbeef);
1197 ret = DestroyCursor(handle);
1198 ok(ret, "DestroyCursor() failed.\n");
1199 error = GetLastError();
1200 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1202 HeapFree(GetProcessHeap(), 0, icon_data);
1203 DeleteFileA("icon.ico");
1205 /* Test a system icon */
1206 handle = LoadIcon( 0, IDI_HAND );
1207 ok(handle != NULL, "LoadImage() failed.\n");
1208 if (pGetIconInfoExA)
1210 ICONINFOEXA infoexA;
1211 ICONINFOEXW infoexW;
1212 infoexA.cbSize = sizeof(infoexA);
1213 ret = pGetIconInfoExA( handle, &infoexA );
1214 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1215 ok( infoexA.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexA.wResID );
1216 /* the A version is broken on 64-bit, it truncates the string after the first char */
1217 if (is_win64 && infoexA.szModName[0] && infoexA.szModName[1] == 0)
1218 trace( "GetIconInfoExA broken on Win64\n" );
1220 ok( GetModuleHandleA(infoexA.szModName) == GetModuleHandleA("user32.dll"),
1221 "GetIconInfoEx wrong module %s\n", infoexA.szModName );
1222 ok( infoexA.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA.szResName );
1223 infoexW.cbSize = sizeof(infoexW);
1224 ret = pGetIconInfoExW( handle, &infoexW );
1225 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1226 ok( infoexW.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexW.wResID );
1227 ok( GetModuleHandleW(infoexW.szModName) == GetModuleHandleA("user32.dll"),
1228 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW.szModName) );
1229 ok( infoexW.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW.szResName) );
1231 SetLastError(0xdeadbeef);
1232 DestroyIcon(handle);
1234 test_LoadImageFile("BMP", bmpimage, sizeof(bmpimage), "bmp", 1);
1235 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage, sizeof(bmpcoreimage), "bmp", 1);
1236 test_LoadImageFile("GIF", gifimage, sizeof(gifimage), "gif", 0);
1237 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel, sizeof(gif4pixel), "gif", 0);
1238 test_LoadImageFile("JPG", jpgimage, sizeof(jpgimage), "jpg", 0);
1239 test_LoadImageFile("PNG", pngimage, sizeof(pngimage), "png", 0);
1241 /* Check failure for broken BMP images */
1242 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1244 bitmap_header->biHeight = 65536;
1245 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1246 bitmap_header->biHeight = 1;
1248 bitmap_header->biWidth = 65536;
1249 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1250 bitmap_header->biWidth = 1;
1252 for (i = 0; i < ARRAY_SIZE(biSize_tests); i++) {
1253 bitmap_header->biSize = biSize_tests[i];
1254 test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
1256 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1261 static void test_CreateIconFromResource(void)
1266 BITMAPINFOHEADER *icon_header;
1270 #define ICON_RES_WIDTH 32
1271 #define ICON_RES_HEIGHT 32
1272 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1273 #define ICON_RES_BPP 32
1274 #define ICON_RES_SIZE \
1275 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1276 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1278 /* Set icon data. */
1279 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1281 /* Cursor resources have an extra hotspot, icon resources not. */
1285 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1286 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1287 icon_header->biWidth = ICON_WIDTH;
1288 icon_header->biHeight = ICON_HEIGHT*2;
1289 icon_header->biPlanes = 1;
1290 icon_header->biBitCount = ICON_BPP;
1291 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1293 /* Test creating a cursor. */
1294 SetLastError(0xdeadbeef);
1295 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1296 ok(handle != NULL, "Create cursor failed.\n");
1298 /* Test the icon information. */
1299 SetLastError(0xdeadbeef);
1300 ret = GetIconInfo(handle, &icon_info);
1301 ok(ret, "GetIconInfo() failed.\n");
1302 error = GetLastError();
1303 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1307 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1308 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1309 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1310 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1312 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1315 if (pGetIconInfoExA)
1318 infoex.cbSize = sizeof(infoex);
1319 ret = pGetIconInfoExA( handle, &infoex );
1320 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1321 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1322 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1323 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1327 SetLastError(0xdeadbeef);
1328 ret = DestroyCursor(handle);
1329 ok(ret, "DestroyCursor() failed.\n");
1330 error = GetLastError();
1331 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1333 /* Test creating an icon. */
1334 SetLastError(0xdeadbeef);
1335 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1337 ok(handle != NULL, "Create icon failed.\n");
1339 /* Test the icon information. */
1340 SetLastError(0xdeadbeef);
1341 ret = GetIconInfo(handle, &icon_info);
1342 ok(ret, "GetIconInfo() failed.\n");
1343 error = GetLastError();
1344 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1348 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
1349 /* Icons always have hotspot in the middle */
1350 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
1351 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
1352 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
1353 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1357 SetLastError(0xdeadbeef);
1358 ret = DestroyCursor(handle);
1359 ok(ret, "DestroyCursor() failed.\n");
1360 error = GetLastError();
1361 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1363 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1365 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1366 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1368 HeapFree(GetProcessHeap(), 0, hotspot);
1370 /* Test creating an animated cursor. */
1371 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1372 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1373 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1374 handle = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1375 ok(handle != NULL, "Create cursor failed.\n");
1377 /* Test the animated cursor's information. */
1378 SetLastError(0xdeadbeef);
1379 ret = GetIconInfo(handle, &icon_info);
1380 ok(ret, "GetIconInfo() failed.\n");
1381 error = GetLastError();
1382 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1386 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1387 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1388 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1389 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1391 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1395 SetLastError(0xdeadbeef);
1396 ret = DestroyCursor(handle);
1397 ok(ret, "DestroyCursor() failed.\n");
1398 error = GetLastError();
1399 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1402 static int check_cursor_data( HDC hdc, HCURSOR hCursor, void *data, int length)
1410 ret = GetIconInfo( hCursor, &iinfo );
1411 ok(ret, "GetIconInfo() failed\n");
1414 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ));
1415 ok(info != NULL, "HeapAlloc() failed\n");
1416 if (!info) return 0;
1418 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1419 info->bmiHeader.biWidth = 32;
1420 info->bmiHeader.biHeight = 32;
1421 info->bmiHeader.biPlanes = 1;
1422 info->bmiHeader.biBitCount = 32;
1423 info->bmiHeader.biCompression = BI_RGB;
1424 info->bmiHeader.biSizeImage = 32 * 32 * 4;
1425 info->bmiHeader.biXPelsPerMeter = 0;
1426 info->bmiHeader.biYPelsPerMeter = 0;
1427 info->bmiHeader.biClrUsed = 0;
1428 info->bmiHeader.biClrImportant = 0;
1429 image = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage );
1430 ok(image != NULL, "HeapAlloc() failed\n");
1431 if (!image) goto cleanup;
1432 ret = GetDIBits( hdc, iinfo.hbmColor, 0, 32, image, info, DIB_RGB_COLORS );
1433 ok(ret, "GetDIBits() failed\n");
1434 for (i = 0; ret && i < length / sizeof(COLORREF); i++)
1436 ret = color_match( ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1437 ok(ret, "%04x: Expected 0x%x, actually 0x%x\n", i, ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1440 HeapFree( GetProcessHeap(), 0, image );
1441 HeapFree( GetProcessHeap(), 0, info );
1445 static HCURSOR (WINAPI *pGetCursorFrameInfo)(HCURSOR hCursor, DWORD unk1, DWORD istep, DWORD *rate, DWORD *steps);
1446 static void test_GetCursorFrameInfo(void)
1448 DWORD frame_identifier[] = { 0x10Ad, 0xc001, 0x1c05 };
1449 HBITMAP bmp = NULL, bmpOld = NULL;
1451 BITMAPINFOHEADER *icon_header;
1452 BITMAPINFO bitmapInfo;
1460 if (!pGetCursorFrameInfo)
1462 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1466 hdc = CreateCompatibleDC(0);
1467 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1471 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1472 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1473 bitmapInfo.bmiHeader.biWidth = 3;
1474 bitmapInfo.bmiHeader.biHeight = 3;
1475 bitmapInfo.bmiHeader.biBitCount = 32;
1476 bitmapInfo.bmiHeader.biPlanes = 1;
1477 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1478 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1479 bmp = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1480 ok (bmp && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1483 bmpOld = SelectObject(hdc, bmp);
1485 #define ICON_RES_WIDTH 32
1486 #define ICON_RES_HEIGHT 32
1487 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1488 #define ICON_RES_BPP 32
1489 #define ICON_RES_SIZE \
1490 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1491 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1493 /* Set icon data. */
1494 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1496 /* Cursor resources have an extra hotspot, icon resources not. */
1500 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1501 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1502 icon_header->biWidth = ICON_WIDTH;
1503 icon_header->biHeight = ICON_HEIGHT*2;
1504 icon_header->biPlanes = 1;
1505 icon_header->biBitCount = ICON_BPP;
1506 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1508 /* Creating a static cursor. */
1509 SetLastError(0xdeadbeef);
1510 h1 = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1511 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1513 /* Check GetCursorFrameInfo behavior on a static cursor */
1514 rate = steps = 0xdead;
1515 h2 = pGetCursorFrameInfo(h1, 0xdead, 0xdead, &rate, &steps);
1516 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1517 ok(rate == 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1518 ok(steps == 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1520 /* Clean up static cursor. */
1521 SetLastError(0xdeadbeef);
1522 ret = DestroyCursor(h1);
1523 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1525 /* Creating a single-frame animated cursor. */
1526 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1527 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1528 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1529 memcpy( &empty_anicursor.frames[0].data.bmi_data.data[0], &frame_identifier[0], sizeof(DWORD) );
1530 SetLastError(0xdeadbeef);
1531 h1 = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1532 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1534 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1535 rate = steps = 0xdead;
1536 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1537 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1538 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1539 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1540 ok(rate == 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1541 ok(steps == empty_anicursor.header.header.num_steps,
1542 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1544 /* Clean up single-frame animated cursor. */
1545 SetLastError(0xdeadbeef);
1546 ret = DestroyCursor(h1);
1547 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1549 /* Creating a multi-frame animated cursor. */
1550 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1552 empty_anicursor3.frames[i].data.icon_info.idType = 2; /* type: cursor */
1553 empty_anicursor3.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1554 empty_anicursor3.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1555 memcpy( &empty_anicursor3.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1557 SetLastError(0xdeadbeef);
1558 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1559 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1561 /* Check number of steps in multi-frame animated cursor */
1563 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1565 ok(i == empty_anicursor3.header.header.num_steps,
1566 "Unexpected number of steps in cursor (%d != %d)\n",
1567 i, empty_anicursor3.header.header.num_steps);
1569 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1570 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1572 rate = steps = 0xdead;
1573 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1574 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1575 ret = check_cursor_data( hdc, h2, &frame_identifier[i], sizeof(DWORD) );
1576 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1577 ok(rate == empty_anicursor3.header.header.display_rate,
1578 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1579 rate, empty_anicursor3.header.header.display_rate);
1580 ok(steps == empty_anicursor3.header.header.num_steps,
1581 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1582 steps, empty_anicursor3.header.header.num_steps);
1585 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1586 rate = steps = 0xdead;
1587 h2 = pGetCursorFrameInfo(h1, 0xdead, 3, &rate, &steps);
1588 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1589 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1590 || broken(rate == ~0) /*win2k (sporadic)*/,
1591 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1592 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1593 || broken(steps == 0) /*win2k (sporadic)*/,
1594 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps);
1596 /* Clean up multi-frame animated cursor. */
1597 SetLastError(0xdeadbeef);
1598 ret = DestroyCursor(h1);
1599 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1601 /* Create a multi-frame animated cursor with num_steps == 1 */
1602 empty_anicursor3.header.header.num_steps = 1;
1603 SetLastError(0xdeadbeef);
1604 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1605 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1607 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1609 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1611 ok(i == empty_anicursor3.header.header.num_steps,
1612 "Unexpected number of steps in cursor (%d != %d)\n",
1613 i, empty_anicursor3.header.header.num_steps);
1615 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1616 rate = steps = 0xdead;
1617 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1618 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1619 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1620 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1621 ok(rate == empty_anicursor3.header.header.display_rate,
1622 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1623 rate, empty_anicursor3.header.header.display_rate);
1624 ok(steps == ~0 || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/,
1625 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps);
1627 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1628 rate = steps = 0xdead;
1629 h2 = pGetCursorFrameInfo(h1, 0xdead, 1, &rate, &steps);
1630 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1631 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1632 || broken(rate == ~0) /*win2k (sporadic)*/,
1633 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1634 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1635 || broken(steps == 0) /*win2k (sporadic)*/,
1636 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps);
1638 /* Clean up multi-frame animated cursor. */
1639 SetLastError(0xdeadbeef);
1640 ret = DestroyCursor(h1);
1641 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1643 /* Creating a multi-frame animated cursor with rate data. */
1644 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1646 empty_anicursor3_seq.frames[i].data.icon_info.idType = 2; /* type: cursor */
1647 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1648 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1649 memcpy( &empty_anicursor3_seq.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1651 SetLastError(0xdeadbeef);
1652 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3_seq, sizeof(empty_anicursor3_seq), FALSE, 0x00030000);
1653 ok(h1 != NULL, "Create cursor failed (error = %x).\n", GetLastError());
1655 /* Check number of steps in multi-frame animated cursor with rate data */
1657 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1659 ok(i == empty_anicursor3_seq.header.header.num_steps,
1660 "Unexpected number of steps in cursor (%d != %d)\n",
1661 i, empty_anicursor3_seq.header.header.num_steps);
1663 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1664 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1666 int frame_id = empty_anicursor3_seq.seq.order[i];
1668 rate = steps = 0xdead;
1669 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1670 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1671 ret = check_cursor_data( hdc, h2, &frame_identifier[frame_id], sizeof(DWORD) );
1672 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1673 ok(rate == empty_anicursor3_seq.rates.rate[i],
1674 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1675 rate, empty_anicursor3_seq.rates.rate[i]);
1676 ok(steps == empty_anicursor3_seq.header.header.num_steps,
1677 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1678 steps, empty_anicursor3_seq.header.header.num_steps);
1681 /* Clean up multi-frame animated cursor with rate data. */
1682 SetLastError(0xdeadbeef);
1683 ret = DestroyCursor(h1);
1684 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1687 if(bmpOld) SelectObject(hdc, bmpOld);
1688 if(bmp) DeleteObject(bmp);
1689 if(hdc) DeleteDC(hdc);
1692 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1693 BOOL maskvalue, UINT32 *color, int colorSize)
1696 BITMAPINFO bitmapInfo;
1697 void *buffer = NULL;
1698 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1700 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1701 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1702 bitmapInfo.bmiHeader.biWidth = width;
1703 bitmapInfo.bmiHeader.biHeight = height;
1704 bitmapInfo.bmiHeader.biPlanes = 1;
1705 bitmapInfo.bmiHeader.biBitCount = bpp;
1706 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1707 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1709 iconInfo.fIcon = TRUE;
1710 iconInfo.xHotspot = 0;
1711 iconInfo.yHotspot = 0;
1713 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1714 if(!iconInfo.hbmMask) return NULL;
1716 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1717 if(!iconInfo.hbmColor || !buffer)
1719 DeleteObject(iconInfo.hbmMask);
1723 memcpy(buffer, color, colorSize);
1725 return CreateIconIndirect(&iconInfo);
1728 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1732 COLORREF modern_expected, legacy_expected, result;
1734 color[0] = 0x00A0B0C0;
1735 color[1] = alpha ? 0xFF000000 : 0x00000000;
1736 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1737 legacy_expected = 0x00C0B0A0;
1739 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1742 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1745 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1747 DrawIcon(hdc, 0, 0, hicon);
1749 result = GetPixel(hdc, 0, 0);
1750 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1751 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1752 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1753 "Got %06X from line %d\n",
1754 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1755 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1758 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1759 COLORREF modern_expected, COLORREF legacy_expected, int line)
1762 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1764 SetPixelV(hdc, 0, 0, background);
1765 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1766 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1767 DrawIcon(hdc, 0, 0, hicon);
1768 result = GetPixel(hdc, 0, 0);
1770 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1771 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1772 "Overlaying Mask %d on Color %06X with DrawIcon. "
1773 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1774 maskvalue, color, modern_expected, legacy_expected, result, line);
1776 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1778 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1779 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1780 "Overlaying Mask %d on Color %06X with DrawIcon. "
1781 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1782 maskvalue, color, modern_expected, legacy_expected, result, line);
1784 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1786 ok (color_match(result, background),
1787 "Overlaying Mask %d on Color %06X with DrawIcon. "
1788 "Expected unchanged background color %06X. Got %06X from line %d\n",
1789 maskvalue, color, background, result, line);
1792 static void test_DrawIcon(void)
1794 BITMAPINFO bitmapInfo;
1796 HBITMAP bmpDst = NULL;
1797 HBITMAP bmpOld = NULL;
1800 hdcDst = CreateCompatibleDC(0);
1801 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1805 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1807 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1811 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1812 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1813 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1814 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1815 bitmapInfo.bmiHeader.biBitCount = 32;
1816 bitmapInfo.bmiHeader.biPlanes = 1;
1817 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1818 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1820 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1821 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1822 if (!bmpDst || !bits)
1824 bmpOld = SelectObject(hdcDst, bmpDst);
1826 /* Mask is only heeded if alpha channel is always zero */
1827 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1828 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1830 /* Test alpha blending */
1831 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1832 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1833 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1835 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1836 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1837 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1838 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1840 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1841 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1843 /* Test detecting of alpha channel */
1844 /* If a single pixel's alpha channel is non-zero, the icon
1845 will be alpha blended, otherwise it will be draw with
1847 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1848 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1852 SelectObject(hdcDst, bmpOld);
1854 DeleteObject(bmpDst);
1859 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1860 COLORREF modern_expected, COLORREF legacy_expected, int line)
1863 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1865 SetPixelV(hdc, 0, 0, background);
1866 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1867 result = GetPixel(hdc, 0, 0);
1869 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1870 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1871 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1872 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1873 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1876 static void test_DrawIconEx(void)
1878 BITMAPINFO bitmapInfo;
1880 HBITMAP bmpDst = NULL;
1881 HBITMAP bmpOld = NULL;
1884 hdcDst = CreateCompatibleDC(0);
1885 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1889 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1891 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1895 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1896 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1897 bitmapInfo.bmiHeader.biWidth = 1;
1898 bitmapInfo.bmiHeader.biHeight = 1;
1899 bitmapInfo.bmiHeader.biBitCount = 32;
1900 bitmapInfo.bmiHeader.biPlanes = 1;
1901 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1902 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1903 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1904 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1905 if (!bmpDst || !bits)
1907 bmpOld = SelectObject(hdcDst, bmpDst);
1909 /* Test null, image only, and mask only drawing */
1910 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1911 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1913 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00000000, 0x00000000, __LINE__);
1914 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1916 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1917 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1919 /* Test normal drawing */
1920 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1921 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1922 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1924 /* Test alpha blending */
1925 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1926 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1928 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1929 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1930 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1931 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1933 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1934 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1936 /* Test detecting of alpha channel */
1937 /* If a single pixel's alpha channel is non-zero, the icon
1938 will be alpha blended, otherwise it will be draw with
1940 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1941 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1945 SelectObject(hdcDst, bmpOld);
1947 DeleteObject(bmpDst);
1952 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1954 COLORREF result, background;
1956 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1957 background = 0x00FFFFFF;
1958 /* Set color of the 2 pixels that will be checked afterwards */
1959 SetPixelV(hdc, 0, 0, background);
1960 SetPixelV(hdc, 2, 2, background);
1962 /* Let DrawState calculate the size of the icon (it's 1x1) */
1963 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1965 result = GetPixel(hdc, 0, 0);
1966 passed[0] = color_match(result, background);
1967 result = GetPixel(hdc, 2, 2);
1968 passed[0] = passed[0] & color_match(result, background);
1970 /* Check if manually specifying the icon size DOESN'T work */
1972 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1973 * size in which it should be ultimately drawn. Therefore giving
1974 * width/height 2x2 if the icon is only 1x1 pixels in size should
1975 * result in drawing it with size 1x1. The size parameters must be
1976 * ignored if a Icon has to be drawn! */
1977 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1979 result = GetPixel(hdc, 0, 0);
1980 passed[1] = color_match(result, background);
1981 result = GetPixel(hdc, 2, 2);
1982 passed[1] = passed[0] & color_match(result, background);
1984 if(!passed[0]&&!passed[1])
1986 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
1987 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
1988 "Color %06X with flags %08X. Line %d\n",
1989 maskvalue, color, (DST_ICON | flags), line);
1992 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1993 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
1994 "Mask %d on Color %06X with flags %08X. Line %d\n",
1995 maskvalue, color, (DST_ICON | flags), line);
1998 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1999 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
2000 "Color %06X with flags %08X. Line %d\n",
2001 maskvalue, color, (DST_ICON | flags), line);
2004 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
2005 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
2008 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2010 /* Set color of the pixel that will be checked afterwards */
2011 SetPixelV(hdc, 1, 1, background);
2013 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
2015 /* Check the color of the pixel is correct */
2016 result = GetPixel(hdc, 1, 1);
2018 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
2019 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
2020 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2021 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2022 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
2025 static void test_DrawState(void)
2027 BITMAPINFO bitmapInfo;
2029 HBITMAP bmpDst = NULL;
2030 HBITMAP bmpOld = NULL;
2033 hdcDst = CreateCompatibleDC(0);
2034 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2038 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
2040 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2044 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
2045 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2046 bitmapInfo.bmiHeader.biWidth = 3;
2047 bitmapInfo.bmiHeader.biHeight = 3;
2048 bitmapInfo.bmiHeader.biBitCount = 32;
2049 bitmapInfo.bmiHeader.biPlanes = 1;
2050 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2051 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2052 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
2053 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2054 if (!bmpDst || !bits)
2056 bmpOld = SelectObject(hdcDst, bmpDst);
2058 /* potential flags to test with DrawState are: */
2059 /* DSS_DISABLED embosses the icon */
2060 /* DSS_MONO draw Icon using a brush as parameter 5 */
2061 /* DSS_NORMAL draw Icon without any modifications */
2062 /* DSS_UNION draw the Icon dithered */
2064 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
2065 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
2069 SelectObject(hdcDst, bmpOld);
2071 DeleteObject(bmpDst);
2076 static DWORD parent_id;
2078 static DWORD CALLBACK set_cursor_thread( void *arg )
2082 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2085 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2086 ok( ret, "AttachThreadInput failed\n" );
2088 if (arg) ret = SetCursor( (HCURSOR)arg );
2089 else ret = GetCursor();
2090 return (DWORD_PTR)ret;
2093 static void test_SetCursor(void)
2095 static const BYTE bmp_bits[4096];
2096 ICONINFO cursorInfo;
2097 HCURSOR cursor, old_cursor, global_cursor = 0;
2098 DWORD error, id, result;
2106 memset( &info, 0, sizeof(info) );
2107 info.cbSize = sizeof(info);
2108 if (!pGetCursorInfo( &info ))
2110 win_skip( "GetCursorInfo not working\n" );
2111 pGetCursorInfo = NULL;
2113 else global_cursor = info.hCursor;
2115 cursor = GetCursor();
2116 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2117 WaitForSingleObject( thread, 1000 );
2118 GetExitCodeThread( thread, &result );
2119 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
2122 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2125 cursorInfo.fIcon = FALSE;
2126 cursorInfo.xHotspot = 0;
2127 cursorInfo.yHotspot = 0;
2128 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2129 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2131 cursor = CreateIconIndirect(&cursorInfo);
2132 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2133 old_cursor = SetCursor( cursor );
2137 info.cbSize = sizeof(info);
2138 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2139 /* global cursor doesn't change since we don't have a window */
2140 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2141 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2143 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2144 WaitForSingleObject( thread, 1000 );
2145 GetExitCodeThread( thread, &result );
2146 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2149 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2150 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2151 WaitForSingleObject( thread, 1000 );
2152 GetExitCodeThread( thread, &result );
2153 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2155 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2156 WaitForSingleObject( thread, 1000 );
2157 GetExitCodeThread( thread, &result );
2158 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2159 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2161 parent_id = GetCurrentThreadId();
2162 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2163 WaitForSingleObject( thread, 1000 );
2164 GetExitCodeThread( thread, &result );
2165 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2166 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
2170 info.cbSize = sizeof(info);
2171 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2172 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2173 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2175 SetCursor( old_cursor );
2176 DestroyCursor( cursor );
2178 SetLastError( 0xdeadbeef );
2179 cursor = SetCursor( (HCURSOR)0xbadbad );
2180 error = GetLastError();
2181 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
2182 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
2183 "wrong error %u\n", error );
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 );
2194 static HANDLE event_start, event_next;
2196 static DWORD CALLBACK show_cursor_thread( void *arg )
2198 DWORD count = (DWORD_PTR)arg;
2201 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2204 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2205 ok( ret, "AttachThreadInput failed\n" );
2207 if (!count) ret = ShowCursor( FALSE );
2208 else while (count--) ret = ShowCursor( TRUE );
2209 SetEvent( event_start );
2210 WaitForSingleObject( event_next, 2000 );
2214 static void test_ShowCursor(void)
2223 memset( &info, 0, sizeof(info) );
2224 info.cbSize = sizeof(info);
2225 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2226 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2229 event_start = CreateEvent( NULL, FALSE, FALSE, NULL );
2230 event_next = CreateEvent( NULL, FALSE, FALSE, NULL );
2232 count = ShowCursor( TRUE );
2233 ok( count == 1, "wrong count %d\n", count );
2234 count = ShowCursor( TRUE );
2235 ok( count == 2, "wrong count %d\n", count );
2236 count = ShowCursor( FALSE );
2237 ok( count == 1, "wrong count %d\n", count );
2238 count = ShowCursor( FALSE );
2239 ok( count == 0, "wrong count %d\n", count );
2240 count = ShowCursor( FALSE );
2241 ok( count == -1, "wrong count %d\n", count );
2242 count = ShowCursor( FALSE );
2243 ok( count == -2, "wrong count %d\n", count );
2247 info.cbSize = sizeof(info);
2248 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2249 /* global show count is not affected since we don't have a window */
2250 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2254 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2255 WaitForSingleObject( event_start, 1000 );
2256 count = ShowCursor( FALSE );
2257 ok( count == -3, "wrong count %d\n", count );
2258 SetEvent( event_next );
2259 WaitForSingleObject( thread, 1000 );
2260 GetExitCodeThread( thread, &result );
2261 ok( result == -1, "wrong thread count %d\n", result );
2262 count = ShowCursor( FALSE );
2263 ok( count == -4, "wrong count %d\n", count );
2265 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
2266 WaitForSingleObject( event_start, 1000 );
2267 count = ShowCursor( TRUE );
2268 ok( count == -3, "wrong count %d\n", count );
2269 SetEvent( event_next );
2270 WaitForSingleObject( thread, 1000 );
2271 GetExitCodeThread( thread, &result );
2272 ok( result == 1, "wrong thread count %d\n", result );
2273 count = ShowCursor( TRUE );
2274 ok( count == -2, "wrong count %d\n", count );
2276 parent_id = GetCurrentThreadId();
2277 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2278 WaitForSingleObject( event_start, 1000 );
2279 count = ShowCursor( TRUE );
2280 ok( count == -2, "wrong count %d\n", count );
2281 SetEvent( event_next );
2282 WaitForSingleObject( thread, 1000 );
2283 GetExitCodeThread( thread, &result );
2284 ok( result == -3, "wrong thread count %d\n", result );
2285 count = ShowCursor( FALSE );
2286 ok( count == -2, "wrong count %d\n", count );
2288 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
2289 WaitForSingleObject( event_start, 1000 );
2290 count = ShowCursor( TRUE );
2291 ok( count == 2, "wrong count %d\n", count );
2292 SetEvent( event_next );
2293 WaitForSingleObject( thread, 1000 );
2294 GetExitCodeThread( thread, &result );
2295 ok( result == 1, "wrong thread count %d\n", result );
2296 count = ShowCursor( FALSE );
2297 ok( count == -2, "wrong count %d\n", count );
2301 info.cbSize = sizeof(info);
2302 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2303 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2306 count = ShowCursor( TRUE );
2307 ok( count == -1, "wrong count %d\n", count );
2308 count = ShowCursor( TRUE );
2309 ok( count == 0, "wrong count %d\n", count );
2313 info.cbSize = sizeof(info);
2314 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2315 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2320 static void test_DestroyCursor(void)
2322 static const BYTE bmp_bits[4096];
2323 ICONINFO cursorInfo, new_info;
2324 HCURSOR cursor, cursor2, new_cursor;
2331 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2334 cursorInfo.fIcon = FALSE;
2335 cursorInfo.xHotspot = 0;
2336 cursorInfo.yHotspot = 0;
2337 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2338 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2340 cursor = CreateIconIndirect(&cursorInfo);
2341 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2347 SetLastError(0xdeadbeef);
2348 ret = DestroyCursor(cursor);
2349 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2350 error = GetLastError();
2351 ok(error == 0xdeadbeef, "Last error: %u\n", error);
2353 new_cursor = GetCursor();
2354 if (ret) /* win9x replaces cursor by another one on destroy */
2355 ok(new_cursor != cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2357 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2359 SetLastError(0xdeadbeef);
2360 ret = GetIconInfo( cursor, &new_info );
2361 ok( !ret || broken(ret), /* nt4 */ "GetIconInfo succeeded\n" );
2362 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2363 broken(GetLastError() == 0xdeadbeef), /* win9x */
2364 "wrong error %u\n", GetLastError() );
2366 if (ret) /* nt4 delays destruction until cursor changes */
2368 DeleteObject( new_info.hbmColor );
2369 DeleteObject( new_info.hbmMask );
2371 SetLastError(0xdeadbeef);
2372 ret = DestroyCursor( cursor );
2373 ok( !ret, "DestroyCursor succeeded\n" );
2374 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2375 "wrong error %u\n", GetLastError() );
2377 SetLastError(0xdeadbeef);
2378 cursor2 = SetCursor( cursor );
2379 ok( cursor2 == cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2380 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2381 "wrong error %u\n", GetLastError() );
2385 SetLastError(0xdeadbeef);
2386 cursor2 = CopyCursor( cursor );
2387 ok(!cursor2, "CopyCursor succeeded\n" );
2388 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2389 broken(GetLastError() == 0xdeadbeef), /* win9x */
2390 "wrong error %u\n", GetLastError() );
2392 SetLastError(0xdeadbeef);
2393 ret = DestroyCursor( cursor );
2394 if (new_cursor != cursor) /* win9x */
2395 ok( ret, "DestroyCursor succeeded\n" );
2397 ok( !ret, "DestroyCursor succeeded\n" );
2398 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2399 "wrong error %u\n", GetLastError() );
2401 SetLastError(0xdeadbeef);
2402 cursor2 = SetCursor( cursor );
2403 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2404 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2405 "wrong error %u\n", GetLastError() );
2408 cursor2 = GetCursor();
2409 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2411 SetLastError(0xdeadbeef);
2412 cursor2 = SetCursor( 0 );
2413 if (new_cursor != cursor) /* win9x */
2414 ok(cursor2 == new_cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2416 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2417 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2419 cursor2 = GetCursor();
2420 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2422 SetLastError(0xdeadbeef);
2423 ret = DestroyCursor(cursor);
2424 if (new_cursor != cursor) /* win9x */
2425 ok( ret, "DestroyCursor succeeded\n" );
2427 ok( !ret, "DestroyCursor succeeded\n" );
2428 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2429 "wrong error %u\n", GetLastError() );
2431 DeleteObject(cursorInfo.hbmMask);
2432 DeleteObject(cursorInfo.hbmColor);
2434 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2435 cursor = LoadCursor(NULL, IDC_ARROW);
2437 SetLastError(0xdeadbeef);
2438 ret = DestroyCursor(cursor);
2439 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2440 error = GetLastError();
2441 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2443 /* Try setting the cursor to a destroyed OEM cursor. */
2444 SetLastError(0xdeadbeef);
2446 error = GetLastError();
2447 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2449 /* Check if LoadCursor() returns the same handle with the same icon. */
2450 cursor2 = LoadCursor(NULL, IDC_ARROW);
2451 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2453 /* Check if LoadCursor() returns the same handle with a different icon. */
2454 cursor2 = LoadCursor(NULL, IDC_WAIT);
2455 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2458 START_TEST(cursoricon)
2460 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2461 pGetIconInfoExA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2462 pGetIconInfoExW = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2463 pGetCursorFrameInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2464 test_argc = winetest_get_mainargs(&test_argv);
2468 /* Child process. */
2469 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2471 ok(parent != NULL, "Parent not found.\n");
2479 test_CopyImage_Bitmap(1);
2480 test_CopyImage_Bitmap(4);
2481 test_CopyImage_Bitmap(8);
2482 test_CopyImage_Bitmap(16);
2483 test_CopyImage_Bitmap(24);
2484 test_CopyImage_Bitmap(32);
2485 test_initial_cursor();
2488 test_CreateIconFromResource();
2489 test_GetCursorFrameInfo();
2495 test_DestroyCursor();
2497 test_child_process();
2498 finish_child_process();