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];
59 static char **test_argv;
61 static HWND child = 0;
62 static HWND parent = 0;
63 static HANDLE child_process;
65 #define PROC_INIT (WM_USER+1)
67 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
69 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
76 /* Destroy the cursor. */
78 SetLastError(0xdeadbeef);
79 ret = DestroyCursor((HCURSOR) lParam);
80 error = GetLastError();
81 todo_wine ok(!ret || broken(ret) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
82 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD ||
83 error == 0xdeadbeef, /* vista */
84 "Last error: %u\n", error);
91 return DefWindowProc(hwnd, msg, wParam, lParam);
94 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
98 child = (HWND) wParam;
102 return DefWindowProc(hwnd, msg, wParam, lParam);
105 static void do_child(void)
111 /* Register a new class. */
112 class.style = CS_GLOBALCLASS;
113 class.lpfnWndProc = callback_child;
114 class.cbClsExtra = 0;
115 class.cbWndExtra = 0;
116 class.hInstance = GetModuleHandle(NULL);
118 class.hCursor = NULL;
119 class.hbrBackground = NULL;
120 class.lpszMenuName = NULL;
121 class.lpszClassName = "cursor_child";
123 SetLastError(0xdeadbeef);
124 ret = RegisterClass(&class);
125 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
127 /* Create a window. */
128 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
129 0, 0, 200, 200, 0, 0, 0, NULL);
130 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
132 /* Let the parent know our HWND. */
133 PostMessage(parent, PROC_INIT, (WPARAM) child, 0);
135 /* Receive messages. */
136 while ((ret = GetMessage(&msg, 0, 0, 0)))
138 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
139 TranslateMessage(&msg);
140 DispatchMessage(&msg);
144 static void do_parent(void)
146 char path_name[MAX_PATH];
147 PROCESS_INFORMATION info;
148 STARTUPINFOA startup;
153 /* Register a new class. */
154 class.style = CS_GLOBALCLASS;
155 class.lpfnWndProc = callback_parent;
156 class.cbClsExtra = 0;
157 class.cbWndExtra = 0;
158 class.hInstance = GetModuleHandle(NULL);
160 class.hCursor = NULL;
161 class.hbrBackground = NULL;
162 class.lpszMenuName = NULL;
163 class.lpszClassName = "cursor_parent";
165 SetLastError(0xdeadbeef);
166 ret = RegisterClass(&class);
167 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
169 /* Create a window. */
170 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
171 0, 0, 200, 200, 0, 0, 0, NULL);
172 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
174 /* Start child process. */
175 memset(&startup, 0, sizeof(startup));
176 startup.cb = sizeof(startup);
177 startup.dwFlags = STARTF_USESHOWWINDOW;
178 startup.wShowWindow = SW_SHOWNORMAL;
180 sprintf(path_name, "%s cursoricon %lx", test_argv[0], (INT_PTR)parent);
181 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
182 child_process = info.hProcess;
184 /* Wait for child window handle. */
185 while ((child == 0) && (ret = GetMessage(&msg, parent, 0, 0)))
187 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
188 TranslateMessage(&msg);
189 DispatchMessage(&msg);
193 static void finish_child_process(void)
195 SendMessage(child, WM_CLOSE, 0, 0);
196 winetest_wait_child_process( child_process );
197 CloseHandle(child_process);
200 static void test_child_process(void)
202 static const BYTE bmp_bits[4096];
208 /* Create and set a dummy cursor. */
210 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
213 cursorInfo.fIcon = FALSE;
214 cursorInfo.xHotspot = 0;
215 cursorInfo.yHotspot = 0;
216 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
217 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
219 cursor = CreateIconIndirect(&cursorInfo);
220 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
224 /* Destroy the cursor. */
225 SendMessage(child, WM_USER+1, 0, (LPARAM) cursor);
228 static BOOL color_match(COLORREF a, COLORREF b)
230 /* 5-bit accuracy is a sufficient test. This will match as long as
231 * colors are never truncated to less that 3x5-bit accuracy i.e.
233 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
236 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
237 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
245 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
246 ok(copy != NULL, "CopyImage() failed\n");
249 GetObject(bitmap, sizeof(origBitmap), &origBitmap);
250 GetObject(copy, sizeof(copyBitmap), ©Bitmap);
251 orig_is_dib = (origBitmap.bmBits != NULL);
252 copy_is_dib = (copyBitmap.bmBits != NULL);
254 if (copy_is_dib && dibExpected
255 && copyBitmap.bmBitsPixel == 24
256 && (expectedDepth == 16 || expectedDepth == 32))
258 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
259 if (GetVersion() & 0x80000000)
265 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
267 /* It's not forbidden to create a DIB section if the flag
268 LR_CREATEDIBSECTION is absent.
269 Windows 9x does this if the bitmap has a depth that doesn't
270 match the screen depth, Windows NT doesn't */
272 expectedDepth = origBitmap.bmBitsPixel;
275 ok((!(dibExpected ^ copy_is_dib)
276 && (copyBitmap.bmWidth == expectedWidth)
277 && (copyBitmap.bmHeight == expectedHeight)
278 && (copyBitmap.bmBitsPixel == expectedDepth)),
279 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
280 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
281 copyWidth, copyHeight, flags,
282 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
283 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
289 static void test_CopyImage_Bitmap(int depth)
298 /* Create a device-independent bitmap (DIB) */
299 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
300 info->bmiHeader.biSize = sizeof(info->bmiHeader);
301 info->bmiHeader.biWidth = 2;
302 info->bmiHeader.biHeight = 2;
303 info->bmiHeader.biPlanes = 1;
304 info->bmiHeader.biBitCount = depth;
305 info->bmiHeader.biCompression = BI_RGB;
307 for (i=0; i < 256; i++)
309 info->bmiColors[i].rgbRed = i;
310 info->bmiColors[i].rgbGreen = i;
311 info->bmiColors[i].rgbBlue = 255 - i;
312 info->bmiColors[i].rgbReserved = 0;
315 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
317 /* Create a device-dependent bitmap (DDB) */
318 screenDC = GetDC(NULL);
319 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
320 if (depth == 1 || depth == screen_depth)
322 ddb = CreateBitmap(2, 2, 1, depth, NULL);
328 ReleaseDC(NULL, screenDC);
332 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
333 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
334 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
335 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
337 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
338 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
339 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
340 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
342 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
343 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
344 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
345 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
347 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
348 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
349 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
350 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
351 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
358 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
359 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
360 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
361 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
364 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
365 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
366 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
367 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
369 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
370 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
371 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
372 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
374 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
375 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
376 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
377 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
378 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
384 /* Special case: A monochrome DIB is converted to a monochrome DDB if
385 the colors in the color table are black and white.
387 Skip this test on Windows 95, it always creates a monochrome DDB
390 if (!(GetVersion() & 0x80000000))
392 info->bmiHeader.biBitCount = 1;
393 info->bmiColors[0].rgbRed = 0xFF;
394 info->bmiColors[0].rgbGreen = 0;
395 info->bmiColors[0].rgbBlue = 0;
396 info->bmiColors[1].rgbRed = 0;
397 info->bmiColors[1].rgbGreen = 0xFF;
398 info->bmiColors[1].rgbBlue = 0;
400 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
401 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
402 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
403 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
404 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
407 info->bmiHeader.biBitCount = 1;
408 info->bmiColors[0].rgbRed = 0;
409 info->bmiColors[0].rgbGreen = 0;
410 info->bmiColors[0].rgbBlue = 0;
411 info->bmiColors[1].rgbRed = 0xFF;
412 info->bmiColors[1].rgbGreen = 0xFF;
413 info->bmiColors[1].rgbBlue = 0xFF;
415 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
416 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
417 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
418 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
419 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
422 info->bmiHeader.biBitCount = 1;
423 info->bmiColors[0].rgbRed = 0xFF;
424 info->bmiColors[0].rgbGreen = 0xFF;
425 info->bmiColors[0].rgbBlue = 0xFF;
426 info->bmiColors[1].rgbRed = 0;
427 info->bmiColors[1].rgbGreen = 0;
428 info->bmiColors[1].rgbBlue = 0;
430 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
431 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
432 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
433 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
434 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
439 HeapFree(GetProcessHeap(), 0, info);
442 static void test_initial_cursor(void)
444 HCURSOR cursor, cursor2;
447 cursor = GetCursor();
449 /* Check what handle GetCursor() returns if a cursor is not set yet. */
450 SetLastError(0xdeadbeef);
451 cursor2 = LoadCursor(NULL, IDC_WAIT);
453 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
455 error = GetLastError();
456 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
459 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_bpp, int line)
463 BITMAP bmMask, bmColor;
465 ret = GetIconInfo(hIcon, &info);
466 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
468 /* CreateIcon under XP causes info.fIcon to be 0 */
469 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
470 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
471 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
473 ret = GetObject(info.hbmMask, sizeof(bmMask), &bmMask);
474 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
477 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
485 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
488 ret = GetObject(info.hbmColor, sizeof(bmColor), &bmColor);
489 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
491 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
492 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
493 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
494 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
495 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
497 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
498 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
499 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
503 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
504 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
505 ok_(__FILE__, line)(bmMask.bmHeight == exp_cy * 2, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
509 #define test_icon_info(a,b,c,d) test_icon_info_dbg((a),(b),(c),(d),__LINE__)
511 static void test_CreateIcon(void)
513 static const BYTE bmp_bits[1024];
515 HBITMAP hbmMask, hbmColor;
523 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
525 /* these crash under XP
526 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
527 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
530 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
531 ok(hIcon != 0, "CreateIcon failed\n");
532 test_icon_info(hIcon, 16, 16, 1);
535 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
536 ok(hIcon != 0, "CreateIcon failed\n");
537 test_icon_info(hIcon, 16, 16, display_bpp);
540 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
541 ok(hbmMask != 0, "CreateBitmap failed\n");
542 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
543 ok(hbmColor != 0, "CreateBitmap failed\n");
550 SetLastError(0xdeadbeaf);
551 hIcon = CreateIconIndirect(&info);
552 ok(!hIcon, "CreateIconIndirect should fail\n");
553 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
559 info.hbmColor = hbmColor;
560 SetLastError(0xdeadbeaf);
561 hIcon = CreateIconIndirect(&info);
562 ok(!hIcon, "CreateIconIndirect should fail\n");
563 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
568 info.hbmMask = hbmMask;
569 info.hbmColor = hbmColor;
570 hIcon = CreateIconIndirect(&info);
571 ok(hIcon != 0, "CreateIconIndirect failed\n");
572 test_icon_info(hIcon, 16, 16, display_bpp);
575 DeleteObject(hbmMask);
576 DeleteObject(hbmColor);
578 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
579 ok(hbmMask != 0, "CreateBitmap failed\n");
584 info.hbmMask = hbmMask;
586 SetLastError(0xdeadbeaf);
587 hIcon = CreateIconIndirect(&info);
588 ok(hIcon != 0, "CreateIconIndirect failed\n");
589 test_icon_info(hIcon, 16, 16, 1);
592 DeleteObject(hbmMask);
593 DeleteObject(hbmColor);
595 /* test creating an icon from a DIB section */
597 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
598 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
599 bmpinfo->bmiHeader.biWidth = 32;
600 bmpinfo->bmiHeader.biHeight = 32;
601 bmpinfo->bmiHeader.biPlanes = 1;
602 bmpinfo->bmiHeader.biBitCount = 8;
603 bmpinfo->bmiHeader.biCompression = BI_RGB;
604 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
605 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
607 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
608 bmpinfo->bmiHeader.biBitCount = 1;
609 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
610 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
612 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
617 info.hbmMask = hbmColor;
618 info.hbmColor = hbmMask;
619 SetLastError(0xdeadbeaf);
620 hIcon = CreateIconIndirect(&info);
621 ok(hIcon != 0, "CreateIconIndirect failed\n");
622 test_icon_info(hIcon, 32, 32, 8);
624 DeleteObject(hbmColor);
626 bmpinfo->bmiHeader.biBitCount = 16;
627 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
628 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
630 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
635 info.hbmMask = hbmColor;
636 info.hbmColor = hbmMask;
637 SetLastError(0xdeadbeaf);
638 hIcon = CreateIconIndirect(&info);
639 ok(hIcon != 0, "CreateIconIndirect failed\n");
640 test_icon_info(hIcon, 32, 32, 8);
642 DeleteObject(hbmColor);
644 bmpinfo->bmiHeader.biBitCount = 32;
645 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
646 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
648 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
653 info.hbmMask = hbmColor;
654 info.hbmColor = hbmMask;
655 SetLastError(0xdeadbeaf);
656 hIcon = CreateIconIndirect(&info);
657 ok(hIcon != 0, "CreateIconIndirect failed\n");
658 test_icon_info(hIcon, 32, 32, 8);
661 DeleteObject(hbmMask);
662 DeleteObject(hbmColor);
663 HeapFree( GetProcessHeap(), 0, bmpinfo );
668 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
670 static const unsigned char gifimage[35] = {
671 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
672 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
677 static const unsigned char jpgimage[285] = {
678 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
679 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
680 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
681 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
682 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
683 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
684 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
685 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
686 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
687 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
688 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
689 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
690 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
691 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
692 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
693 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
694 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
695 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
699 static const unsigned char pngimage[285] = {
700 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
701 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
702 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
703 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
704 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
705 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
706 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
709 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
710 zeroes, gap is 0xFF. */
711 static const unsigned char bmpimage[70] = {
712 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
713 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
714 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
715 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
716 0xFF,0xFF,0x00,0x00,0x00,0x00
720 static const unsigned char gif4pixel[42] = {
721 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
722 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
723 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
726 static void test_LoadImageBitmap(HBITMAP hbm)
730 DWORD ret, pixel = 0;
731 HDC hdc = GetDC(NULL);
733 ret = GetObject(hbm, sizeof(bm), &bm);
734 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
736 memset(&bmi, 0, sizeof(bmi));
737 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
738 bmi.bmiHeader.biWidth = bm.bmWidth;
739 bmi.bmiHeader.biHeight = bm.bmHeight;
740 bmi.bmiHeader.biPlanes = 1;
741 bmi.bmiHeader.biBitCount= 24;
742 bmi.bmiHeader.biCompression= BI_RGB;
743 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
744 ok(ret == bm.bmHeight, "%d lines were converted, not %d\n", ret, bm.bmHeight);
746 ok(color_match(pixel, 0x00ffffff), "Pixel is 0x%08x\n", pixel);
749 static void test_LoadImageFile(const unsigned char * image_data,
750 unsigned int image_size, const char * ext, BOOL expect_success)
754 DWORD error, bytes_written;
757 strcpy(filename, "test.");
758 strcat(filename, ext);
760 /* Create the test image. */
761 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
762 FILE_ATTRIBUTE_NORMAL, NULL);
763 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
764 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
765 ok(ret && bytes_written == image_size, "test file created improperly.\n");
768 /* Load as cursor. For all tested formats, this should fail */
769 SetLastError(0xdeadbeef);
770 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
771 ok(handle == NULL, "LoadImage(%s) as IMAGE_CURSOR succeeded incorrectly.\n", ext);
772 error = GetLastError();
774 broken(error == 0xdeadbeef) || /* Win9x */
775 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
776 "Last error: %u\n", error);
777 if (handle != NULL) DestroyCursor(handle);
779 /* Load as icon. For all tested formats, this should fail */
780 SetLastError(0xdeadbeef);
781 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
782 ok(handle == NULL, "LoadImage(%s) as IMAGE_ICON succeeded incorrectly.\n", ext);
783 error = GetLastError();
785 broken(error == 0xdeadbeef) || /* Win9x */
786 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
787 "Last error: %u\n", error);
788 if (handle != NULL) DestroyIcon(handle);
790 /* Load as bitmap. Should succeed if bmp, fail for everything else */
791 SetLastError(0xdeadbeef);
792 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
793 error = GetLastError();
795 error == 0xdeadbeef, /* Win9x, WinMe */
796 "Last error: %u\n", error);
798 if (expect_success) {
799 ok(handle != NULL, "LoadImage(%s) as IMAGE_BITMAP failed.\n", ext);
800 if (handle != NULL) test_LoadImageBitmap(handle);
802 else ok(handle == NULL, "LoadImage(%s) as IMAGE_BITMAP succeeded incorrectly.\n", ext);
804 if (handle != NULL) DeleteObject(handle);
805 DeleteFileA(filename);
808 static void test_LoadImage(void)
812 DWORD error, bytes_written;
813 CURSORICONFILEDIR *icon_data;
814 CURSORICONFILEDIRENTRY *icon_entry;
815 BITMAPINFOHEADER *icon_header;
818 #define ICON_WIDTH 32
819 #define ICON_HEIGHT 32
820 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
823 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
824 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
827 icon_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ICON_SIZE);
828 icon_data->idReserved = 0;
829 icon_data->idType = 1;
830 icon_data->idCount = 1;
832 icon_entry = icon_data->idEntries;
833 icon_entry->bWidth = ICON_WIDTH;
834 icon_entry->bHeight = ICON_HEIGHT;
835 icon_entry->bColorCount = 0;
836 icon_entry->bReserved = 0;
837 icon_entry->xHotspot = 1;
838 icon_entry->yHotspot = 1;
839 icon_entry->dwDIBSize = ICON_SIZE - sizeof(CURSORICONFILEDIR);
840 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
842 icon_header = (BITMAPINFOHEADER *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
843 icon_header->biSize = sizeof(BITMAPINFOHEADER);
844 icon_header->biWidth = ICON_WIDTH;
845 icon_header->biHeight = ICON_HEIGHT*2;
846 icon_header->biPlanes = 1;
847 icon_header->biBitCount = ICON_BPP;
848 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
850 /* Create the icon. */
851 handle = CreateFileA("icon.ico", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
852 FILE_ATTRIBUTE_NORMAL, NULL);
853 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
854 ret = WriteFile(handle, icon_data, ICON_SIZE, &bytes_written, NULL);
855 ok(ret && bytes_written == ICON_SIZE, "icon.ico created improperly.\n");
858 /* Test loading an icon as a cursor. */
859 SetLastError(0xdeadbeef);
860 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
861 ok(handle != NULL, "LoadImage() failed.\n");
862 error = GetLastError();
864 broken(error == 0xdeadbeef) || /* Win9x */
865 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
866 "Last error: %u\n", error);
868 /* Test the icon information. */
869 SetLastError(0xdeadbeef);
870 ret = GetIconInfo(handle, &icon_info);
871 ok(ret, "GetIconInfo() failed.\n");
872 error = GetLastError();
873 ok(error == 0xdeadbeef, "Last error: %u\n", error);
877 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
878 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
879 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
880 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
882 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
886 SetLastError(0xdeadbeef);
887 ret = DestroyCursor(handle);
888 ok(ret, "DestroyCursor() failed.\n");
889 error = GetLastError();
890 ok(error == 0xdeadbeef, "Last error: %u\n", error);
892 HeapFree(GetProcessHeap(), 0, icon_data);
893 DeleteFileA("icon.ico");
895 test_LoadImageFile(bmpimage, sizeof(bmpimage), "bmp", 1);
896 test_LoadImageFile(gifimage, sizeof(gifimage), "gif", 0);
897 test_LoadImageFile(gif4pixel, sizeof(gif4pixel), "gif", 0);
898 test_LoadImageFile(jpgimage, sizeof(jpgimage), "jpg", 0);
899 test_LoadImageFile(pngimage, sizeof(pngimage), "png", 0);
902 static void test_CreateIconFromResource(void)
907 BITMAPINFOHEADER *icon_header;
911 #define ICON_RES_WIDTH 32
912 #define ICON_RES_HEIGHT 32
913 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
914 #define ICON_RES_BPP 32
915 #define ICON_RES_SIZE \
916 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
917 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
920 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
922 /* Cursor resources have an extra hotspot, icon resources not. */
926 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
927 icon_header->biSize = sizeof(BITMAPINFOHEADER);
928 icon_header->biWidth = ICON_WIDTH;
929 icon_header->biHeight = ICON_HEIGHT*2;
930 icon_header->biPlanes = 1;
931 icon_header->biBitCount = ICON_BPP;
932 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
934 /* Test creating a cursor. */
935 SetLastError(0xdeadbeef);
936 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
937 ok(handle != NULL, "Create cursor failed.\n");
939 /* Test the icon information. */
940 SetLastError(0xdeadbeef);
941 ret = GetIconInfo(handle, &icon_info);
942 ok(ret, "GetIconInfo() failed.\n");
943 error = GetLastError();
944 ok(error == 0xdeadbeef, "Last error: %u\n", error);
948 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
949 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
950 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
951 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
953 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
957 SetLastError(0xdeadbeef);
958 ret = DestroyCursor(handle);
959 ok(ret, "DestroyCursor() failed.\n");
960 error = GetLastError();
961 ok(error == 0xdeadbeef, "Last error: %u\n", error);
963 /* Test creating an icon. */
964 SetLastError(0xdeadbeef);
965 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
967 ok(handle != NULL, "Create icon failed.\n");
969 /* Test the icon information. */
970 SetLastError(0xdeadbeef);
971 ret = GetIconInfo(handle, &icon_info);
972 ok(ret, "GetIconInfo() failed.\n");
973 error = GetLastError();
974 ok(error == 0xdeadbeef, "Last error: %u\n", error);
978 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
979 /* Icons always have hotspot in the middle */
980 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
981 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
982 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
983 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
987 SetLastError(0xdeadbeef);
988 ret = DestroyCursor(handle);
989 ok(ret, "DestroyCursor() failed.\n");
990 error = GetLastError();
991 ok(error == 0xdeadbeef, "Last error: %u\n", error);
993 HeapFree(GetProcessHeap(), 0, hotspot);
996 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
997 BOOL maskvalue, UINT32 *color, int colorSize)
1000 BITMAPINFO bitmapInfo;
1001 void *buffer = NULL;
1002 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1004 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1005 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1006 bitmapInfo.bmiHeader.biWidth = width;
1007 bitmapInfo.bmiHeader.biHeight = height;
1008 bitmapInfo.bmiHeader.biPlanes = 1;
1009 bitmapInfo.bmiHeader.biBitCount = bpp;
1010 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1011 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1013 iconInfo.fIcon = TRUE;
1014 iconInfo.xHotspot = 0;
1015 iconInfo.yHotspot = 0;
1017 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1018 if(!iconInfo.hbmMask) return NULL;
1020 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1021 if(!iconInfo.hbmColor || !buffer)
1023 DeleteObject(iconInfo.hbmMask);
1027 memcpy(buffer, color, colorSize);
1029 return CreateIconIndirect(&iconInfo);
1032 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1036 COLORREF modern_expected, legacy_expected, result;
1038 color[0] = 0x00A0B0C0;
1039 color[1] = alpha ? 0xFF000000 : 0x00000000;
1040 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1041 legacy_expected = 0x00C0B0A0;
1043 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1046 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1049 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1051 DrawIcon(hdc, 0, 0, hicon);
1053 result = GetPixel(hdc, 0, 0);
1054 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1055 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1056 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1057 "Got %06X from line %d\n",
1058 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1059 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1062 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1063 COLORREF modern_expected, COLORREF legacy_expected, int line)
1066 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1068 SetPixelV(hdc, 0, 0, background);
1069 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1070 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1071 DrawIcon(hdc, 0, 0, hicon);
1072 result = GetPixel(hdc, 0, 0);
1074 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1075 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1076 "Overlaying Mask %d on Color %06X with DrawIcon. "
1077 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1078 maskvalue, color, modern_expected, legacy_expected, result, line);
1080 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1082 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1083 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1084 "Overlaying Mask %d on Color %06X with DrawIcon. "
1085 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1086 maskvalue, color, modern_expected, legacy_expected, result, line);
1088 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1090 ok (color_match(result, background),
1091 "Overlaying Mask %d on Color %06X with DrawIcon. "
1092 "Expected unchanged background color %06X. Got %06X from line %d\n",
1093 maskvalue, color, background, result, line);
1096 static void test_DrawIcon(void)
1098 BITMAPINFO bitmapInfo;
1100 HBITMAP bmpDst = NULL;
1101 HBITMAP bmpOld = NULL;
1104 hdcDst = CreateCompatibleDC(0);
1105 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1109 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1111 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palletizing.\n");
1115 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1116 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1117 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1118 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1119 bitmapInfo.bmiHeader.biBitCount = 32;
1120 bitmapInfo.bmiHeader.biPlanes = 1;
1121 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1122 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1124 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1125 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1126 if (!bmpDst || !bits)
1128 bmpOld = SelectObject(hdcDst, bmpDst);
1130 /* Mask is only heeded if alpha channel is always zero */
1131 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1132 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1134 /* Test alpha blending */
1135 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1136 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1137 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1139 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1140 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1141 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1142 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1144 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1145 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1147 /* Test detecting of alpha channel */
1148 /* If a single pixel's alpha channel is non-zero, the icon
1149 will be alpha blended, otherwise it will be draw with
1151 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1152 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1156 SelectObject(hdcDst, bmpOld);
1158 DeleteObject(bmpDst);
1163 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1164 COLORREF modern_expected, COLORREF legacy_expected, int line)
1167 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1169 SetPixelV(hdc, 0, 0, background);
1170 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1171 result = GetPixel(hdc, 0, 0);
1173 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1174 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1175 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1176 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1177 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1180 static void test_DrawIconEx(void)
1182 BITMAPINFO bitmapInfo;
1184 HBITMAP bmpDst = NULL;
1185 HBITMAP bmpOld = NULL;
1188 hdcDst = CreateCompatibleDC(0);
1189 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1193 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1195 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1199 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1200 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1201 bitmapInfo.bmiHeader.biWidth = 1;
1202 bitmapInfo.bmiHeader.biHeight = 1;
1203 bitmapInfo.bmiHeader.biBitCount = 32;
1204 bitmapInfo.bmiHeader.biPlanes = 1;
1205 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1206 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1207 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1208 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1209 if (!bmpDst || !bits)
1211 bmpOld = SelectObject(hdcDst, bmpDst);
1213 /* Test null, image only, and mask only drawing */
1214 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1215 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1217 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00000000, 0x00000000, __LINE__);
1218 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1220 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1221 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1223 /* Test normal drawing */
1224 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1225 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1226 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1228 /* Test alpha blending */
1229 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1230 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1232 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1233 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1234 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1235 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1237 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1238 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1240 /* Test detecting of alpha channel */
1241 /* If a single pixel's alpha channel is non-zero, the icon
1242 will be alpha blended, otherwise it will be draw with
1244 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1245 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1249 SelectObject(hdcDst, bmpOld);
1251 DeleteObject(bmpDst);
1256 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1258 COLORREF result, background;
1260 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1261 background = 0x00FFFFFF;
1262 /* Set color of the 2 pixels that will be checked afterwards */
1263 SetPixelV(hdc, 0, 0, background);
1264 SetPixelV(hdc, 2, 2, background);
1266 /* Let DrawState calculate the size of the icon (it's 1x1) */
1267 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1269 result = GetPixel(hdc, 0, 0);
1270 passed[0] = color_match(result, background);
1271 result = GetPixel(hdc, 2, 2);
1272 passed[0] = passed[0] & color_match(result, background);
1274 /* Check if manually specifying the icon size DOESN'T work */
1276 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1277 * size in which it should be ultimately drawn. Therefore giving
1278 * width/height 2x2 if the icon is only 1x1 pixels in size should
1279 * result in drawing it with size 1x1. The size parameters must be
1280 * ignored if a Icon has to be drawn! */
1281 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1283 result = GetPixel(hdc, 0, 0);
1284 passed[1] = color_match(result, background);
1285 result = GetPixel(hdc, 2, 2);
1286 passed[1] = passed[0] & color_match(result, background);
1288 if(!passed[0]&&!passed[1])
1290 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
1291 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
1292 "Color %06X with flags %08X. Line %d\n",
1293 maskvalue, color, (DST_ICON | flags), line);
1296 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1297 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
1298 "Mask %d on Color %06X with flags %08X. Line %d\n",
1299 maskvalue, color, (DST_ICON | flags), line);
1302 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1303 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
1304 "Color %06X with flags %08X. Line %d\n",
1305 maskvalue, color, (DST_ICON | flags), line);
1308 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
1309 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
1312 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1314 /* Set color of the pixel that will be checked afterwards */
1315 SetPixelV(hdc, 1, 1, background);
1317 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
1319 /* Check the color of the pixel is correct */
1320 result = GetPixel(hdc, 1, 1);
1322 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1323 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1324 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
1325 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1326 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
1329 static void test_DrawState(void)
1331 BITMAPINFO bitmapInfo;
1333 HBITMAP bmpDst = NULL;
1334 HBITMAP bmpOld = NULL;
1337 hdcDst = CreateCompatibleDC(0);
1338 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1342 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1344 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1348 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1349 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1350 bitmapInfo.bmiHeader.biWidth = 3;
1351 bitmapInfo.bmiHeader.biHeight = 3;
1352 bitmapInfo.bmiHeader.biBitCount = 32;
1353 bitmapInfo.bmiHeader.biPlanes = 1;
1354 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1355 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1356 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1357 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1358 if (!bmpDst || !bits)
1360 bmpOld = SelectObject(hdcDst, bmpDst);
1362 /* potential flags to test with DrawState are: */
1363 /* DSS_DISABLED embosses the icon */
1364 /* DSS_MONO draw Icon using a brush as parameter 5 */
1365 /* DSS_NORMAL draw Icon without any modifications */
1366 /* DSS_UNION draw the Icon dithered */
1368 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
1369 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1373 SelectObject(hdcDst, bmpOld);
1375 DeleteObject(bmpDst);
1380 static DWORD parent_id;
1382 static DWORD CALLBACK set_cursor_thread( void *arg )
1386 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
1389 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
1390 ok( ret, "AttachThreadInput failed\n" );
1392 if (arg) ret = SetCursor( (HCURSOR)arg );
1393 else ret = GetCursor();
1394 return (DWORD_PTR)ret;
1397 static void test_SetCursor(void)
1399 static const BYTE bmp_bits[4096];
1400 ICONINFO cursorInfo;
1401 HCURSOR cursor, old_cursor, global_cursor = 0;
1402 DWORD error, id, result;
1410 memset( &info, 0, sizeof(info) );
1411 info.cbSize = sizeof(info);
1412 if (!pGetCursorInfo( &info ))
1414 win_skip( "GetCursorInfo not working\n" );
1415 pGetCursorInfo = NULL;
1417 else global_cursor = info.hCursor;
1419 cursor = GetCursor();
1420 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
1421 WaitForSingleObject( thread, 1000 );
1422 GetExitCodeThread( thread, &result );
1423 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
1426 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
1429 cursorInfo.fIcon = FALSE;
1430 cursorInfo.xHotspot = 0;
1431 cursorInfo.yHotspot = 0;
1432 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
1433 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
1435 cursor = CreateIconIndirect(&cursorInfo);
1436 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
1437 old_cursor = SetCursor( cursor );
1441 info.cbSize = sizeof(info);
1442 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1443 /* global cursor doesn't change since we don't have a window */
1444 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1445 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
1447 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
1448 WaitForSingleObject( thread, 1000 );
1449 GetExitCodeThread( thread, &result );
1450 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
1453 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
1454 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
1455 WaitForSingleObject( thread, 1000 );
1456 GetExitCodeThread( thread, &result );
1457 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
1459 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
1460 WaitForSingleObject( thread, 1000 );
1461 GetExitCodeThread( thread, &result );
1462 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
1463 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
1465 parent_id = GetCurrentThreadId();
1466 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
1467 WaitForSingleObject( thread, 1000 );
1468 GetExitCodeThread( thread, &result );
1469 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
1470 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
1474 info.cbSize = sizeof(info);
1475 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1476 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1477 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
1479 SetCursor( old_cursor );
1480 DestroyCursor( cursor );
1482 SetLastError( 0xdeadbeef );
1483 cursor = SetCursor( (HCURSOR)0xbadbad );
1484 error = GetLastError();
1485 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
1486 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
1487 "wrong error %u\n", error );
1491 info.cbSize = sizeof(info);
1492 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1493 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1494 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
1498 static HANDLE event_start, event_next;
1500 static DWORD CALLBACK show_cursor_thread( void *arg )
1502 DWORD count = (DWORD_PTR)arg;
1505 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
1508 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
1509 ok( ret, "AttachThreadInput failed\n" );
1511 if (!count) ret = ShowCursor( FALSE );
1512 else while (count--) ret = ShowCursor( TRUE );
1513 SetEvent( event_start );
1514 WaitForSingleObject( event_next, 2000 );
1518 static void test_ShowCursor(void)
1527 memset( &info, 0, sizeof(info) );
1528 info.cbSize = sizeof(info);
1529 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1530 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1533 event_start = CreateEvent( NULL, FALSE, FALSE, NULL );
1534 event_next = CreateEvent( NULL, FALSE, FALSE, NULL );
1536 count = ShowCursor( TRUE );
1537 ok( count == 1, "wrong count %d\n", count );
1538 count = ShowCursor( TRUE );
1539 ok( count == 2, "wrong count %d\n", count );
1540 count = ShowCursor( FALSE );
1541 ok( count == 1, "wrong count %d\n", count );
1542 count = ShowCursor( FALSE );
1543 ok( count == 0, "wrong count %d\n", count );
1544 count = ShowCursor( FALSE );
1545 ok( count == -1, "wrong count %d\n", count );
1546 count = ShowCursor( FALSE );
1547 ok( count == -2, "wrong count %d\n", count );
1551 info.cbSize = sizeof(info);
1552 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1553 /* global show count is not affected since we don't have a window */
1554 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1558 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
1559 WaitForSingleObject( event_start, 1000 );
1560 count = ShowCursor( FALSE );
1561 ok( count == -3, "wrong count %d\n", count );
1562 SetEvent( event_next );
1563 WaitForSingleObject( thread, 1000 );
1564 GetExitCodeThread( thread, &result );
1565 ok( result == -1, "wrong thread count %d\n", result );
1566 count = ShowCursor( FALSE );
1567 ok( count == -4, "wrong count %d\n", count );
1569 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
1570 WaitForSingleObject( event_start, 1000 );
1571 count = ShowCursor( TRUE );
1572 ok( count == -3, "wrong count %d\n", count );
1573 SetEvent( event_next );
1574 WaitForSingleObject( thread, 1000 );
1575 GetExitCodeThread( thread, &result );
1576 ok( result == 1, "wrong thread count %d\n", result );
1577 count = ShowCursor( TRUE );
1578 ok( count == -2, "wrong count %d\n", count );
1580 parent_id = GetCurrentThreadId();
1581 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
1582 WaitForSingleObject( event_start, 1000 );
1583 count = ShowCursor( TRUE );
1584 ok( count == -2, "wrong count %d\n", count );
1585 SetEvent( event_next );
1586 WaitForSingleObject( thread, 1000 );
1587 GetExitCodeThread( thread, &result );
1588 ok( result == -3, "wrong thread count %d\n", result );
1589 count = ShowCursor( FALSE );
1590 ok( count == -2, "wrong count %d\n", count );
1592 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
1593 WaitForSingleObject( event_start, 1000 );
1594 count = ShowCursor( TRUE );
1595 ok( count == 2, "wrong count %d\n", count );
1596 SetEvent( event_next );
1597 WaitForSingleObject( thread, 1000 );
1598 GetExitCodeThread( thread, &result );
1599 ok( result == 1, "wrong thread count %d\n", result );
1600 count = ShowCursor( FALSE );
1601 ok( count == -2, "wrong count %d\n", count );
1605 info.cbSize = sizeof(info);
1606 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1607 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1610 count = ShowCursor( TRUE );
1611 ok( count == -1, "wrong count %d\n", count );
1612 count = ShowCursor( TRUE );
1613 ok( count == 0, "wrong count %d\n", count );
1617 info.cbSize = sizeof(info);
1618 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1619 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1624 static void test_DestroyCursor(void)
1626 static const BYTE bmp_bits[4096];
1627 ICONINFO cursorInfo;
1628 HCURSOR cursor, cursor2;
1635 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
1638 cursorInfo.fIcon = FALSE;
1639 cursorInfo.xHotspot = 0;
1640 cursorInfo.yHotspot = 0;
1641 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
1642 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
1644 cursor = CreateIconIndirect(&cursorInfo);
1645 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
1651 SetLastError(0xdeadbeef);
1652 ret = DestroyCursor(cursor);
1653 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
1654 error = GetLastError();
1655 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1658 cursor2 = GetCursor();
1659 ok(cursor2 == cursor, "Active was set to %p when trying to destroy it\n", cursor2);
1662 /* Trying to destroy the cursor properly fails now with
1663 * ERROR_INVALID_CURSOR_HANDLE. This happens because we called
1664 * DestroyCursor() 2+ times after calling SetCursor(). The calls to
1665 * GetCursor() and SetCursor(NULL) in between make no difference. */
1666 SetLastError(0xdeadbeef);
1667 ret = DestroyCursor(cursor);
1668 todo_wine ok(!ret, "DestroyCursor succeeded.\n");
1669 error = GetLastError();
1670 ok(error == ERROR_INVALID_CURSOR_HANDLE || error == 0xdeadbeef, /* vista */
1671 "Last error: 0x%08x\n", error);
1674 DeleteObject(cursorInfo.hbmMask);
1675 DeleteObject(cursorInfo.hbmColor);
1677 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
1678 cursor = LoadCursor(NULL, IDC_ARROW);
1680 SetLastError(0xdeadbeef);
1681 ret = DestroyCursor(cursor);
1682 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
1683 error = GetLastError();
1684 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
1686 /* Try setting the cursor to a destroyed OEM cursor. */
1687 SetLastError(0xdeadbeef);
1689 error = GetLastError();
1690 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
1692 /* Check if LoadCursor() returns the same handle with the same icon. */
1693 cursor2 = LoadCursor(NULL, IDC_ARROW);
1694 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
1696 /* Check if LoadCursor() returns the same handle with a different icon. */
1697 cursor2 = LoadCursor(NULL, IDC_WAIT);
1698 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
1701 START_TEST(cursoricon)
1703 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
1704 test_argc = winetest_get_mainargs(&test_argv);
1708 /* Child process. */
1709 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
1711 ok(parent != NULL, "Parent not found.\n");
1719 test_CopyImage_Bitmap(1);
1720 test_CopyImage_Bitmap(4);
1721 test_CopyImage_Bitmap(8);
1722 test_CopyImage_Bitmap(16);
1723 test_CopyImage_Bitmap(24);
1724 test_CopyImage_Bitmap(32);
1725 test_initial_cursor();
1728 test_CreateIconFromResource();
1734 test_DestroyCursor();
1736 test_child_process();
1737 finish_child_process();