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_RIFF_ID */
139 DWORD chunk_size; /* actual size of data */
140 DWORD chunk_type; /* ANI_ACON_ID */
141 riff_header_t header; /* RIFF animated cursor header */
142 riff_rate3_t rates; /* rate data for three cursor frames */
143 riff_list_t frame_list; /* RIFF animated cursor frame list info */
144 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
145 } riff_cursor3_rate_t;
147 #define EMPTY_ICON32 \
150 sizeof(ani_frame32x32x32), \
153 0x0, /* reserved */ \
154 0, /* type: icon(1), cursor(2) */ \
160 0, /* color count */ \
161 0x0, /* reserved */ \
162 16, /* x hotspot */ \
163 16, /* y hotspot */ \
164 sizeof(ani_data32x32x32), /* DIB size */ \
165 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
170 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
172 32*2, /* actual height times two */ \
175 BI_RGB, /* compression */ \
176 0, /* image size */ \
177 0, /* biXPelsPerMeter */ \
178 0, /* biYPelsPerMeter */ \
180 0 /* biClrImportant */ \
182 { /* DIB data: left uninitialized */ } \
186 riff_cursor1_t empty_anicursor = {
188 sizeof(empty_anicursor) - sizeof(DWORD)*2,
201 10, /* display rate in jiffies */
202 ANI_FLAG_ICON /* flags */
207 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
215 riff_cursor3_t empty_anicursor3 = {
217 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
230 0xbeef, /* display rate in jiffies */
231 ANI_FLAG_ICON /* flags */
236 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
246 riff_cursor3_rate_t empty_anicursor3_rate = {
248 sizeof(empty_anicursor3_rate) - sizeof(DWORD)*2,
261 0xbeef, /* display rate in jiffies */
262 ANI_FLAG_ICON /* flags */
267 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
268 { 0xc0de, 0xcafe, 0xbabe}
272 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
284 static char **test_argv;
285 static int test_argc;
286 static HWND child = 0;
287 static HWND parent = 0;
288 static HANDLE child_process;
290 #define PROC_INIT (WM_USER+1)
292 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
293 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
294 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
296 static const int is_win64 = (sizeof(void *) > sizeof(int));
298 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
305 /* Destroy the cursor. */
307 SetLastError(0xdeadbeef);
308 ret = DestroyCursor((HCURSOR) lParam);
309 error = GetLastError();
310 ok(!ret || broken(ret) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
311 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD ||
312 error == 0xdeadbeef, /* vista */
313 "Last error: %u\n", error);
320 return DefWindowProc(hwnd, msg, wParam, lParam);
323 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
325 if (msg == PROC_INIT)
327 child = (HWND) wParam;
331 return DefWindowProc(hwnd, msg, wParam, lParam);
334 static void do_child(void)
340 /* Register a new class. */
341 class.style = CS_GLOBALCLASS;
342 class.lpfnWndProc = callback_child;
343 class.cbClsExtra = 0;
344 class.cbWndExtra = 0;
345 class.hInstance = GetModuleHandle(NULL);
347 class.hCursor = NULL;
348 class.hbrBackground = NULL;
349 class.lpszMenuName = NULL;
350 class.lpszClassName = "cursor_child";
352 SetLastError(0xdeadbeef);
353 ret = RegisterClass(&class);
354 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
356 /* Create a window. */
357 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
358 0, 0, 200, 200, 0, 0, 0, NULL);
359 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
361 /* Let the parent know our HWND. */
362 PostMessage(parent, PROC_INIT, (WPARAM) child, 0);
364 /* Receive messages. */
365 while ((ret = GetMessage(&msg, 0, 0, 0)))
367 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
368 TranslateMessage(&msg);
369 DispatchMessage(&msg);
373 static void do_parent(void)
375 char path_name[MAX_PATH];
376 PROCESS_INFORMATION info;
377 STARTUPINFOA startup;
382 /* Register a new class. */
383 class.style = CS_GLOBALCLASS;
384 class.lpfnWndProc = callback_parent;
385 class.cbClsExtra = 0;
386 class.cbWndExtra = 0;
387 class.hInstance = GetModuleHandle(NULL);
389 class.hCursor = NULL;
390 class.hbrBackground = NULL;
391 class.lpszMenuName = NULL;
392 class.lpszClassName = "cursor_parent";
394 SetLastError(0xdeadbeef);
395 ret = RegisterClass(&class);
396 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
398 /* Create a window. */
399 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
400 0, 0, 200, 200, 0, 0, 0, NULL);
401 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
403 /* Start child process. */
404 memset(&startup, 0, sizeof(startup));
405 startup.cb = sizeof(startup);
406 startup.dwFlags = STARTF_USESHOWWINDOW;
407 startup.wShowWindow = SW_SHOWNORMAL;
409 sprintf(path_name, "%s cursoricon %lx", test_argv[0], (INT_PTR)parent);
410 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
411 child_process = info.hProcess;
413 /* Wait for child window handle. */
414 while ((child == 0) && (ret = GetMessage(&msg, parent, 0, 0)))
416 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
417 TranslateMessage(&msg);
418 DispatchMessage(&msg);
422 static void finish_child_process(void)
424 SendMessage(child, WM_CLOSE, 0, 0);
425 winetest_wait_child_process( child_process );
426 CloseHandle(child_process);
429 static void test_child_process(void)
431 static const BYTE bmp_bits[4096];
437 /* Create and set a dummy cursor. */
439 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
442 cursorInfo.fIcon = FALSE;
443 cursorInfo.xHotspot = 0;
444 cursorInfo.yHotspot = 0;
445 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
446 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
448 cursor = CreateIconIndirect(&cursorInfo);
449 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
453 /* Destroy the cursor. */
454 SendMessage(child, WM_USER+1, 0, (LPARAM) cursor);
457 static BOOL color_match(COLORREF a, COLORREF b)
459 /* 5-bit accuracy is a sufficient test. This will match as long as
460 * colors are never truncated to less that 3x5-bit accuracy i.e.
462 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
465 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
466 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
474 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
475 ok(copy != NULL, "CopyImage() failed\n");
478 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
479 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
480 orig_is_dib = (origBitmap.bmBits != NULL);
481 copy_is_dib = (copyBitmap.bmBits != NULL);
483 if (copy_is_dib && dibExpected
484 && copyBitmap.bmBitsPixel == 24
485 && (expectedDepth == 16 || expectedDepth == 32))
487 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
488 if (GetVersion() & 0x80000000)
494 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
496 /* It's not forbidden to create a DIB section if the flag
497 LR_CREATEDIBSECTION is absent.
498 Windows 9x does this if the bitmap has a depth that doesn't
499 match the screen depth, Windows NT doesn't */
501 expectedDepth = origBitmap.bmBitsPixel;
504 ok((!(dibExpected ^ copy_is_dib)
505 && (copyBitmap.bmWidth == expectedWidth)
506 && (copyBitmap.bmHeight == expectedHeight)
507 && (copyBitmap.bmBitsPixel == expectedDepth)),
508 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
509 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
510 copyWidth, copyHeight, flags,
511 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
512 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
518 static void test_CopyImage_Bitmap(int depth)
527 /* Create a device-independent bitmap (DIB) */
528 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
529 info->bmiHeader.biSize = sizeof(info->bmiHeader);
530 info->bmiHeader.biWidth = 2;
531 info->bmiHeader.biHeight = 2;
532 info->bmiHeader.biPlanes = 1;
533 info->bmiHeader.biBitCount = depth;
534 info->bmiHeader.biCompression = BI_RGB;
536 for (i=0; i < 256; i++)
538 info->bmiColors[i].rgbRed = i;
539 info->bmiColors[i].rgbGreen = i;
540 info->bmiColors[i].rgbBlue = 255 - i;
541 info->bmiColors[i].rgbReserved = 0;
544 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
546 /* Create a device-dependent bitmap (DDB) */
547 screenDC = GetDC(NULL);
548 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
549 if (depth == 1 || depth == screen_depth)
551 ddb = CreateBitmap(2, 2, 1, depth, NULL);
557 ReleaseDC(NULL, screenDC);
561 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
562 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
563 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
564 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
566 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
567 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
568 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
569 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
571 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
572 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
573 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
574 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
576 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
577 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
578 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
579 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
580 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
587 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
588 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
589 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
590 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
593 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
594 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
595 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
596 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
598 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
599 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
600 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
601 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
603 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
604 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
605 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
606 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
607 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
613 /* Special case: A monochrome DIB is converted to a monochrome DDB if
614 the colors in the color table are black and white.
616 Skip this test on Windows 95, it always creates a monochrome DDB
619 if (!(GetVersion() & 0x80000000))
621 info->bmiHeader.biBitCount = 1;
622 info->bmiColors[0].rgbRed = 0xFF;
623 info->bmiColors[0].rgbGreen = 0;
624 info->bmiColors[0].rgbBlue = 0;
625 info->bmiColors[1].rgbRed = 0;
626 info->bmiColors[1].rgbGreen = 0xFF;
627 info->bmiColors[1].rgbBlue = 0;
629 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
630 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
631 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
632 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
633 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
636 info->bmiHeader.biBitCount = 1;
637 info->bmiColors[0].rgbRed = 0;
638 info->bmiColors[0].rgbGreen = 0;
639 info->bmiColors[0].rgbBlue = 0;
640 info->bmiColors[1].rgbRed = 0xFF;
641 info->bmiColors[1].rgbGreen = 0xFF;
642 info->bmiColors[1].rgbBlue = 0xFF;
644 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
645 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
646 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
647 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
648 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
651 info->bmiHeader.biBitCount = 1;
652 info->bmiColors[0].rgbRed = 0xFF;
653 info->bmiColors[0].rgbGreen = 0xFF;
654 info->bmiColors[0].rgbBlue = 0xFF;
655 info->bmiColors[1].rgbRed = 0;
656 info->bmiColors[1].rgbGreen = 0;
657 info->bmiColors[1].rgbBlue = 0;
659 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
660 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
661 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
662 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
663 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
668 HeapFree(GetProcessHeap(), 0, info);
671 static void test_initial_cursor(void)
673 HCURSOR cursor, cursor2;
676 cursor = GetCursor();
678 /* Check what handle GetCursor() returns if a cursor is not set yet. */
679 SetLastError(0xdeadbeef);
680 cursor2 = LoadCursor(NULL, IDC_WAIT);
682 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
684 error = GetLastError();
685 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
688 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_bpp, int line)
692 BITMAP bmMask, bmColor;
694 ret = GetIconInfo(hIcon, &info);
695 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
697 /* CreateIcon under XP causes info.fIcon to be 0 */
698 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
699 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
700 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
702 ret = GetObject(info.hbmMask, sizeof(bmMask), &bmMask);
703 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
706 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
714 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
717 ret = GetObject(info.hbmColor, sizeof(bmColor), &bmColor);
718 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
720 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
721 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
722 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
723 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
724 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
726 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
727 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
728 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
732 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
733 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
734 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy * 2, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
740 memset( &infoex, 0xcc, sizeof(infoex) );
741 SetLastError( 0xdeadbeef );
742 infoex.cbSize = sizeof(infoex) - 1;
743 ret = pGetIconInfoExA( hIcon, &infoex );
744 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
745 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
747 SetLastError( 0xdeadbeef );
748 infoex.cbSize = sizeof(infoex) + 1;
749 ret = pGetIconInfoExA( hIcon, &infoex );
750 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
751 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
753 SetLastError( 0xdeadbeef );
754 infoex.cbSize = sizeof(infoex);
755 ret = pGetIconInfoExA( (HICON)0xdeadbabe, &infoex );
756 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
757 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE,
758 "wrong error %d\n", GetLastError());
760 infoex.cbSize = sizeof(infoex);
761 ret = pGetIconInfoExA( hIcon, &infoex );
762 ok_(__FILE__, line)(ret, "GetIconInfoEx failed err %d\n", GetLastError());
763 ok_(__FILE__, line)(infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID);
764 ok_(__FILE__, line)(infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName);
765 ok_(__FILE__, line)(infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName);
769 #define test_icon_info(a,b,c,d) test_icon_info_dbg((a),(b),(c),(d),__LINE__)
771 static void test_CreateIcon(void)
773 static const BYTE bmp_bits[1024];
775 HBITMAP hbmMask, hbmColor;
783 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
785 /* these crash under XP
786 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
787 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
790 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
791 ok(hIcon != 0, "CreateIcon failed\n");
792 test_icon_info(hIcon, 16, 16, 1);
795 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
796 ok(hIcon != 0, "CreateIcon failed\n");
797 test_icon_info(hIcon, 16, 16, display_bpp);
800 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
801 ok(hbmMask != 0, "CreateBitmap failed\n");
802 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
803 ok(hbmColor != 0, "CreateBitmap failed\n");
810 SetLastError(0xdeadbeaf);
811 hIcon = CreateIconIndirect(&info);
812 ok(!hIcon, "CreateIconIndirect should fail\n");
813 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
819 info.hbmColor = hbmColor;
820 SetLastError(0xdeadbeaf);
821 hIcon = CreateIconIndirect(&info);
822 ok(!hIcon, "CreateIconIndirect should fail\n");
823 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
828 info.hbmMask = hbmMask;
829 info.hbmColor = hbmColor;
830 hIcon = CreateIconIndirect(&info);
831 ok(hIcon != 0, "CreateIconIndirect failed\n");
832 test_icon_info(hIcon, 16, 16, display_bpp);
835 DeleteObject(hbmMask);
836 DeleteObject(hbmColor);
838 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
839 ok(hbmMask != 0, "CreateBitmap failed\n");
844 info.hbmMask = hbmMask;
846 SetLastError(0xdeadbeaf);
847 hIcon = CreateIconIndirect(&info);
848 ok(hIcon != 0, "CreateIconIndirect failed\n");
849 test_icon_info(hIcon, 16, 16, 1);
852 DeleteObject(hbmMask);
853 DeleteObject(hbmColor);
855 /* test creating an icon from a DIB section */
857 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
858 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
859 bmpinfo->bmiHeader.biWidth = 32;
860 bmpinfo->bmiHeader.biHeight = 32;
861 bmpinfo->bmiHeader.biPlanes = 1;
862 bmpinfo->bmiHeader.biBitCount = 8;
863 bmpinfo->bmiHeader.biCompression = BI_RGB;
864 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
865 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
867 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
868 bmpinfo->bmiHeader.biBitCount = 1;
869 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
870 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
872 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
877 info.hbmMask = hbmColor;
878 info.hbmColor = hbmMask;
879 SetLastError(0xdeadbeaf);
880 hIcon = CreateIconIndirect(&info);
881 ok(hIcon != 0, "CreateIconIndirect failed\n");
882 test_icon_info(hIcon, 32, 32, 8);
884 DeleteObject(hbmColor);
886 bmpinfo->bmiHeader.biBitCount = 16;
887 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
888 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
890 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
895 info.hbmMask = hbmColor;
896 info.hbmColor = hbmMask;
897 SetLastError(0xdeadbeaf);
898 hIcon = CreateIconIndirect(&info);
899 ok(hIcon != 0, "CreateIconIndirect failed\n");
900 test_icon_info(hIcon, 32, 32, 8);
902 DeleteObject(hbmColor);
904 bmpinfo->bmiHeader.biBitCount = 32;
905 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
906 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
908 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
913 info.hbmMask = hbmColor;
914 info.hbmColor = hbmMask;
915 SetLastError(0xdeadbeaf);
916 hIcon = CreateIconIndirect(&info);
917 ok(hIcon != 0, "CreateIconIndirect failed\n");
918 test_icon_info(hIcon, 32, 32, 8);
921 DeleteObject(hbmMask);
922 DeleteObject(hbmColor);
923 HeapFree( GetProcessHeap(), 0, bmpinfo );
928 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
930 static unsigned char gifimage[35] = {
931 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
932 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
937 static unsigned char jpgimage[285] = {
938 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
939 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
940 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
941 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
942 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
943 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
944 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
945 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
946 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
947 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
948 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
949 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
950 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
951 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
952 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
953 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
954 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
955 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
959 static unsigned char pngimage[285] = {
960 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
961 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
962 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
963 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
964 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
965 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
966 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
969 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
970 zeroes, gap is 0xFF. */
971 static unsigned char bmpimage[70] = {
972 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
973 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
974 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
975 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
976 0xFF,0xFF,0x00,0x00,0x00,0x00
979 /* 1x1 pixel bmp using BITMAPCOREHEADER */
980 static unsigned char bmpcoreimage[38] = {
981 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
982 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
983 0x55,0x00,0x00,0x00,0x00,0x00
987 static unsigned char gif4pixel[42] = {
988 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
989 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
990 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
993 static const DWORD biSize_tests[] = {
995 sizeof(BITMAPCOREHEADER) - 1,
996 sizeof(BITMAPCOREHEADER) + 1,
997 sizeof(BITMAPINFOHEADER) - 1,
998 sizeof(BITMAPINFOHEADER) + 1,
999 sizeof(BITMAPV4HEADER) - 1,
1000 sizeof(BITMAPV4HEADER) + 1,
1001 sizeof(BITMAPV5HEADER) - 1,
1002 sizeof(BITMAPV5HEADER) + 1,
1003 (sizeof(BITMAPCOREHEADER) + sizeof(BITMAPINFOHEADER)) / 2,
1004 (sizeof(BITMAPV4HEADER) + sizeof(BITMAPV5HEADER)) / 2,
1009 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1011 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1015 DWORD ret, pixel = 0;
1016 HDC hdc = GetDC(NULL);
1018 ret = GetObject(hbm, sizeof(bm), &bm);
1019 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1021 memset(&bmi, 0, sizeof(bmi));
1022 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1023 bmi.bmiHeader.biWidth = bm.bmWidth;
1024 bmi.bmiHeader.biHeight = bm.bmHeight;
1025 bmi.bmiHeader.biPlanes = 1;
1026 bmi.bmiHeader.biBitCount= 24;
1027 bmi.bmiHeader.biCompression= BI_RGB;
1028 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
1029 ok(ret == bm.bmHeight, "%s: %d lines were converted, not %d\n", test_desc, ret, bm.bmHeight);
1031 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1034 static void test_LoadImageFile(const char * test_desc, unsigned char * image_data,
1035 unsigned int image_size, const char * ext, BOOL expect_success)
1039 DWORD error, bytes_written;
1042 strcpy(filename, "test.");
1043 strcat(filename, ext);
1045 /* Create the test image. */
1046 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1047 FILE_ATTRIBUTE_NORMAL, NULL);
1048 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1049 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
1050 ok(ret && bytes_written == image_size, "test file created improperly.\n");
1051 CloseHandle(handle);
1053 /* Load as cursor. For all tested formats, this should fail */
1054 SetLastError(0xdeadbeef);
1055 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1056 ok(handle == NULL, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc);
1057 error = GetLastError();
1059 broken(error == 0xdeadbeef) || /* Win9x */
1060 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1061 "Last error: %u\n", error);
1062 if (handle != NULL) DestroyCursor(handle);
1064 /* Load as icon. For all tested formats, this should fail */
1065 SetLastError(0xdeadbeef);
1066 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
1067 ok(handle == NULL, "%s: IMAGE_ICON 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) DestroyIcon(handle);
1075 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1076 SetLastError(0xdeadbeef);
1077 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
1078 error = GetLastError();
1080 error == 0xdeadbeef, /* Win9x, WinMe */
1081 "Last error: %u\n", error);
1083 if (expect_success) {
1084 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1085 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1087 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1089 if (handle != NULL) DeleteObject(handle);
1090 DeleteFileA(filename);
1093 static void test_LoadImage(void)
1097 DWORD error, bytes_written;
1098 CURSORICONFILEDIR *icon_data;
1099 CURSORICONFILEDIRENTRY *icon_entry;
1100 BITMAPINFOHEADER *icon_header, *bitmap_header;
1104 #define ICON_WIDTH 32
1105 #define ICON_HEIGHT 32
1106 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1109 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1110 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1112 /* Set icon data. */
1113 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
1114 icon_data->idReserved = 0;
1115 icon_data->idType = 1;
1116 icon_data->idCount = 1;
1118 icon_entry = icon_data->idEntries;
1119 icon_entry->bWidth = ICON_WIDTH;
1120 icon_entry->bHeight = ICON_HEIGHT;
1121 icon_entry->bColorCount = 0;
1122 icon_entry->bReserved = 0;
1123 icon_entry->xHotspot = 1;
1124 icon_entry->yHotspot = 1;
1125 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
1126 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
1128 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
1129 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1130 icon_header->biWidth = ICON_WIDTH;
1131 icon_header->biHeight = ICON_HEIGHT*2;
1132 icon_header->biPlanes = 1;
1133 icon_header->biBitCount = ICON_BPP;
1134 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1136 /* Create the icon. */
1137 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1138 FILE_ATTRIBUTE_NORMAL, NULL);
1139 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1140 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
1141 ok(ret && bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
1142 CloseHandle(handle);
1144 /* Test loading an icon as a cursor. */
1145 SetLastError(0xdeadbeef);
1146 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1147 ok(handle != NULL, "LoadImage() failed.\n");
1148 error = GetLastError();
1150 broken(error == 0xdeadbeef) || /* Win9x */
1151 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1152 "Last error: %u\n", error);
1154 /* Test the icon information. */
1155 SetLastError(0xdeadbeef);
1156 ret = GetIconInfo(handle, &icon_info);
1157 ok(ret, "GetIconInfo() failed.\n");
1158 error = GetLastError();
1159 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1163 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1164 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
1165 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
1166 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1168 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1171 if (pGetIconInfoExA)
1174 infoex.cbSize = sizeof(infoex);
1175 ret = pGetIconInfoExA( handle, &infoex );
1176 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1177 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1178 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1179 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1181 else win_skip( "GetIconInfoEx not available\n" );
1184 SetLastError(0xdeadbeef);
1185 ret = DestroyCursor(handle);
1186 ok(ret, "DestroyCursor() failed.\n");
1187 error = GetLastError();
1188 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1190 HeapFree(GetProcessHeap(), 0, icon_data);
1191 DeleteFileA("icon.ico");
1193 /* Test a system icon */
1194 handle = LoadIcon( 0, IDI_HAND );
1195 ok(handle != NULL, "LoadImage() failed.\n");
1196 if (pGetIconInfoExA)
1198 ICONINFOEXA infoexA;
1199 ICONINFOEXW infoexW;
1200 infoexA.cbSize = sizeof(infoexA);
1201 ret = pGetIconInfoExA( handle, &infoexA );
1202 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1203 ok( infoexA.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexA.wResID );
1204 /* the A version is broken on 64-bit, it truncates the string after the first char */
1205 if (is_win64 && infoexA.szModName[0] && infoexA.szModName[1] == 0)
1206 trace( "GetIconInfoExA broken on Win64\n" );
1208 ok( GetModuleHandleA(infoexA.szModName) == GetModuleHandleA("user32.dll"),
1209 "GetIconInfoEx wrong module %s\n", infoexA.szModName );
1210 ok( infoexA.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA.szResName );
1211 infoexW.cbSize = sizeof(infoexW);
1212 ret = pGetIconInfoExW( handle, &infoexW );
1213 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1214 ok( infoexW.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexW.wResID );
1215 ok( GetModuleHandleW(infoexW.szModName) == GetModuleHandleA("user32.dll"),
1216 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW.szModName) );
1217 ok( infoexW.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW.szResName) );
1219 SetLastError(0xdeadbeef);
1220 DestroyIcon(handle);
1222 test_LoadImageFile("BMP", bmpimage, sizeof(bmpimage), "bmp", 1);
1223 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage, sizeof(bmpcoreimage), "bmp", 1);
1224 test_LoadImageFile("GIF", gifimage, sizeof(gifimage), "gif", 0);
1225 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel, sizeof(gif4pixel), "gif", 0);
1226 test_LoadImageFile("JPG", jpgimage, sizeof(jpgimage), "jpg", 0);
1227 test_LoadImageFile("PNG", pngimage, sizeof(pngimage), "png", 0);
1229 /* Check failure for broken BMP images */
1230 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1232 bitmap_header->biHeight = 65536;
1233 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1234 bitmap_header->biHeight = 1;
1236 bitmap_header->biWidth = 65536;
1237 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1238 bitmap_header->biWidth = 1;
1240 for (i = 0; i < ARRAY_SIZE(biSize_tests); i++) {
1241 bitmap_header->biSize = biSize_tests[i];
1242 test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
1244 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1249 static void test_CreateIconFromResource(void)
1254 BITMAPINFOHEADER *icon_header;
1258 #define ICON_RES_WIDTH 32
1259 #define ICON_RES_HEIGHT 32
1260 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1261 #define ICON_RES_BPP 32
1262 #define ICON_RES_SIZE \
1263 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1264 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1266 /* Set icon data. */
1267 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1269 /* Cursor resources have an extra hotspot, icon resources not. */
1273 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1274 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1275 icon_header->biWidth = ICON_WIDTH;
1276 icon_header->biHeight = ICON_HEIGHT*2;
1277 icon_header->biPlanes = 1;
1278 icon_header->biBitCount = ICON_BPP;
1279 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1281 /* Test creating a cursor. */
1282 SetLastError(0xdeadbeef);
1283 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1284 ok(handle != NULL, "Create cursor failed.\n");
1286 /* Test the icon information. */
1287 SetLastError(0xdeadbeef);
1288 ret = GetIconInfo(handle, &icon_info);
1289 ok(ret, "GetIconInfo() failed.\n");
1290 error = GetLastError();
1291 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1295 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1296 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1297 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1298 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1300 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1303 if (pGetIconInfoExA)
1306 infoex.cbSize = sizeof(infoex);
1307 ret = pGetIconInfoExA( handle, &infoex );
1308 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1309 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1310 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1311 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1315 SetLastError(0xdeadbeef);
1316 ret = DestroyCursor(handle);
1317 ok(ret, "DestroyCursor() failed.\n");
1318 error = GetLastError();
1319 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1321 /* Test creating an icon. */
1322 SetLastError(0xdeadbeef);
1323 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1325 ok(handle != NULL, "Create icon failed.\n");
1327 /* Test the icon information. */
1328 SetLastError(0xdeadbeef);
1329 ret = GetIconInfo(handle, &icon_info);
1330 ok(ret, "GetIconInfo() failed.\n");
1331 error = GetLastError();
1332 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1336 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
1337 /* Icons always have hotspot in the middle */
1338 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
1339 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
1340 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
1341 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1345 SetLastError(0xdeadbeef);
1346 ret = DestroyCursor(handle);
1347 ok(ret, "DestroyCursor() failed.\n");
1348 error = GetLastError();
1349 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1351 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1353 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1354 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1356 HeapFree(GetProcessHeap(), 0, hotspot);
1358 /* Test creating an animated cursor. */
1359 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1360 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1361 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1362 handle = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1363 ok(handle != NULL, "Create cursor failed.\n");
1365 /* Test the animated cursor's information. */
1366 SetLastError(0xdeadbeef);
1367 ret = GetIconInfo(handle, &icon_info);
1368 ok(ret, "GetIconInfo() failed.\n");
1369 error = GetLastError();
1370 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1374 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1375 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1376 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1377 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1379 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1383 SetLastError(0xdeadbeef);
1384 ret = DestroyCursor(handle);
1385 ok(ret, "DestroyCursor() failed.\n");
1386 error = GetLastError();
1387 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1390 static HCURSOR WINAPI (*pGetCursorFrameInfo)(HCURSOR hCursor, VOID *unk1, VOID *unk2, VOID *unk3, VOID *unk4);
1391 static void test_GetCursorFrameInfo(void)
1393 HBITMAP bmp = NULL, bmpOld = NULL;
1394 DWORD unk1, unk2, unk3, unk4;
1395 BITMAPINFOHEADER *icon_header;
1396 BITMAPINFO bitmapInfo;
1404 if (!pGetCursorFrameInfo)
1406 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1410 hdc = CreateCompatibleDC(0);
1411 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1415 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1416 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1417 bitmapInfo.bmiHeader.biWidth = 3;
1418 bitmapInfo.bmiHeader.biHeight = 3;
1419 bitmapInfo.bmiHeader.biBitCount = 32;
1420 bitmapInfo.bmiHeader.biPlanes = 1;
1421 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1422 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1423 bmp = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1424 ok (bmp && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1427 bmpOld = SelectObject(hdc, bmp);
1429 #define ICON_RES_WIDTH 32
1430 #define ICON_RES_HEIGHT 32
1431 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1432 #define ICON_RES_BPP 32
1433 #define ICON_RES_SIZE \
1434 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1435 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1437 /* Set icon data. */
1438 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1440 /* Cursor resources have an extra hotspot, icon resources not. */
1444 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1445 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1446 icon_header->biWidth = ICON_WIDTH;
1447 icon_header->biHeight = ICON_HEIGHT*2;
1448 icon_header->biPlanes = 1;
1449 icon_header->biBitCount = ICON_BPP;
1450 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1452 /* Creating a static cursor. */
1453 SetLastError(0xdeadbeef);
1454 h1 = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1455 ok(h1 != NULL, "Create cursor failed.\n");
1457 /* Check GetCursorFrameInfo behavior on a static cursor */
1458 unk1 = unk2 = unk3 = unk4 = 0xdead;
1459 h2 = pGetCursorFrameInfo(h1, &unk1, &unk2, &unk3, &unk4);
1460 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1461 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1462 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1463 ok(unk3 == 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", unk3);
1464 ok(unk4 == 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", unk4);
1466 /* Clean up static cursor. */
1467 ret = DestroyCursor(h1);
1468 ok(ret, "DestroyCursor() failed.\n");
1470 /* Creating a single-frame animated cursor. */
1471 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1472 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1473 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1474 h1 = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1475 ok(h1 != NULL, "Create cursor failed.\n");
1477 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1478 unk1 = unk2 = unk3 = unk4 = 0xdead;
1479 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)0, &unk3, &unk4);
1480 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1481 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1482 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1483 ok(unk3 == 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", unk3);
1484 ok(unk4 == empty_anicursor.header.header.num_steps,
1485 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", unk4);
1487 /* Clean up single-frame animated cursor. */
1488 ret = DestroyCursor(h1);
1489 ok(ret, "DestroyCursor() failed.\n");
1491 /* Creating a multi-frame animated cursor. */
1492 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1494 empty_anicursor3.frames[i].data.icon_info.idType = 2; /* type: cursor */
1495 empty_anicursor3.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1496 empty_anicursor3.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1498 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1499 ok(h1 != NULL, "Create cursor failed.\n");
1501 /* Check number of steps in multi-frame animated cursor */
1503 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1505 ok(i == empty_anicursor3.header.header.num_steps,
1506 "Unexpected number of steps in cursor (%d != %d)\n",
1507 i, empty_anicursor3.header.header.num_steps);
1509 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1510 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1512 unk1 = unk2 = unk3 = unk4 = 0xdead;
1513 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)i, &unk3, &unk4);
1514 ok(h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p == 0).\n", h1, h2);
1515 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1516 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1517 ok(unk3 == empty_anicursor3.header.header.display_rate,
1518 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1519 unk3, empty_anicursor3.header.header.display_rate);
1520 ok(unk4 == empty_anicursor3.header.header.num_steps,
1521 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1522 unk4, empty_anicursor3.header.header.num_steps);
1525 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1526 unk1 = unk2 = unk3 = unk4 = 0xdead;
1527 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)3, &unk3, &unk4);
1528 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1529 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1530 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1531 ok(unk3 == 0xdead || broken(unk3 == empty_anicursor3.header.header.display_rate) /*win2k*/
1532 || broken(unk3 == ~0) /*win2k (sporadic)*/,
1533 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", unk3);
1534 ok(unk4 == 0xdead || broken(unk4 == empty_anicursor3.header.header.num_steps) /*win2k*/
1535 || broken(unk4 == 0) /*win2k (sporadic)*/,
1536 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", unk4);
1538 /* Clean up multi-frame animated cursor. */
1539 ret = DestroyCursor(h1);
1540 ok(ret, "DestroyCursor() failed.\n");
1542 /* Create a multi-frame animated cursor with num_steps == 1 */
1543 empty_anicursor3.header.header.num_steps = 1;
1544 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1545 ok(h1 != NULL, "Create cursor failed.\n");
1547 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1549 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1551 ok(i == empty_anicursor3.header.header.num_steps,
1552 "Unexpected number of steps in cursor (%d != %d)\n",
1553 i, empty_anicursor3.header.header.num_steps);
1555 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1556 unk1 = unk2 = unk3 = unk4 = 0xdead;
1557 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)0, &unk3, &unk4);
1558 ok(h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p == 0).\n", h1, h2);
1559 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1560 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1561 ok(unk3 == empty_anicursor3.header.header.display_rate,
1562 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1563 unk3, empty_anicursor3.header.header.display_rate);
1564 ok(unk4 == ~0 || broken(unk4 == empty_anicursor3.header.header.num_steps) /*win2k*/,
1565 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", unk4);
1567 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1568 unk1 = unk2 = unk3 = unk4 = 0xdead;
1569 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)1, &unk3, &unk4);
1570 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1571 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1572 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1573 ok(unk3 == 0xdead || broken(unk3 == empty_anicursor3.header.header.display_rate) /*win2k*/
1574 || broken(unk3 == ~0) /*win2k (sporadic)*/,
1575 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", unk3);
1576 ok(unk4 == 0xdead || broken(unk4 == empty_anicursor3.header.header.num_steps) /*win2k*/
1577 || broken(unk4 == 0) /*win2k (sporadic)*/,
1578 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", unk4);
1580 /* Clean up multi-frame animated cursor. */
1581 ret = DestroyCursor(h1);
1582 ok(ret, "DestroyCursor() failed.\n");
1584 /* Creating a multi-frame animated cursor with rate data. */
1585 for (i=0; i<empty_anicursor3_rate.header.header.num_frames; i++)
1587 empty_anicursor3_rate.frames[i].data.icon_info.idType = 2; /* type: cursor */
1588 empty_anicursor3_rate.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1589 empty_anicursor3_rate.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1591 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3_rate, sizeof(empty_anicursor3_rate), FALSE, 0x00030000);
1592 ok(h1 != NULL, "Create cursor failed.\n");
1594 /* Check number of steps in multi-frame animated cursor with rate data */
1596 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1598 ok(i == empty_anicursor3_rate.header.header.num_steps,
1599 "Unexpected number of steps in cursor (%d != %d)\n",
1600 i, empty_anicursor3_rate.header.header.num_steps);
1602 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1603 for (i=0; i<empty_anicursor3_rate.header.header.num_frames; i++)
1605 unk1 = unk2 = unk3 = unk4 = 0xdead;
1606 h2 = pGetCursorFrameInfo(h1, &unk1, (VOID*)i, &unk3, &unk4);
1607 ok(h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1608 ok(unk1 == 0xdead, "GetCursorFrameInfo() unexpected param 2 value (0x%x != 0xdead).\n", unk1);
1609 ok(unk2 == 0xdead, "GetCursorFrameInfo() unexpected param 3 value (0x%x != 0xdead).\n", unk2);
1610 ok(unk3 == empty_anicursor3_rate.rates.rate[i],
1611 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1612 unk3, empty_anicursor3_rate.rates.rate[i]);
1613 ok(unk4 == empty_anicursor3_rate.header.header.num_steps,
1614 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1615 unk4, empty_anicursor3_rate.header.header.num_steps);
1618 /* Clean up multi-frame animated cursor with rate data. */
1619 ret = DestroyCursor(h1);
1620 ok(ret, "DestroyCursor() failed.\n");
1623 if(bmpOld) SelectObject(hdc, bmpOld);
1624 if(bmp) DeleteObject(bmp);
1625 if(hdc) DeleteDC(hdc);
1628 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1629 BOOL maskvalue, UINT32 *color, int colorSize)
1632 BITMAPINFO bitmapInfo;
1633 void *buffer = NULL;
1634 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1636 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1637 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1638 bitmapInfo.bmiHeader.biWidth = width;
1639 bitmapInfo.bmiHeader.biHeight = height;
1640 bitmapInfo.bmiHeader.biPlanes = 1;
1641 bitmapInfo.bmiHeader.biBitCount = bpp;
1642 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1643 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1645 iconInfo.fIcon = TRUE;
1646 iconInfo.xHotspot = 0;
1647 iconInfo.yHotspot = 0;
1649 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1650 if(!iconInfo.hbmMask) return NULL;
1652 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1653 if(!iconInfo.hbmColor || !buffer)
1655 DeleteObject(iconInfo.hbmMask);
1659 memcpy(buffer, color, colorSize);
1661 return CreateIconIndirect(&iconInfo);
1664 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1668 COLORREF modern_expected, legacy_expected, result;
1670 color[0] = 0x00A0B0C0;
1671 color[1] = alpha ? 0xFF000000 : 0x00000000;
1672 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1673 legacy_expected = 0x00C0B0A0;
1675 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1678 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1681 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1683 DrawIcon(hdc, 0, 0, hicon);
1685 result = GetPixel(hdc, 0, 0);
1686 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1687 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1688 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1689 "Got %06X from line %d\n",
1690 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1691 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1694 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1695 COLORREF modern_expected, COLORREF legacy_expected, int line)
1698 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1700 SetPixelV(hdc, 0, 0, background);
1701 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1702 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1703 DrawIcon(hdc, 0, 0, hicon);
1704 result = GetPixel(hdc, 0, 0);
1706 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1707 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1708 "Overlaying Mask %d on Color %06X with DrawIcon. "
1709 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1710 maskvalue, color, modern_expected, legacy_expected, result, line);
1712 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1714 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1715 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1716 "Overlaying Mask %d on Color %06X with DrawIcon. "
1717 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1718 maskvalue, color, modern_expected, legacy_expected, result, line);
1720 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1722 ok (color_match(result, background),
1723 "Overlaying Mask %d on Color %06X with DrawIcon. "
1724 "Expected unchanged background color %06X. Got %06X from line %d\n",
1725 maskvalue, color, background, result, line);
1728 static void test_DrawIcon(void)
1730 BITMAPINFO bitmapInfo;
1732 HBITMAP bmpDst = NULL;
1733 HBITMAP bmpOld = NULL;
1736 hdcDst = CreateCompatibleDC(0);
1737 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1741 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1743 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palletizing.\n");
1747 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1748 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1749 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1750 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1751 bitmapInfo.bmiHeader.biBitCount = 32;
1752 bitmapInfo.bmiHeader.biPlanes = 1;
1753 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1754 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1756 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1757 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1758 if (!bmpDst || !bits)
1760 bmpOld = SelectObject(hdcDst, bmpDst);
1762 /* Mask is only heeded if alpha channel is always zero */
1763 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1764 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1766 /* Test alpha blending */
1767 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1768 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1769 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1771 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1772 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1773 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1774 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1776 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1777 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1779 /* Test detecting of alpha channel */
1780 /* If a single pixel's alpha channel is non-zero, the icon
1781 will be alpha blended, otherwise it will be draw with
1783 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1784 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1788 SelectObject(hdcDst, bmpOld);
1790 DeleteObject(bmpDst);
1795 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1796 COLORREF modern_expected, COLORREF legacy_expected, int line)
1799 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1801 SetPixelV(hdc, 0, 0, background);
1802 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1803 result = GetPixel(hdc, 0, 0);
1805 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1806 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1807 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1808 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1809 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1812 static void test_DrawIconEx(void)
1814 BITMAPINFO bitmapInfo;
1816 HBITMAP bmpDst = NULL;
1817 HBITMAP bmpOld = NULL;
1820 hdcDst = CreateCompatibleDC(0);
1821 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1825 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1827 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1831 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1832 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1833 bitmapInfo.bmiHeader.biWidth = 1;
1834 bitmapInfo.bmiHeader.biHeight = 1;
1835 bitmapInfo.bmiHeader.biBitCount = 32;
1836 bitmapInfo.bmiHeader.biPlanes = 1;
1837 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1838 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1839 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1840 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1841 if (!bmpDst || !bits)
1843 bmpOld = SelectObject(hdcDst, bmpDst);
1845 /* Test null, image only, and mask only drawing */
1846 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1847 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1849 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00000000, 0x00000000, __LINE__);
1850 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1852 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1853 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1855 /* Test normal drawing */
1856 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1857 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1858 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1860 /* Test alpha blending */
1861 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1862 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1864 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1865 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1866 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1867 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1869 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1870 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1872 /* Test detecting of alpha channel */
1873 /* If a single pixel's alpha channel is non-zero, the icon
1874 will be alpha blended, otherwise it will be draw with
1876 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1877 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1881 SelectObject(hdcDst, bmpOld);
1883 DeleteObject(bmpDst);
1888 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1890 COLORREF result, background;
1892 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1893 background = 0x00FFFFFF;
1894 /* Set color of the 2 pixels that will be checked afterwards */
1895 SetPixelV(hdc, 0, 0, background);
1896 SetPixelV(hdc, 2, 2, background);
1898 /* Let DrawState calculate the size of the icon (it's 1x1) */
1899 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1901 result = GetPixel(hdc, 0, 0);
1902 passed[0] = color_match(result, background);
1903 result = GetPixel(hdc, 2, 2);
1904 passed[0] = passed[0] & color_match(result, background);
1906 /* Check if manually specifying the icon size DOESN'T work */
1908 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1909 * size in which it should be ultimately drawn. Therefore giving
1910 * width/height 2x2 if the icon is only 1x1 pixels in size should
1911 * result in drawing it with size 1x1. The size parameters must be
1912 * ignored if a Icon has to be drawn! */
1913 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1915 result = GetPixel(hdc, 0, 0);
1916 passed[1] = color_match(result, background);
1917 result = GetPixel(hdc, 2, 2);
1918 passed[1] = passed[0] & color_match(result, background);
1920 if(!passed[0]&&!passed[1])
1922 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
1923 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
1924 "Color %06X with flags %08X. Line %d\n",
1925 maskvalue, color, (DST_ICON | flags), line);
1928 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1929 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
1930 "Mask %d on Color %06X with flags %08X. Line %d\n",
1931 maskvalue, color, (DST_ICON | flags), line);
1934 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1935 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
1936 "Color %06X with flags %08X. Line %d\n",
1937 maskvalue, color, (DST_ICON | flags), line);
1940 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
1941 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
1944 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1946 /* Set color of the pixel that will be checked afterwards */
1947 SetPixelV(hdc, 1, 1, background);
1949 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
1951 /* Check the color of the pixel is correct */
1952 result = GetPixel(hdc, 1, 1);
1954 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1955 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1956 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
1957 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1958 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
1961 static void test_DrawState(void)
1963 BITMAPINFO bitmapInfo;
1965 HBITMAP bmpDst = NULL;
1966 HBITMAP bmpOld = NULL;
1969 hdcDst = CreateCompatibleDC(0);
1970 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1974 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1976 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1980 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1981 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1982 bitmapInfo.bmiHeader.biWidth = 3;
1983 bitmapInfo.bmiHeader.biHeight = 3;
1984 bitmapInfo.bmiHeader.biBitCount = 32;
1985 bitmapInfo.bmiHeader.biPlanes = 1;
1986 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1987 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1988 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1989 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1990 if (!bmpDst || !bits)
1992 bmpOld = SelectObject(hdcDst, bmpDst);
1994 /* potential flags to test with DrawState are: */
1995 /* DSS_DISABLED embosses the icon */
1996 /* DSS_MONO draw Icon using a brush as parameter 5 */
1997 /* DSS_NORMAL draw Icon without any modifications */
1998 /* DSS_UNION draw the Icon dithered */
2000 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
2001 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
2005 SelectObject(hdcDst, bmpOld);
2007 DeleteObject(bmpDst);
2012 static DWORD parent_id;
2014 static DWORD CALLBACK set_cursor_thread( void *arg )
2018 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2021 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2022 ok( ret, "AttachThreadInput failed\n" );
2024 if (arg) ret = SetCursor( (HCURSOR)arg );
2025 else ret = GetCursor();
2026 return (DWORD_PTR)ret;
2029 static void test_SetCursor(void)
2031 static const BYTE bmp_bits[4096];
2032 ICONINFO cursorInfo;
2033 HCURSOR cursor, old_cursor, global_cursor = 0;
2034 DWORD error, id, result;
2042 memset( &info, 0, sizeof(info) );
2043 info.cbSize = sizeof(info);
2044 if (!pGetCursorInfo( &info ))
2046 win_skip( "GetCursorInfo not working\n" );
2047 pGetCursorInfo = NULL;
2049 else global_cursor = info.hCursor;
2051 cursor = GetCursor();
2052 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2053 WaitForSingleObject( thread, 1000 );
2054 GetExitCodeThread( thread, &result );
2055 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
2058 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2061 cursorInfo.fIcon = FALSE;
2062 cursorInfo.xHotspot = 0;
2063 cursorInfo.yHotspot = 0;
2064 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2065 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2067 cursor = CreateIconIndirect(&cursorInfo);
2068 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2069 old_cursor = SetCursor( cursor );
2073 info.cbSize = sizeof(info);
2074 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2075 /* global cursor doesn't change since we don't have a window */
2076 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2077 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2079 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2080 WaitForSingleObject( thread, 1000 );
2081 GetExitCodeThread( thread, &result );
2082 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2085 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2086 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2087 WaitForSingleObject( thread, 1000 );
2088 GetExitCodeThread( thread, &result );
2089 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2091 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2092 WaitForSingleObject( thread, 1000 );
2093 GetExitCodeThread( thread, &result );
2094 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2095 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2097 parent_id = GetCurrentThreadId();
2098 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2099 WaitForSingleObject( thread, 1000 );
2100 GetExitCodeThread( thread, &result );
2101 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2102 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
2106 info.cbSize = sizeof(info);
2107 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2108 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2109 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2111 SetCursor( old_cursor );
2112 DestroyCursor( cursor );
2114 SetLastError( 0xdeadbeef );
2115 cursor = SetCursor( (HCURSOR)0xbadbad );
2116 error = GetLastError();
2117 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
2118 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
2119 "wrong error %u\n", error );
2123 info.cbSize = sizeof(info);
2124 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2125 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2126 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2130 static HANDLE event_start, event_next;
2132 static DWORD CALLBACK show_cursor_thread( void *arg )
2134 DWORD count = (DWORD_PTR)arg;
2137 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2140 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2141 ok( ret, "AttachThreadInput failed\n" );
2143 if (!count) ret = ShowCursor( FALSE );
2144 else while (count--) ret = ShowCursor( TRUE );
2145 SetEvent( event_start );
2146 WaitForSingleObject( event_next, 2000 );
2150 static void test_ShowCursor(void)
2159 memset( &info, 0, sizeof(info) );
2160 info.cbSize = sizeof(info);
2161 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2162 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2165 event_start = CreateEvent( NULL, FALSE, FALSE, NULL );
2166 event_next = CreateEvent( NULL, FALSE, FALSE, NULL );
2168 count = ShowCursor( TRUE );
2169 ok( count == 1, "wrong count %d\n", count );
2170 count = ShowCursor( TRUE );
2171 ok( count == 2, "wrong count %d\n", count );
2172 count = ShowCursor( FALSE );
2173 ok( count == 1, "wrong count %d\n", count );
2174 count = ShowCursor( FALSE );
2175 ok( count == 0, "wrong count %d\n", count );
2176 count = ShowCursor( FALSE );
2177 ok( count == -1, "wrong count %d\n", count );
2178 count = ShowCursor( FALSE );
2179 ok( count == -2, "wrong count %d\n", count );
2183 info.cbSize = sizeof(info);
2184 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2185 /* global show count is not affected since we don't have a window */
2186 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2190 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2191 WaitForSingleObject( event_start, 1000 );
2192 count = ShowCursor( FALSE );
2193 ok( count == -3, "wrong count %d\n", count );
2194 SetEvent( event_next );
2195 WaitForSingleObject( thread, 1000 );
2196 GetExitCodeThread( thread, &result );
2197 ok( result == -1, "wrong thread count %d\n", result );
2198 count = ShowCursor( FALSE );
2199 ok( count == -4, "wrong count %d\n", count );
2201 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
2202 WaitForSingleObject( event_start, 1000 );
2203 count = ShowCursor( TRUE );
2204 ok( count == -3, "wrong count %d\n", count );
2205 SetEvent( event_next );
2206 WaitForSingleObject( thread, 1000 );
2207 GetExitCodeThread( thread, &result );
2208 ok( result == 1, "wrong thread count %d\n", result );
2209 count = ShowCursor( TRUE );
2210 ok( count == -2, "wrong count %d\n", count );
2212 parent_id = GetCurrentThreadId();
2213 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2214 WaitForSingleObject( event_start, 1000 );
2215 count = ShowCursor( TRUE );
2216 ok( count == -2, "wrong count %d\n", count );
2217 SetEvent( event_next );
2218 WaitForSingleObject( thread, 1000 );
2219 GetExitCodeThread( thread, &result );
2220 ok( result == -3, "wrong thread count %d\n", result );
2221 count = ShowCursor( FALSE );
2222 ok( count == -2, "wrong count %d\n", count );
2224 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
2225 WaitForSingleObject( event_start, 1000 );
2226 count = ShowCursor( TRUE );
2227 ok( count == 2, "wrong count %d\n", count );
2228 SetEvent( event_next );
2229 WaitForSingleObject( thread, 1000 );
2230 GetExitCodeThread( thread, &result );
2231 ok( result == 1, "wrong thread count %d\n", result );
2232 count = ShowCursor( FALSE );
2233 ok( count == -2, "wrong count %d\n", count );
2237 info.cbSize = sizeof(info);
2238 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2239 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2242 count = ShowCursor( TRUE );
2243 ok( count == -1, "wrong count %d\n", count );
2244 count = ShowCursor( TRUE );
2245 ok( count == 0, "wrong count %d\n", count );
2249 info.cbSize = sizeof(info);
2250 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2251 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2256 static void test_DestroyCursor(void)
2258 static const BYTE bmp_bits[4096];
2259 ICONINFO cursorInfo, new_info;
2260 HCURSOR cursor, cursor2, new_cursor;
2267 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2270 cursorInfo.fIcon = FALSE;
2271 cursorInfo.xHotspot = 0;
2272 cursorInfo.yHotspot = 0;
2273 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2274 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2276 cursor = CreateIconIndirect(&cursorInfo);
2277 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2283 SetLastError(0xdeadbeef);
2284 ret = DestroyCursor(cursor);
2285 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2286 error = GetLastError();
2287 ok(error == 0xdeadbeef, "Last error: %u\n", error);
2289 new_cursor = GetCursor();
2290 if (ret) /* win9x replaces cursor by another one on destroy */
2291 ok(new_cursor != cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2293 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2295 SetLastError(0xdeadbeef);
2296 ret = GetIconInfo( cursor, &new_info );
2297 ok( !ret || broken(ret), /* nt4 */ "GetIconInfo succeeded\n" );
2298 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2299 broken(GetLastError() == 0xdeadbeef), /* win9x */
2300 "wrong error %u\n", GetLastError() );
2302 if (ret) /* nt4 delays destruction until cursor changes */
2304 DeleteObject( new_info.hbmColor );
2305 DeleteObject( new_info.hbmMask );
2307 SetLastError(0xdeadbeef);
2308 ret = DestroyCursor( cursor );
2309 ok( !ret, "DestroyCursor succeeded\n" );
2310 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2311 "wrong error %u\n", GetLastError() );
2313 SetLastError(0xdeadbeef);
2314 cursor2 = SetCursor( cursor );
2315 ok( cursor2 == cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2316 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2317 "wrong error %u\n", GetLastError() );
2321 SetLastError(0xdeadbeef);
2322 cursor2 = CopyCursor( cursor );
2323 ok(!cursor2, "CopyCursor succeeded\n" );
2324 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2325 broken(GetLastError() == 0xdeadbeef), /* win9x */
2326 "wrong error %u\n", GetLastError() );
2328 SetLastError(0xdeadbeef);
2329 ret = DestroyCursor( cursor );
2330 if (new_cursor != cursor) /* win9x */
2331 ok( ret, "DestroyCursor succeeded\n" );
2333 ok( !ret, "DestroyCursor succeeded\n" );
2334 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2335 "wrong error %u\n", GetLastError() );
2337 SetLastError(0xdeadbeef);
2338 cursor2 = SetCursor( cursor );
2339 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2340 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2341 "wrong error %u\n", GetLastError() );
2344 cursor2 = GetCursor();
2345 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2347 SetLastError(0xdeadbeef);
2348 cursor2 = SetCursor( 0 );
2349 if (new_cursor != cursor) /* win9x */
2350 ok(cursor2 == new_cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2352 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2353 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2355 cursor2 = GetCursor();
2356 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2358 SetLastError(0xdeadbeef);
2359 ret = DestroyCursor(cursor);
2360 if (new_cursor != cursor) /* win9x */
2361 ok( ret, "DestroyCursor succeeded\n" );
2363 ok( !ret, "DestroyCursor succeeded\n" );
2364 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2365 "wrong error %u\n", GetLastError() );
2367 DeleteObject(cursorInfo.hbmMask);
2368 DeleteObject(cursorInfo.hbmColor);
2370 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2371 cursor = LoadCursor(NULL, IDC_ARROW);
2373 SetLastError(0xdeadbeef);
2374 ret = DestroyCursor(cursor);
2375 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2376 error = GetLastError();
2377 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2379 /* Try setting the cursor to a destroyed OEM cursor. */
2380 SetLastError(0xdeadbeef);
2382 error = GetLastError();
2383 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2385 /* Check if LoadCursor() returns the same handle with the same icon. */
2386 cursor2 = LoadCursor(NULL, IDC_ARROW);
2387 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2389 /* Check if LoadCursor() returns the same handle with a different icon. */
2390 cursor2 = LoadCursor(NULL, IDC_WAIT);
2391 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2394 START_TEST(cursoricon)
2396 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2397 pGetIconInfoExA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2398 pGetIconInfoExW = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2399 pGetCursorFrameInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2400 test_argc = winetest_get_mainargs(&test_argv);
2404 /* Child process. */
2405 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2407 ok(parent != NULL, "Parent not found.\n");
2415 test_CopyImage_Bitmap(1);
2416 test_CopyImage_Bitmap(4);
2417 test_CopyImage_Bitmap(8);
2418 test_CopyImage_Bitmap(16);
2419 test_CopyImage_Bitmap(24);
2420 test_CopyImage_Bitmap(32);
2421 test_initial_cursor();
2424 test_CreateIconFromResource();
2425 test_GetCursorFrameInfo();
2431 test_DestroyCursor();
2433 test_child_process();
2434 finish_child_process();