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 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 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 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 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 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(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 for correct 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);
900 /* Check failure for broken BMP images */
901 bmpimage[0x14]++; /* biHeight > 65535 */
902 test_LoadImageFile(bmpimage, sizeof(bmpimage), "bmp", 0);
904 bmpimage[0x18]++; /* biWidth > 65535 */
905 test_LoadImageFile(bmpimage, sizeof(bmpimage), "bmp", 0);
909 static void test_CreateIconFromResource(void)
914 BITMAPINFOHEADER *icon_header;
918 #define ICON_RES_WIDTH 32
919 #define ICON_RES_HEIGHT 32
920 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
921 #define ICON_RES_BPP 32
922 #define ICON_RES_SIZE \
923 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
924 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
927 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
929 /* Cursor resources have an extra hotspot, icon resources not. */
933 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
934 icon_header->biSize = sizeof(BITMAPINFOHEADER);
935 icon_header->biWidth = ICON_WIDTH;
936 icon_header->biHeight = ICON_HEIGHT*2;
937 icon_header->biPlanes = 1;
938 icon_header->biBitCount = ICON_BPP;
939 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
941 /* Test creating a cursor. */
942 SetLastError(0xdeadbeef);
943 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
944 ok(handle != NULL, "Create cursor failed.\n");
946 /* Test the icon information. */
947 SetLastError(0xdeadbeef);
948 ret = GetIconInfo(handle, &icon_info);
949 ok(ret, "GetIconInfo() failed.\n");
950 error = GetLastError();
951 ok(error == 0xdeadbeef, "Last error: %u\n", error);
955 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
956 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
957 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
958 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
960 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
964 SetLastError(0xdeadbeef);
965 ret = DestroyCursor(handle);
966 ok(ret, "DestroyCursor() failed.\n");
967 error = GetLastError();
968 ok(error == 0xdeadbeef, "Last error: %u\n", error);
970 /* Test creating an icon. */
971 SetLastError(0xdeadbeef);
972 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
974 ok(handle != NULL, "Create icon failed.\n");
976 /* Test the icon information. */
977 SetLastError(0xdeadbeef);
978 ret = GetIconInfo(handle, &icon_info);
979 ok(ret, "GetIconInfo() failed.\n");
980 error = GetLastError();
981 ok(error == 0xdeadbeef, "Last error: %u\n", error);
985 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
986 /* Icons always have hotspot in the middle */
987 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
988 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
989 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
990 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
994 SetLastError(0xdeadbeef);
995 ret = DestroyCursor(handle);
996 ok(ret, "DestroyCursor() failed.\n");
997 error = GetLastError();
998 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1000 HeapFree(GetProcessHeap(), 0, hotspot);
1003 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1004 BOOL maskvalue, UINT32 *color, int colorSize)
1007 BITMAPINFO bitmapInfo;
1008 void *buffer = NULL;
1009 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1011 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1012 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1013 bitmapInfo.bmiHeader.biWidth = width;
1014 bitmapInfo.bmiHeader.biHeight = height;
1015 bitmapInfo.bmiHeader.biPlanes = 1;
1016 bitmapInfo.bmiHeader.biBitCount = bpp;
1017 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1018 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1020 iconInfo.fIcon = TRUE;
1021 iconInfo.xHotspot = 0;
1022 iconInfo.yHotspot = 0;
1024 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1025 if(!iconInfo.hbmMask) return NULL;
1027 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1028 if(!iconInfo.hbmColor || !buffer)
1030 DeleteObject(iconInfo.hbmMask);
1034 memcpy(buffer, color, colorSize);
1036 return CreateIconIndirect(&iconInfo);
1039 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1043 COLORREF modern_expected, legacy_expected, result;
1045 color[0] = 0x00A0B0C0;
1046 color[1] = alpha ? 0xFF000000 : 0x00000000;
1047 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1048 legacy_expected = 0x00C0B0A0;
1050 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1053 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1056 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1058 DrawIcon(hdc, 0, 0, hicon);
1060 result = GetPixel(hdc, 0, 0);
1061 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1062 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1063 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1064 "Got %06X from line %d\n",
1065 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1066 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1069 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1070 COLORREF modern_expected, COLORREF legacy_expected, int line)
1073 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1075 SetPixelV(hdc, 0, 0, background);
1076 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1077 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1078 DrawIcon(hdc, 0, 0, hicon);
1079 result = GetPixel(hdc, 0, 0);
1081 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1082 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1083 "Overlaying Mask %d on Color %06X with DrawIcon. "
1084 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1085 maskvalue, color, modern_expected, legacy_expected, result, line);
1087 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1089 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1090 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1091 "Overlaying Mask %d on Color %06X with DrawIcon. "
1092 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1093 maskvalue, color, modern_expected, legacy_expected, result, line);
1095 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1097 ok (color_match(result, background),
1098 "Overlaying Mask %d on Color %06X with DrawIcon. "
1099 "Expected unchanged background color %06X. Got %06X from line %d\n",
1100 maskvalue, color, background, result, line);
1103 static void test_DrawIcon(void)
1105 BITMAPINFO bitmapInfo;
1107 HBITMAP bmpDst = NULL;
1108 HBITMAP bmpOld = NULL;
1111 hdcDst = CreateCompatibleDC(0);
1112 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1116 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1118 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palletizing.\n");
1122 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1123 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1124 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1125 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1126 bitmapInfo.bmiHeader.biBitCount = 32;
1127 bitmapInfo.bmiHeader.biPlanes = 1;
1128 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1129 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1131 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1132 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1133 if (!bmpDst || !bits)
1135 bmpOld = SelectObject(hdcDst, bmpDst);
1137 /* Mask is only heeded if alpha channel is always zero */
1138 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1139 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1141 /* Test alpha blending */
1142 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1143 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1144 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1146 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1147 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1148 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1149 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1151 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1152 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1154 /* Test detecting of alpha channel */
1155 /* If a single pixel's alpha channel is non-zero, the icon
1156 will be alpha blended, otherwise it will be draw with
1158 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1159 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1163 SelectObject(hdcDst, bmpOld);
1165 DeleteObject(bmpDst);
1170 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1171 COLORREF modern_expected, COLORREF legacy_expected, int line)
1174 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1176 SetPixelV(hdc, 0, 0, background);
1177 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1178 result = GetPixel(hdc, 0, 0);
1180 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1181 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1182 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1183 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1184 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1187 static void test_DrawIconEx(void)
1189 BITMAPINFO bitmapInfo;
1191 HBITMAP bmpDst = NULL;
1192 HBITMAP bmpOld = NULL;
1195 hdcDst = CreateCompatibleDC(0);
1196 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1200 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1202 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1206 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1207 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1208 bitmapInfo.bmiHeader.biWidth = 1;
1209 bitmapInfo.bmiHeader.biHeight = 1;
1210 bitmapInfo.bmiHeader.biBitCount = 32;
1211 bitmapInfo.bmiHeader.biPlanes = 1;
1212 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1213 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1214 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1215 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1216 if (!bmpDst || !bits)
1218 bmpOld = SelectObject(hdcDst, bmpDst);
1220 /* Test null, image only, and mask only drawing */
1221 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1222 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1224 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00000000, 0x00000000, __LINE__);
1225 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1227 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1228 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1230 /* Test normal drawing */
1231 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1232 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1233 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1235 /* Test alpha blending */
1236 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1237 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1239 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1240 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1241 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1242 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1244 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1245 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1247 /* Test detecting of alpha channel */
1248 /* If a single pixel's alpha channel is non-zero, the icon
1249 will be alpha blended, otherwise it will be draw with
1251 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1252 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1256 SelectObject(hdcDst, bmpOld);
1258 DeleteObject(bmpDst);
1263 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1265 COLORREF result, background;
1267 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1268 background = 0x00FFFFFF;
1269 /* Set color of the 2 pixels that will be checked afterwards */
1270 SetPixelV(hdc, 0, 0, background);
1271 SetPixelV(hdc, 2, 2, background);
1273 /* Let DrawState calculate the size of the icon (it's 1x1) */
1274 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
1276 result = GetPixel(hdc, 0, 0);
1277 passed[0] = color_match(result, background);
1278 result = GetPixel(hdc, 2, 2);
1279 passed[0] = passed[0] & color_match(result, background);
1281 /* Check if manually specifying the icon size DOESN'T work */
1283 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
1284 * size in which it should be ultimately drawn. Therefore giving
1285 * width/height 2x2 if the icon is only 1x1 pixels in size should
1286 * result in drawing it with size 1x1. The size parameters must be
1287 * ignored if a Icon has to be drawn! */
1288 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
1290 result = GetPixel(hdc, 0, 0);
1291 passed[1] = color_match(result, background);
1292 result = GetPixel(hdc, 2, 2);
1293 passed[1] = passed[0] & color_match(result, background);
1295 if(!passed[0]&&!passed[1])
1297 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
1298 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
1299 "Color %06X with flags %08X. Line %d\n",
1300 maskvalue, color, (DST_ICON | flags), line);
1303 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1304 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
1305 "Mask %d on Color %06X with flags %08X. Line %d\n",
1306 maskvalue, color, (DST_ICON | flags), line);
1309 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
1310 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
1311 "Color %06X with flags %08X. Line %d\n",
1312 maskvalue, color, (DST_ICON | flags), line);
1315 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
1316 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
1319 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1321 /* Set color of the pixel that will be checked afterwards */
1322 SetPixelV(hdc, 1, 1, background);
1324 DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
1326 /* Check the color of the pixel is correct */
1327 result = GetPixel(hdc, 1, 1);
1329 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1330 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1331 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
1332 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1333 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
1336 static void test_DrawState(void)
1338 BITMAPINFO bitmapInfo;
1340 HBITMAP bmpDst = NULL;
1341 HBITMAP bmpOld = NULL;
1344 hdcDst = CreateCompatibleDC(0);
1345 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1349 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1351 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
1355 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1356 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1357 bitmapInfo.bmiHeader.biWidth = 3;
1358 bitmapInfo.bmiHeader.biHeight = 3;
1359 bitmapInfo.bmiHeader.biBitCount = 32;
1360 bitmapInfo.bmiHeader.biPlanes = 1;
1361 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1362 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1363 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1364 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1365 if (!bmpDst || !bits)
1367 bmpOld = SelectObject(hdcDst, bmpDst);
1369 /* potential flags to test with DrawState are: */
1370 /* DSS_DISABLED embosses the icon */
1371 /* DSS_MONO draw Icon using a brush as parameter 5 */
1372 /* DSS_NORMAL draw Icon without any modifications */
1373 /* DSS_UNION draw the Icon dithered */
1375 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
1376 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1380 SelectObject(hdcDst, bmpOld);
1382 DeleteObject(bmpDst);
1387 static DWORD parent_id;
1389 static DWORD CALLBACK set_cursor_thread( void *arg )
1393 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
1396 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
1397 ok( ret, "AttachThreadInput failed\n" );
1399 if (arg) ret = SetCursor( (HCURSOR)arg );
1400 else ret = GetCursor();
1401 return (DWORD_PTR)ret;
1404 static void test_SetCursor(void)
1406 static const BYTE bmp_bits[4096];
1407 ICONINFO cursorInfo;
1408 HCURSOR cursor, old_cursor, global_cursor = 0;
1409 DWORD error, id, result;
1417 memset( &info, 0, sizeof(info) );
1418 info.cbSize = sizeof(info);
1419 if (!pGetCursorInfo( &info ))
1421 win_skip( "GetCursorInfo not working\n" );
1422 pGetCursorInfo = NULL;
1424 else global_cursor = info.hCursor;
1426 cursor = GetCursor();
1427 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
1428 WaitForSingleObject( thread, 1000 );
1429 GetExitCodeThread( thread, &result );
1430 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
1433 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
1436 cursorInfo.fIcon = FALSE;
1437 cursorInfo.xHotspot = 0;
1438 cursorInfo.yHotspot = 0;
1439 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
1440 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
1442 cursor = CreateIconIndirect(&cursorInfo);
1443 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
1444 old_cursor = SetCursor( cursor );
1448 info.cbSize = sizeof(info);
1449 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1450 /* global cursor doesn't change since we don't have a window */
1451 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1452 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
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 );
1460 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
1461 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
1462 WaitForSingleObject( thread, 1000 );
1463 GetExitCodeThread( thread, &result );
1464 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
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() == 0, "wrong cursor %p/0\n", GetCursor() );
1472 parent_id = GetCurrentThreadId();
1473 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
1474 WaitForSingleObject( thread, 1000 );
1475 GetExitCodeThread( thread, &result );
1476 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
1477 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
1481 info.cbSize = sizeof(info);
1482 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1483 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1484 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
1486 SetCursor( old_cursor );
1487 DestroyCursor( cursor );
1489 SetLastError( 0xdeadbeef );
1490 cursor = SetCursor( (HCURSOR)0xbadbad );
1491 error = GetLastError();
1492 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
1493 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
1494 "wrong error %u\n", error );
1498 info.cbSize = sizeof(info);
1499 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1500 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
1501 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
1505 static HANDLE event_start, event_next;
1507 static DWORD CALLBACK show_cursor_thread( void *arg )
1509 DWORD count = (DWORD_PTR)arg;
1512 PeekMessage( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
1515 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
1516 ok( ret, "AttachThreadInput failed\n" );
1518 if (!count) ret = ShowCursor( FALSE );
1519 else while (count--) ret = ShowCursor( TRUE );
1520 SetEvent( event_start );
1521 WaitForSingleObject( event_next, 2000 );
1525 static void test_ShowCursor(void)
1534 memset( &info, 0, sizeof(info) );
1535 info.cbSize = sizeof(info);
1536 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1537 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1540 event_start = CreateEvent( NULL, FALSE, FALSE, NULL );
1541 event_next = CreateEvent( NULL, FALSE, FALSE, NULL );
1543 count = ShowCursor( TRUE );
1544 ok( count == 1, "wrong count %d\n", count );
1545 count = ShowCursor( TRUE );
1546 ok( count == 2, "wrong count %d\n", count );
1547 count = ShowCursor( FALSE );
1548 ok( count == 1, "wrong count %d\n", count );
1549 count = ShowCursor( FALSE );
1550 ok( count == 0, "wrong count %d\n", count );
1551 count = ShowCursor( FALSE );
1552 ok( count == -1, "wrong count %d\n", count );
1553 count = ShowCursor( FALSE );
1554 ok( count == -2, "wrong count %d\n", count );
1558 info.cbSize = sizeof(info);
1559 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1560 /* global show count is not affected since we don't have a window */
1561 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1565 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
1566 WaitForSingleObject( event_start, 1000 );
1567 count = ShowCursor( FALSE );
1568 ok( count == -3, "wrong count %d\n", count );
1569 SetEvent( event_next );
1570 WaitForSingleObject( thread, 1000 );
1571 GetExitCodeThread( thread, &result );
1572 ok( result == -1, "wrong thread count %d\n", result );
1573 count = ShowCursor( FALSE );
1574 ok( count == -4, "wrong count %d\n", count );
1576 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
1577 WaitForSingleObject( event_start, 1000 );
1578 count = ShowCursor( TRUE );
1579 ok( count == -3, "wrong count %d\n", count );
1580 SetEvent( event_next );
1581 WaitForSingleObject( thread, 1000 );
1582 GetExitCodeThread( thread, &result );
1583 ok( result == 1, "wrong thread count %d\n", result );
1584 count = ShowCursor( TRUE );
1585 ok( count == -2, "wrong count %d\n", count );
1587 parent_id = GetCurrentThreadId();
1588 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
1589 WaitForSingleObject( event_start, 1000 );
1590 count = ShowCursor( TRUE );
1591 ok( count == -2, "wrong count %d\n", count );
1592 SetEvent( event_next );
1593 WaitForSingleObject( thread, 1000 );
1594 GetExitCodeThread( thread, &result );
1595 ok( result == -3, "wrong thread count %d\n", result );
1596 count = ShowCursor( FALSE );
1597 ok( count == -2, "wrong count %d\n", count );
1599 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
1600 WaitForSingleObject( event_start, 1000 );
1601 count = ShowCursor( TRUE );
1602 ok( count == 2, "wrong count %d\n", count );
1603 SetEvent( event_next );
1604 WaitForSingleObject( thread, 1000 );
1605 GetExitCodeThread( thread, &result );
1606 ok( result == 1, "wrong thread count %d\n", result );
1607 count = ShowCursor( FALSE );
1608 ok( count == -2, "wrong count %d\n", count );
1612 info.cbSize = sizeof(info);
1613 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1614 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1617 count = ShowCursor( TRUE );
1618 ok( count == -1, "wrong count %d\n", count );
1619 count = ShowCursor( TRUE );
1620 ok( count == 0, "wrong count %d\n", count );
1624 info.cbSize = sizeof(info);
1625 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
1626 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
1631 static void test_DestroyCursor(void)
1633 static const BYTE bmp_bits[4096];
1634 ICONINFO cursorInfo;
1635 HCURSOR cursor, cursor2;
1642 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
1645 cursorInfo.fIcon = FALSE;
1646 cursorInfo.xHotspot = 0;
1647 cursorInfo.yHotspot = 0;
1648 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
1649 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
1651 cursor = CreateIconIndirect(&cursorInfo);
1652 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
1658 SetLastError(0xdeadbeef);
1659 ret = DestroyCursor(cursor);
1660 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
1661 error = GetLastError();
1662 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1665 cursor2 = GetCursor();
1666 ok(cursor2 == cursor, "Active was set to %p when trying to destroy it\n", cursor2);
1669 /* Trying to destroy the cursor properly fails now with
1670 * ERROR_INVALID_CURSOR_HANDLE. This happens because we called
1671 * DestroyCursor() 2+ times after calling SetCursor(). The calls to
1672 * GetCursor() and SetCursor(NULL) in between make no difference. */
1673 SetLastError(0xdeadbeef);
1674 ret = DestroyCursor(cursor);
1675 todo_wine ok(!ret, "DestroyCursor succeeded.\n");
1676 error = GetLastError();
1677 ok(error == ERROR_INVALID_CURSOR_HANDLE || error == 0xdeadbeef, /* vista */
1678 "Last error: 0x%08x\n", error);
1681 DeleteObject(cursorInfo.hbmMask);
1682 DeleteObject(cursorInfo.hbmColor);
1684 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
1685 cursor = LoadCursor(NULL, IDC_ARROW);
1687 SetLastError(0xdeadbeef);
1688 ret = DestroyCursor(cursor);
1689 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
1690 error = GetLastError();
1691 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
1693 /* Try setting the cursor to a destroyed OEM cursor. */
1694 SetLastError(0xdeadbeef);
1696 error = GetLastError();
1697 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
1699 /* Check if LoadCursor() returns the same handle with the same icon. */
1700 cursor2 = LoadCursor(NULL, IDC_ARROW);
1701 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
1703 /* Check if LoadCursor() returns the same handle with a different icon. */
1704 cursor2 = LoadCursor(NULL, IDC_WAIT);
1705 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
1708 START_TEST(cursoricon)
1710 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
1711 test_argc = winetest_get_mainargs(&test_argv);
1715 /* Child process. */
1716 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
1718 ok(parent != NULL, "Parent not found.\n");
1726 test_CopyImage_Bitmap(1);
1727 test_CopyImage_Bitmap(4);
1728 test_CopyImage_Bitmap(8);
1729 test_CopyImage_Bitmap(16);
1730 test_CopyImage_Bitmap(24);
1731 test_CopyImage_Bitmap(32);
1732 test_initial_cursor();
1735 test_CreateIconFromResource();
1741 test_DestroyCursor();
1743 test_child_process();
1744 finish_child_process();