user32: Check the DpiScalingVer registry key to enable DPI scaling.
[wine.git] / dlls / user32 / tests / cursoricon.c
blob95a6878e9a0e457f40da6cdca61a485320110e47
1 /*
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
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "wine/test.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "wingdi.h"
32 #include "winuser.h"
34 #include "pshpack1.h"
36 typedef struct
38 BYTE bWidth;
39 BYTE bHeight;
40 BYTE bColorCount;
41 BYTE bReserved;
42 WORD xHotspot;
43 WORD yHotspot;
44 DWORD dwDIBSize;
45 DWORD dwDIBOffset;
46 } CURSORICONFILEDIRENTRY;
48 typedef struct
50 WORD idReserved;
51 WORD idType;
52 WORD idCount;
53 CURSORICONFILEDIRENTRY idEntries[1];
54 } CURSORICONFILEDIR;
56 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
57 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
58 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
60 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
61 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
62 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
63 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
64 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
65 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
66 #define ANI_icon_ID RIFF_FOURCC('i', 'c', 'o', 'n')
67 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
69 #define ANI_FLAG_ICON 0x1
70 #define ANI_FLAG_SEQUENCE 0x2
72 typedef struct {
73 DWORD header_size;
74 DWORD num_frames;
75 DWORD num_steps;
76 DWORD width;
77 DWORD height;
78 DWORD bpp;
79 DWORD num_planes;
80 DWORD display_rate;
81 DWORD flags;
82 } ani_header;
84 typedef struct {
85 BYTE data[32*32*4];
86 BYTE mask_data[32*32/8];
87 } ani_data32x32x32;
89 typedef struct {
90 CURSORICONFILEDIR icon_info; /* animated cursor frame information */
91 BITMAPINFOHEADER bmi_header; /* animated cursor frame header */
92 ani_data32x32x32 bmi_data; /* animated cursor frame DIB data */
93 } ani_frame32x32x32;
95 typedef struct {
96 DWORD chunk_id; /* ANI_anih_ID */
97 DWORD chunk_size; /* actual size of data */
98 ani_header header; /* animated cursor header */
99 } riff_header_t;
101 typedef struct {
102 DWORD chunk_id; /* ANI_LIST_ID */
103 DWORD chunk_size; /* actual size of data */
104 DWORD chunk_type; /* ANI_fram_ID */
105 } riff_list_t;
107 typedef struct {
108 DWORD chunk_id; /* ANI_icon_ID */
109 DWORD chunk_size; /* actual size of data */
110 ani_frame32x32x32 data; /* animated cursor frame */
111 } riff_icon32x32x32_t;
113 typedef struct {
114 DWORD chunk_id; /* ANI_RIFF_ID */
115 DWORD chunk_size; /* actual size of data */
116 DWORD chunk_type; /* ANI_ACON_ID */
117 riff_header_t header; /* RIFF animated cursor header */
118 riff_list_t frame_list; /* RIFF animated cursor frame list info */
119 riff_icon32x32x32_t frames[1]; /* array of animated cursor frames */
120 } riff_cursor1_t;
122 typedef struct {
123 DWORD chunk_id; /* ANI_RIFF_ID */
124 DWORD chunk_size; /* actual size of data */
125 DWORD chunk_type; /* ANI_ACON_ID */
126 riff_header_t header; /* RIFF animated cursor header */
127 riff_list_t frame_list; /* RIFF animated cursor frame list info */
128 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
129 } riff_cursor3_t;
131 typedef struct {
132 DWORD chunk_id; /* ANI_rate_ID */
133 DWORD chunk_size; /* actual size of data */
134 DWORD rate[3]; /* animated cursor rate data */
135 } riff_rate3_t;
137 typedef struct {
138 DWORD chunk_id; /* ANI_seq__ID */
139 DWORD chunk_size; /* actual size of data */
140 DWORD order[3]; /* animated cursor sequence data */
141 } riff_seq3_t;
143 typedef struct {
144 DWORD chunk_id; /* ANI_RIFF_ID */
145 DWORD chunk_size; /* actual size of data */
146 DWORD chunk_type; /* ANI_ACON_ID */
147 riff_header_t header; /* RIFF animated cursor header */
148 riff_seq3_t seq; /* sequence data for three cursor frames */
149 riff_rate3_t rates; /* rate data for three cursor frames */
150 riff_list_t frame_list; /* RIFF animated cursor frame list info */
151 riff_icon32x32x32_t frames[3]; /* array of three animated cursor frames */
152 } riff_cursor3_seq_t;
154 #define EMPTY_ICON32 \
156 ANI_icon_ID, \
157 sizeof(ani_frame32x32x32), \
160 0x0, /* reserved */ \
161 0, /* type: icon(1), cursor(2) */ \
162 1, /* count */ \
165 32, /* width */ \
166 32, /* height */ \
167 0, /* color count */ \
168 0x0, /* reserved */ \
169 16, /* x hotspot */ \
170 16, /* y hotspot */ \
171 sizeof(ani_data32x32x32), /* DIB size */ \
172 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
175 }, \
177 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
178 32, /* width */ \
179 32*2, /* actual height times two */ \
180 1, /* planes */ \
181 32, /* bpp */ \
182 BI_RGB, /* compression */ \
183 0, /* image size */ \
184 0, /* biXPelsPerMeter */ \
185 0, /* biYPelsPerMeter */ \
186 0, /* biClrUsed */ \
187 0 /* biClrImportant */ \
189 /* DIB data: left uninitialized */ \
193 riff_cursor1_t empty_anicursor = {
194 ANI_RIFF_ID,
195 sizeof(empty_anicursor) - sizeof(DWORD)*2,
196 ANI_ACON_ID,
198 ANI_anih_ID,
199 sizeof(ani_header),
201 sizeof(ani_header),
202 1, /* frames */
203 1, /* steps */
204 32, /* width */
205 32, /* height */
206 32, /* depth */
207 1, /* planes */
208 10, /* display rate in jiffies */
209 ANI_FLAG_ICON /* flags */
213 ANI_LIST_ID,
214 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
215 ANI_fram_ID,
218 EMPTY_ICON32
222 riff_cursor3_t empty_anicursor3 = {
223 ANI_RIFF_ID,
224 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
225 ANI_ACON_ID,
227 ANI_anih_ID,
228 sizeof(ani_header),
230 sizeof(ani_header),
231 3, /* frames */
232 3, /* steps */
233 32, /* width */
234 32, /* height */
235 32, /* depth */
236 1, /* planes */
237 0xbeef, /* display rate in jiffies */
238 ANI_FLAG_ICON /* flags */
242 ANI_LIST_ID,
243 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
244 ANI_fram_ID,
247 EMPTY_ICON32,
248 EMPTY_ICON32,
249 EMPTY_ICON32
253 riff_cursor3_seq_t empty_anicursor3_seq = {
254 ANI_RIFF_ID,
255 sizeof(empty_anicursor3_seq) - sizeof(DWORD)*2,
256 ANI_ACON_ID,
258 ANI_anih_ID,
259 sizeof(ani_header),
261 sizeof(ani_header),
262 3, /* frames */
263 3, /* steps */
264 32, /* width */
265 32, /* height */
266 32, /* depth */
267 1, /* planes */
268 0xbeef, /* display rate in jiffies */
269 ANI_FLAG_ICON|ANI_FLAG_SEQUENCE /* flags */
273 ANI_seq__ID,
274 sizeof(riff_seq3_t) - sizeof(DWORD)*2,
275 { 2, 0, 1} /* show frames in a uniquely identifiable order */
278 ANI_rate_ID,
279 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
280 { 0xc0de, 0xcafe, 0xbabe}
283 ANI_LIST_ID,
284 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
285 ANI_fram_ID,
288 EMPTY_ICON32,
289 EMPTY_ICON32,
290 EMPTY_ICON32
294 #include "poppack.h"
296 static char **test_argv;
297 static int test_argc;
298 static HWND child = 0;
299 static HWND parent = 0;
300 static HANDLE child_process;
302 #define PROC_INIT (WM_USER+1)
304 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
305 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
306 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
308 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
310 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
312 switch (msg)
314 /* Destroy the cursor. */
315 case WM_USER+1:
317 HCURSOR cursor = (HCURSOR)lParam;
318 ICONINFO info;
319 BOOL ret;
320 DWORD error;
322 memset(&info, 0, sizeof(info));
323 ret = GetIconInfo(cursor, &info);
324 todo_wine ok(ret, "GetIconInfoEx failed with error %u\n", GetLastError());
325 todo_wine ok(info.hbmColor != NULL, "info.hmbColor was not set\n");
326 todo_wine ok(info.hbmMask != NULL, "info.hmbColor was not set\n");
327 DeleteObject(info.hbmColor);
328 DeleteObject(info.hbmMask);
330 SetLastError(0xdeadbeef);
331 ret = DestroyCursor(cursor);
332 error = GetLastError();
333 ok(!ret || broken(ret) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
334 ok(error == ERROR_DESTROY_OBJECT_OF_OTHER_THREAD ||
335 error == 0xdeadbeef, /* vista */
336 "Last error: %u\n", error);
337 return TRUE;
339 case WM_DESTROY:
340 PostQuitMessage(0);
341 return 0;
344 return DefWindowProcA(hwnd, msg, wParam, lParam);
347 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
349 if (msg == PROC_INIT)
351 child = (HWND) wParam;
352 return TRUE;
355 return DefWindowProcA(hwnd, msg, wParam, lParam);
358 static void do_child(void)
360 WNDCLASSA class;
361 MSG msg;
362 BOOL ret;
364 /* Register a new class. */
365 class.style = CS_GLOBALCLASS;
366 class.lpfnWndProc = callback_child;
367 class.cbClsExtra = 0;
368 class.cbWndExtra = 0;
369 class.hInstance = GetModuleHandleA(NULL);
370 class.hIcon = NULL;
371 class.hCursor = NULL;
372 class.hbrBackground = NULL;
373 class.lpszMenuName = NULL;
374 class.lpszClassName = "cursor_child";
376 SetLastError(0xdeadbeef);
377 ret = RegisterClassA(&class);
378 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
380 /* Create a window. */
381 child = CreateWindowA("cursor_child", "cursor_child", WS_POPUP | WS_VISIBLE,
382 0, 0, 200, 200, 0, 0, 0, NULL);
383 ok(child != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
385 /* Let the parent know our HWND. */
386 PostMessageA(parent, PROC_INIT, (WPARAM) child, 0);
388 /* Receive messages. */
389 while ((ret = GetMessageA(&msg, 0, 0, 0)))
391 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
392 TranslateMessage(&msg);
393 DispatchMessageA(&msg);
397 static void do_parent(void)
399 char path_name[MAX_PATH];
400 PROCESS_INFORMATION info;
401 STARTUPINFOA startup;
402 WNDCLASSA class;
403 MSG msg;
404 BOOL ret;
406 /* Register a new class. */
407 class.style = CS_GLOBALCLASS;
408 class.lpfnWndProc = callback_parent;
409 class.cbClsExtra = 0;
410 class.cbWndExtra = 0;
411 class.hInstance = GetModuleHandleA(NULL);
412 class.hIcon = NULL;
413 class.hCursor = NULL;
414 class.hbrBackground = NULL;
415 class.lpszMenuName = NULL;
416 class.lpszClassName = "cursor_parent";
418 SetLastError(0xdeadbeef);
419 ret = RegisterClassA(&class);
420 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
422 /* Create a window. */
423 parent = CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP | WS_VISIBLE,
424 0, 0, 200, 200, 0, 0, 0, NULL);
425 ok(parent != 0, "CreateWindowA failed. Error: %u\n", GetLastError());
427 /* Start child process. */
428 memset(&startup, 0, sizeof(startup));
429 startup.cb = sizeof(startup);
430 startup.dwFlags = STARTF_USESHOWWINDOW;
431 startup.wShowWindow = SW_SHOWNORMAL;
433 sprintf(path_name, "%s cursoricon %lx", test_argv[0], (INT_PTR)parent);
434 ok(CreateProcessA(NULL, path_name, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed.\n");
435 child_process = info.hProcess;
437 /* Wait for child window handle. */
438 while ((child == 0) && (ret = GetMessageA(&msg, parent, 0, 0)))
440 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
441 TranslateMessage(&msg);
442 DispatchMessageA(&msg);
446 static void finish_child_process(void)
448 SendMessageA(child, WM_CLOSE, 0, 0);
449 winetest_wait_child_process( child_process );
450 CloseHandle(child_process);
453 static void test_child_process(void)
455 static const BYTE bmp_bits[4096];
456 HCURSOR cursor;
457 ICONINFO cursorInfo;
458 UINT display_bpp;
459 HDC hdc;
461 /* Create and set a dummy cursor. */
462 hdc = GetDC(0);
463 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
464 ReleaseDC(0, hdc);
466 cursorInfo.fIcon = FALSE;
467 cursorInfo.xHotspot = 0;
468 cursorInfo.yHotspot = 0;
469 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
470 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
472 cursor = CreateIconIndirect(&cursorInfo);
473 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
475 SetCursor(cursor);
477 /* Destroy the cursor. */
478 SendMessageA(child, WM_USER+1, 0, (LPARAM) cursor);
481 static BOOL color_match(COLORREF a, COLORREF b)
483 /* 5-bit accuracy is a sufficient test. This will match as long as
484 * colors are never truncated to less that 3x5-bit accuracy i.e.
485 * palettized. */
486 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
489 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
490 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
492 HBITMAP copy;
493 BITMAP origBitmap;
494 BITMAP copyBitmap;
495 BOOL orig_is_dib;
496 BOOL copy_is_dib;
498 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
499 ok(copy != NULL, "CopyImage() failed\n");
500 if (copy != NULL)
502 GetObjectA(bitmap, sizeof(origBitmap), &origBitmap);
503 GetObjectA(copy, sizeof(copyBitmap), &copyBitmap);
504 orig_is_dib = (origBitmap.bmBits != NULL);
505 copy_is_dib = (copyBitmap.bmBits != NULL);
507 if (copy_is_dib && dibExpected
508 && copyBitmap.bmBitsPixel == 24
509 && (expectedDepth == 16 || expectedDepth == 32))
511 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
512 if (GetVersion() & 0x80000000)
514 expectedDepth = 24;
518 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
520 /* It's not forbidden to create a DIB section if the flag
521 LR_CREATEDIBSECTION is absent.
522 Windows 9x does this if the bitmap has a depth that doesn't
523 match the screen depth, Windows NT doesn't */
524 dibExpected = TRUE;
525 expectedDepth = origBitmap.bmBitsPixel;
528 ok((!(dibExpected ^ copy_is_dib)
529 && (copyBitmap.bmWidth == expectedWidth)
530 && (copyBitmap.bmHeight == expectedHeight)
531 && (copyBitmap.bmBitsPixel == expectedDepth)),
532 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
533 orig_is_dib ? "DIB" : "DDB", origBitmap.bmWidth, origBitmap.bmHeight, origBitmap.bmBitsPixel,
534 copyWidth, copyHeight, flags,
535 dibExpected ? "DIB" : "DDB", expectedWidth, expectedHeight, expectedDepth,
536 copy_is_dib ? "DIB" : "DDB", copyBitmap.bmWidth, copyBitmap.bmHeight, copyBitmap.bmBitsPixel);
538 DeleteObject(copy);
542 static void test_CopyImage_Bitmap(int depth)
544 HBITMAP ddb, dib;
545 HDC screenDC;
546 BITMAPINFO * info;
547 VOID * bits;
548 int screen_depth;
549 unsigned int i;
551 /* Create a device-independent bitmap (DIB) */
552 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
553 info->bmiHeader.biSize = sizeof(info->bmiHeader);
554 info->bmiHeader.biWidth = 2;
555 info->bmiHeader.biHeight = 2;
556 info->bmiHeader.biPlanes = 1;
557 info->bmiHeader.biBitCount = depth;
558 info->bmiHeader.biCompression = BI_RGB;
560 for (i=0; i < 256; i++)
562 info->bmiColors[i].rgbRed = i;
563 info->bmiColors[i].rgbGreen = i;
564 info->bmiColors[i].rgbBlue = 255 - i;
565 info->bmiColors[i].rgbReserved = 0;
568 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
570 /* Create a device-dependent bitmap (DDB) */
571 screenDC = GetDC(NULL);
572 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
573 if (depth == 1 || depth == screen_depth)
575 ddb = CreateBitmap(2, 2, 1, depth, NULL);
577 else
579 ddb = NULL;
581 ReleaseDC(NULL, screenDC);
583 if (ddb != NULL)
585 test_CopyImage_Check(ddb, 0, 0, 0, 2, 2, depth == 1 ? 1 : screen_depth, FALSE);
586 test_CopyImage_Check(ddb, 0, 0, 5, 2, 5, depth == 1 ? 1 : screen_depth, FALSE);
587 test_CopyImage_Check(ddb, 0, 5, 0, 5, 2, depth == 1 ? 1 : screen_depth, FALSE);
588 test_CopyImage_Check(ddb, 0, 5, 5, 5, 5, depth == 1 ? 1 : screen_depth, FALSE);
590 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
591 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
592 test_CopyImage_Check(ddb, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
593 test_CopyImage_Check(ddb, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
595 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
596 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
597 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
598 test_CopyImage_Check(ddb, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
600 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
601 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
602 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
603 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
604 test_CopyImage_Check(ddb, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
606 DeleteObject(ddb);
609 if (depth != 1)
611 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
612 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
613 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
614 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
617 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 0, 2, 2, 1, FALSE);
618 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 0, 5, 2, 1, FALSE);
619 test_CopyImage_Check(dib, LR_MONOCHROME, 0, 5, 2, 5, 1, FALSE);
620 test_CopyImage_Check(dib, LR_MONOCHROME, 5, 5, 5, 5, 1, FALSE);
622 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
623 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
624 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
625 test_CopyImage_Check(dib, LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
627 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
628 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 0, 2, 2, depth, TRUE);
629 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 0, 5, 2, depth, TRUE);
630 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 0, 5, 2, 5, depth, TRUE);
631 test_CopyImage_Check(dib, LR_MONOCHROME | LR_CREATEDIBSECTION, 5, 5, 5, 5, depth, TRUE);
633 DeleteObject(dib);
635 if (depth == 1)
637 /* Special case: A monochrome DIB is converted to a monochrome DDB if
638 the colors in the color table are black and white.
640 Skip this test on Windows 95, it always creates a monochrome DDB
641 in this case */
643 if (!(GetVersion() & 0x80000000))
645 info->bmiHeader.biBitCount = 1;
646 info->bmiColors[0].rgbRed = 0xFF;
647 info->bmiColors[0].rgbGreen = 0;
648 info->bmiColors[0].rgbBlue = 0;
649 info->bmiColors[1].rgbRed = 0;
650 info->bmiColors[1].rgbGreen = 0xFF;
651 info->bmiColors[1].rgbBlue = 0;
653 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
654 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, screen_depth, FALSE);
655 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, screen_depth, FALSE);
656 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, screen_depth, FALSE);
657 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, screen_depth, FALSE);
658 DeleteObject(dib);
660 info->bmiHeader.biBitCount = 1;
661 info->bmiColors[0].rgbRed = 0;
662 info->bmiColors[0].rgbGreen = 0;
663 info->bmiColors[0].rgbBlue = 0;
664 info->bmiColors[1].rgbRed = 0xFF;
665 info->bmiColors[1].rgbGreen = 0xFF;
666 info->bmiColors[1].rgbBlue = 0xFF;
668 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
669 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
670 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
671 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
672 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
673 DeleteObject(dib);
675 info->bmiHeader.biBitCount = 1;
676 info->bmiColors[0].rgbRed = 0xFF;
677 info->bmiColors[0].rgbGreen = 0xFF;
678 info->bmiColors[0].rgbBlue = 0xFF;
679 info->bmiColors[1].rgbRed = 0;
680 info->bmiColors[1].rgbGreen = 0;
681 info->bmiColors[1].rgbBlue = 0;
683 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
684 test_CopyImage_Check(dib, 0, 0, 0, 2, 2, 1, FALSE);
685 test_CopyImage_Check(dib, 0, 5, 0, 5, 2, 1, FALSE);
686 test_CopyImage_Check(dib, 0, 0, 5, 2, 5, 1, FALSE);
687 test_CopyImage_Check(dib, 0, 5, 5, 5, 5, 1, FALSE);
688 DeleteObject(dib);
692 HeapFree(GetProcessHeap(), 0, info);
695 static void test_initial_cursor(void)
697 HCURSOR cursor, cursor2;
698 DWORD error;
700 cursor = GetCursor();
702 /* Check what handle GetCursor() returns if a cursor is not set yet. */
703 SetLastError(0xdeadbeef);
704 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_WAIT);
705 todo_wine {
706 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
708 error = GetLastError();
709 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
712 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_mask_cy, UINT exp_bpp, int line)
714 ICONINFO info;
715 DWORD ret;
716 BITMAP bmMask, bmColor;
718 ret = GetIconInfo(hIcon, &info);
719 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
721 /* CreateIcon under XP causes info.fIcon to be 0 */
722 ok_(__FILE__, line)(info.xHotspot == exp_cx/2, "info.xHotspot = %u\n", info.xHotspot);
723 ok_(__FILE__, line)(info.yHotspot == exp_cy/2, "info.yHotspot = %u\n", info.yHotspot);
724 ok_(__FILE__, line)(info.hbmMask != 0, "info.hbmMask is NULL\n");
726 ret = GetObjectA(info.hbmMask, sizeof(bmMask), &bmMask);
727 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
729 if (exp_bpp == 1)
730 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
732 if (info.hbmColor)
734 HDC hdc;
735 UINT display_bpp;
737 hdc = GetDC(0);
738 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
739 ReleaseDC(0, hdc);
741 ret = GetObjectA(info.hbmColor, sizeof(bmColor), &bmColor);
742 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
744 ok_(__FILE__, line)(bmColor.bmBitsPixel == display_bpp /* XP */ ||
745 bmColor.bmBitsPixel == exp_bpp /* Win98 */,
746 "bmColor.bmBitsPixel = %d\n", bmColor.bmBitsPixel);
747 ok_(__FILE__, line)(bmColor.bmWidth == exp_cx, "bmColor.bmWidth = %d\n", bmColor.bmWidth);
748 ok_(__FILE__, line)(bmColor.bmHeight == exp_cy, "bmColor.bmHeight = %d\n", bmColor.bmHeight);
750 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
751 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
752 ok_(__FILE__, line)(bmMask.bmHeight == exp_mask_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
754 else
756 ok_(__FILE__, line)(bmMask.bmBitsPixel == 1, "bmMask.bmBitsPixel = %d\n", bmMask.bmBitsPixel);
757 ok_(__FILE__, line)(bmMask.bmWidth == exp_cx, "bmMask.bmWidth = %d\n", bmMask.bmWidth);
758 ok_(__FILE__, line)(bmMask.bmHeight == exp_mask_cy, "bmMask.bmHeight = %d\n", bmMask.bmHeight);
760 if (pGetIconInfoExA)
762 ICONINFOEXA infoex;
764 memset( &infoex, 0xcc, sizeof(infoex) );
765 SetLastError( 0xdeadbeef );
766 infoex.cbSize = sizeof(infoex) - 1;
767 ret = pGetIconInfoExA( hIcon, &infoex );
768 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
769 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
771 SetLastError( 0xdeadbeef );
772 infoex.cbSize = sizeof(infoex) + 1;
773 ret = pGetIconInfoExA( hIcon, &infoex );
774 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
775 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %d\n", GetLastError());
777 SetLastError( 0xdeadbeef );
778 infoex.cbSize = sizeof(infoex);
779 ret = pGetIconInfoExA( (HICON)0xdeadbabe, &infoex );
780 ok_(__FILE__, line)(!ret, "GetIconInfoEx succeeded\n");
781 ok_(__FILE__, line)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE,
782 "wrong error %d\n", GetLastError());
784 infoex.cbSize = sizeof(infoex);
785 ret = pGetIconInfoExA( hIcon, &infoex );
786 ok_(__FILE__, line)(ret, "GetIconInfoEx failed err %d\n", GetLastError());
787 ok_(__FILE__, line)(infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID);
788 ok_(__FILE__, line)(infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName);
789 ok_(__FILE__, line)(infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName);
793 #define test_icon_info(a,b,c,d,e) test_icon_info_dbg((a),(b),(c),(d),(e),__LINE__)
795 static void test_CreateIcon(void)
797 static const BYTE bmp_bits[1024];
798 HICON hIcon;
799 HBITMAP hbmMask, hbmColor;
800 BITMAPINFO *bmpinfo;
801 ICONINFO info;
802 HDC hdc;
803 void *bits;
804 UINT display_bpp;
805 int i;
807 hdc = GetDC(0);
808 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
810 /* these crash under XP
811 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
812 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
815 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, bmp_bits);
816 ok(hIcon != 0, "CreateIcon failed\n");
817 test_icon_info(hIcon, 16, 16, 32, 1);
818 DestroyIcon(hIcon);
820 hIcon = CreateIcon(0, 16, 16, 1, display_bpp, bmp_bits, bmp_bits);
821 ok(hIcon != 0, "CreateIcon failed\n");
822 test_icon_info(hIcon, 16, 16, 16, display_bpp);
823 DestroyIcon(hIcon);
825 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
826 ok(hbmMask != 0, "CreateBitmap failed\n");
827 hbmColor = CreateBitmap(16, 16, 1, display_bpp, bmp_bits);
828 ok(hbmColor != 0, "CreateBitmap failed\n");
830 info.fIcon = TRUE;
831 info.xHotspot = 8;
832 info.yHotspot = 8;
833 info.hbmMask = 0;
834 info.hbmColor = 0;
835 SetLastError(0xdeadbeaf);
836 hIcon = CreateIconIndirect(&info);
837 ok(!hIcon, "CreateIconIndirect should fail\n");
838 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
840 info.fIcon = TRUE;
841 info.xHotspot = 8;
842 info.yHotspot = 8;
843 info.hbmMask = 0;
844 info.hbmColor = hbmColor;
845 SetLastError(0xdeadbeaf);
846 hIcon = CreateIconIndirect(&info);
847 ok(!hIcon, "CreateIconIndirect should fail\n");
848 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
850 info.fIcon = TRUE;
851 info.xHotspot = 8;
852 info.yHotspot = 8;
853 info.hbmMask = hbmMask;
854 info.hbmColor = hbmColor;
855 hIcon = CreateIconIndirect(&info);
856 ok(hIcon != 0, "CreateIconIndirect failed\n");
857 test_icon_info(hIcon, 16, 16, 16, display_bpp);
858 DestroyIcon(hIcon);
860 DeleteObject(hbmMask);
861 DeleteObject(hbmColor);
863 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
864 ok(hbmMask != 0, "CreateBitmap failed\n");
866 info.fIcon = TRUE;
867 info.xHotspot = 8;
868 info.yHotspot = 8;
869 info.hbmMask = hbmMask;
870 info.hbmColor = 0;
871 SetLastError(0xdeadbeaf);
872 hIcon = CreateIconIndirect(&info);
873 ok(hIcon != 0, "CreateIconIndirect failed\n");
874 test_icon_info(hIcon, 16, 16, 32, 1);
875 DestroyIcon(hIcon);
876 DeleteObject(hbmMask);
878 for (i = 0; i <= 4; i++)
880 hbmMask = CreateBitmap(1, i, 1, 1, bmp_bits);
881 ok(hbmMask != 0, "CreateBitmap failed\n");
883 info.fIcon = TRUE;
884 info.xHotspot = 0;
885 info.yHotspot = 0;
886 info.hbmMask = hbmMask;
887 info.hbmColor = 0;
888 SetLastError(0xdeadbeaf);
889 hIcon = CreateIconIndirect(&info);
890 ok(hIcon != 0, "CreateIconIndirect failed\n");
891 test_icon_info(hIcon, 1, i / 2, max(i,1), 1);
892 DestroyIcon(hIcon);
893 DeleteObject(hbmMask);
896 /* test creating an icon from a DIB section */
898 bmpinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(BITMAPINFO,bmiColors[256]));
899 bmpinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
900 bmpinfo->bmiHeader.biWidth = 32;
901 bmpinfo->bmiHeader.biHeight = 32;
902 bmpinfo->bmiHeader.biPlanes = 1;
903 bmpinfo->bmiHeader.biBitCount = 8;
904 bmpinfo->bmiHeader.biCompression = BI_RGB;
905 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
906 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
907 if (bits)
908 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
909 bmpinfo->bmiHeader.biBitCount = 1;
910 hbmMask = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
911 ok(hbmMask != NULL, "Expected a handle to the DIB\n");
912 if (bits)
913 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
915 info.fIcon = TRUE;
916 info.xHotspot = 8;
917 info.yHotspot = 8;
918 info.hbmMask = hbmColor;
919 info.hbmColor = hbmMask;
920 SetLastError(0xdeadbeaf);
921 hIcon = CreateIconIndirect(&info);
922 ok(hIcon != 0, "CreateIconIndirect failed\n");
923 test_icon_info(hIcon, 32, 32, 32, 8);
924 DestroyIcon(hIcon);
925 DeleteObject(hbmColor);
927 bmpinfo->bmiHeader.biBitCount = 16;
928 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
929 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
930 if (bits)
931 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
933 info.fIcon = TRUE;
934 info.xHotspot = 8;
935 info.yHotspot = 8;
936 info.hbmMask = hbmColor;
937 info.hbmColor = hbmMask;
938 SetLastError(0xdeadbeaf);
939 hIcon = CreateIconIndirect(&info);
940 ok(hIcon != 0, "CreateIconIndirect failed\n");
941 test_icon_info(hIcon, 32, 32, 32, 8);
942 DestroyIcon(hIcon);
943 DeleteObject(hbmColor);
945 bmpinfo->bmiHeader.biBitCount = 32;
946 hbmColor = CreateDIBSection( hdc, bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
947 ok(hbmColor != NULL, "Expected a handle to the DIB\n");
948 if (bits)
949 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
951 info.fIcon = TRUE;
952 info.xHotspot = 8;
953 info.yHotspot = 8;
954 info.hbmMask = hbmColor;
955 info.hbmColor = hbmMask;
956 SetLastError(0xdeadbeaf);
957 hIcon = CreateIconIndirect(&info);
958 ok(hIcon != 0, "CreateIconIndirect failed\n");
959 test_icon_info(hIcon, 32, 32, 32, 8);
960 DestroyIcon(hIcon);
962 DeleteObject(hbmMask);
963 DeleteObject(hbmColor);
964 HeapFree( GetProcessHeap(), 0, bmpinfo );
966 ReleaseDC(0, hdc);
969 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
970 /* 1x1 pixel gif */
971 static const unsigned char gifimage[35] = {
972 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
973 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
974 0x01,0x00,0x3b
977 /* 1x1 pixel jpg */
978 static const unsigned char jpgimage[285] = {
979 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
980 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
981 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
982 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
983 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
984 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
985 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
986 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
987 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
988 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
989 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
990 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
991 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
992 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
993 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
994 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
995 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
996 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
999 /* 1x1 pixel png */
1000 static const unsigned char pngimage[285] = {
1001 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1002 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1003 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1004 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1005 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1006 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1007 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1010 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
1011 zeroes, gap is 0xFF. */
1012 static unsigned char bmpimage[70] = {
1013 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
1014 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1015 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1016 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
1017 0xFF,0xFF,0x00,0x00,0x00,0x00
1020 /* 1x1 pixel bmp using BITMAPCOREHEADER */
1021 static const unsigned char bmpcoreimage[38] = {
1022 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
1023 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
1024 0x55,0x00,0x00,0x00,0x00,0x00
1027 /* 2x2 pixel gif */
1028 static const unsigned char gif4pixel[42] = {
1029 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1030 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1031 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1034 /* An invalid cursor with an invalid dwDIBOffset */
1035 static const unsigned char invalid_dwDIBOffset[] = {
1036 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1037 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00
1040 static const DWORD biSize_tests[] = {
1042 sizeof(BITMAPCOREHEADER) - 1,
1043 sizeof(BITMAPCOREHEADER) + 1,
1044 sizeof(BITMAPINFOHEADER) - 1,
1045 sizeof(BITMAPINFOHEADER) + 1,
1046 sizeof(BITMAPV4HEADER) - 1,
1047 sizeof(BITMAPV4HEADER) + 1,
1048 sizeof(BITMAPV5HEADER) - 1,
1049 sizeof(BITMAPV5HEADER) + 1,
1050 (sizeof(BITMAPCOREHEADER) + sizeof(BITMAPINFOHEADER)) / 2,
1051 (sizeof(BITMAPV4HEADER) + sizeof(BITMAPV5HEADER)) / 2,
1052 0xdeadbeef,
1053 0xffffffff
1056 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1058 BITMAP bm;
1059 BITMAPINFO bmi;
1060 DWORD ret, pixel = 0;
1061 HDC hdc = GetDC(NULL);
1063 ret = GetObjectA(hbm, sizeof(bm), &bm);
1064 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1066 memset(&bmi, 0, sizeof(bmi));
1067 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1068 bmi.bmiHeader.biWidth = bm.bmWidth;
1069 bmi.bmiHeader.biHeight = bm.bmHeight;
1070 bmi.bmiHeader.biPlanes = 1;
1071 bmi.bmiHeader.biBitCount= 24;
1072 bmi.bmiHeader.biCompression= BI_RGB;
1073 ret = GetDIBits(hdc, hbm, 0, bm.bmHeight, &pixel, &bmi, DIB_RGB_COLORS);
1074 ok(ret == bm.bmHeight, "%s: %d lines were converted, not %d\n", test_desc, ret, bm.bmHeight);
1076 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1078 ReleaseDC(NULL, hdc);
1081 static void test_LoadImageFile(const char * test_desc, const unsigned char * image_data,
1082 unsigned int image_size, const char * ext, BOOL expect_success)
1084 HANDLE handle;
1085 BOOL ret;
1086 DWORD error, bytes_written;
1087 char filename[64];
1089 strcpy(filename, "test.");
1090 strcat(filename, ext);
1092 /* Create the test image. */
1093 handle = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW,
1094 FILE_ATTRIBUTE_NORMAL, NULL);
1095 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1096 ret = WriteFile(handle, image_data, image_size, &bytes_written, NULL);
1097 ok(ret && bytes_written == image_size, "test file created improperly.\n");
1098 CloseHandle(handle);
1100 /* Load as cursor. For all tested formats, this should fail */
1101 SetLastError(0xdeadbeef);
1102 handle = LoadImageA(NULL, filename, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1103 ok(handle == NULL, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc);
1104 error = GetLastError();
1105 ok(error == 0 ||
1106 broken(error == 0xdeadbeef) || /* Win9x */
1107 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1108 "Last error: %u\n", error);
1109 if (handle != NULL) DestroyCursor(handle);
1111 /* Load as icon. For all tested formats, this should fail */
1112 SetLastError(0xdeadbeef);
1113 handle = LoadImageA(NULL, filename, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
1114 ok(handle == NULL, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc);
1115 error = GetLastError();
1116 ok(error == 0 ||
1117 broken(error == 0xdeadbeef) || /* Win9x */
1118 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1119 "Last error: %u\n", error);
1120 if (handle != NULL) DestroyIcon(handle);
1122 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1123 SetLastError(0xdeadbeef);
1124 handle = LoadImageA(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
1125 error = GetLastError();
1126 ok(error == 0 ||
1127 error == 0xdeadbeef, /* Win9x, WinMe */
1128 "Last error: %u\n", error);
1130 if (expect_success) {
1131 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1132 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1134 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1136 if (handle != NULL) DeleteObject(handle);
1137 DeleteFileA(filename);
1140 typedef struct {
1141 unsigned width;
1142 unsigned height;
1143 BOOL invalid_offset;
1144 } test_icon_entries_t;
1146 static void create_ico_file(const char *filename, const test_icon_entries_t *test_icon_entries, unsigned entry_cnt)
1148 CURSORICONFILEDIRENTRY *icon_entry;
1149 BITMAPINFOHEADER *icon_header;
1150 CURSORICONFILEDIR *dir;
1151 BYTE *buf, *bitmap_ptr;
1152 DWORD bytes_written;
1153 size_t icon_size;
1154 HANDLE file;
1155 unsigned i;
1156 BOOL ret;
1158 const unsigned icon_bpp = 32;
1160 icon_size = FIELD_OFFSET(CURSORICONFILEDIR, idEntries[entry_cnt]) + sizeof(BITMAPINFOHEADER)*entry_cnt;
1161 for(i=0; i<entry_cnt; i++)
1162 icon_size += icon_bpp * test_icon_entries[i].width * test_icon_entries[i].height / 8;
1164 buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, icon_size);
1165 dir = (CURSORICONFILEDIR*)buf;
1167 dir->idReserved = 0;
1168 dir->idType = 1;
1169 dir->idCount = entry_cnt;
1171 bitmap_ptr = buf + FIELD_OFFSET(CURSORICONFILEDIR, idEntries[entry_cnt]);
1172 for(i=0; i<entry_cnt; i++) {
1173 icon_entry = dir->idEntries+i;
1174 icon_entry->bWidth = test_icon_entries[i].width;
1175 icon_entry->bHeight = test_icon_entries[i].height;
1176 icon_entry->bColorCount = 0;
1177 icon_entry->bReserved = 0;
1178 icon_entry->xHotspot = 1;
1179 icon_entry->yHotspot = 1;
1180 icon_entry->dwDIBSize = sizeof(BITMAPINFOHEADER) + icon_entry->bWidth * icon_entry->bHeight * icon_bpp / 8;
1181 icon_entry->dwDIBOffset = test_icon_entries[i].invalid_offset ? 0xffffffff : bitmap_ptr - buf;
1183 icon_header = (BITMAPINFOHEADER*)bitmap_ptr;
1184 bitmap_ptr += icon_entry->dwDIBSize;
1186 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1187 icon_header->biWidth = icon_entry->bWidth;
1188 icon_header->biHeight = icon_entry->bHeight;
1189 icon_header->biPlanes = 1;
1190 icon_header->biBitCount = icon_bpp;
1191 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1194 memset(bitmap_ptr, 0xf0, buf+icon_size-bitmap_ptr);
1196 /* Create the icon. */
1197 file = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1198 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
1199 ret = WriteFile(file, buf, icon_size, &bytes_written, NULL);
1200 ok(ret && bytes_written == icon_size, "icon.ico created improperly.\n");
1201 CloseHandle(file);
1203 HeapFree(GetProcessHeap(), 0, buf);
1206 static void test_LoadImage(void)
1208 HANDLE handle;
1209 BOOL ret;
1210 DWORD error;
1211 BITMAPINFOHEADER *bitmap_header;
1212 ICONINFO icon_info;
1213 int i;
1215 #define ICON_WIDTH 32
1216 #define ICON_HEIGHT 32
1217 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1218 #define ICON_BPP 32
1219 #define ICON_SIZE \
1220 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1221 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1223 static const test_icon_entries_t icon_desc = {32, 32};
1225 create_ico_file("icon.ico", &icon_desc, 1);
1227 /* Test loading an icon as a cursor. */
1228 SetLastError(0xdeadbeef);
1229 handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
1230 ok(handle != NULL, "LoadImage() failed.\n");
1231 error = GetLastError();
1232 ok(error == 0 ||
1233 broken(error == 0xdeadbeef) || /* Win9x */
1234 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1235 "Last error: %u\n", error);
1237 /* Test the icon information. */
1238 SetLastError(0xdeadbeef);
1239 ret = GetIconInfo(handle, &icon_info);
1240 ok(ret, "GetIconInfo() failed.\n");
1241 error = GetLastError();
1242 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1244 if (ret)
1246 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1247 ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
1248 ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
1249 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1250 "No hbmColor!\n");
1251 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1254 if (pGetIconInfoExA)
1256 ICONINFOEXA infoex;
1257 infoex.cbSize = sizeof(infoex);
1258 ret = pGetIconInfoExA( handle, &infoex );
1259 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1260 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1261 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1262 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1264 else win_skip( "GetIconInfoEx not available\n" );
1266 /* Clean up. */
1267 SetLastError(0xdeadbeef);
1268 ret = DestroyCursor(handle);
1269 ok(ret, "DestroyCursor() failed.\n");
1270 error = GetLastError();
1271 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1273 DeleteFileA("icon.ico");
1275 /* Test a system icon */
1276 handle = LoadIconA( 0, (LPCSTR)IDI_HAND );
1277 ok(handle != NULL, "LoadImage() failed.\n");
1278 if (pGetIconInfoExA)
1280 ICONINFOEXA infoexA;
1281 ICONINFOEXW infoexW;
1282 infoexA.cbSize = sizeof(infoexA);
1283 ret = pGetIconInfoExA( handle, &infoexA );
1284 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1285 ok( infoexA.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexA.wResID );
1286 /* the A version is broken on 64-bit, it truncates the string after the first char */
1287 if (is_win64 && infoexA.szModName[0] && infoexA.szModName[1] == 0)
1288 trace( "GetIconInfoExA broken on Win64\n" );
1289 else
1290 ok( GetModuleHandleA(infoexA.szModName) == GetModuleHandleA("user32.dll"),
1291 "GetIconInfoEx wrong module %s\n", infoexA.szModName );
1292 ok( infoexA.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA.szResName );
1293 infoexW.cbSize = sizeof(infoexW);
1294 ret = pGetIconInfoExW( handle, &infoexW );
1295 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1296 ok( infoexW.wResID == (UINT_PTR)IDI_HAND, "GetIconInfoEx wrong resid %x\n", infoexW.wResID );
1297 ok( GetModuleHandleW(infoexW.szModName) == GetModuleHandleA("user32.dll"),
1298 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW.szModName) );
1299 ok( infoexW.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW.szResName) );
1301 SetLastError(0xdeadbeef);
1302 DestroyIcon(handle);
1304 test_LoadImageFile("BMP", bmpimage, sizeof(bmpimage), "bmp", 1);
1305 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage, sizeof(bmpcoreimage), "bmp", 1);
1306 test_LoadImageFile("GIF", gifimage, sizeof(gifimage), "gif", 0);
1307 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel, sizeof(gif4pixel), "gif", 0);
1308 test_LoadImageFile("JPG", jpgimage, sizeof(jpgimage), "jpg", 0);
1309 test_LoadImageFile("PNG", pngimage, sizeof(pngimage), "png", 0);
1311 /* Check failure for broken BMP images */
1312 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1314 bitmap_header->biHeight = 65536;
1315 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1316 bitmap_header->biHeight = 1;
1318 bitmap_header->biWidth = 65536;
1319 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1320 bitmap_header->biWidth = 1;
1322 for (i = 0; i < ARRAY_SIZE(biSize_tests); i++) {
1323 bitmap_header->biSize = biSize_tests[i];
1324 test_LoadImageFile("BMP (broken biSize)", bmpimage, sizeof(bmpimage), "bmp", 0);
1326 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1328 test_LoadImageFile("Cursor (invalid dwDIBOffset)", invalid_dwDIBOffset, sizeof(invalid_dwDIBOffset), "cur", 0);
1331 #undef ARRAY_SIZE
1333 static void test_CreateIconFromResource(void)
1335 HANDLE handle;
1336 BOOL ret;
1337 DWORD error;
1338 BITMAPINFOHEADER *icon_header;
1339 INT16 *hotspot;
1340 ICONINFO icon_info;
1342 #define ICON_RES_WIDTH 32
1343 #define ICON_RES_HEIGHT 32
1344 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1345 #define ICON_RES_BPP 32
1346 #define ICON_RES_SIZE \
1347 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1348 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1350 /* Set icon data. */
1351 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1353 /* Cursor resources have an extra hotspot, icon resources not. */
1354 hotspot[0] = 3;
1355 hotspot[1] = 3;
1357 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1358 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1359 icon_header->biWidth = ICON_WIDTH;
1360 icon_header->biHeight = ICON_HEIGHT*2;
1361 icon_header->biPlanes = 1;
1362 icon_header->biBitCount = ICON_BPP;
1363 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1365 /* Test creating a cursor. */
1366 SetLastError(0xdeadbeef);
1367 handle = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1368 ok(handle != NULL, "Create cursor failed.\n");
1370 /* Test the icon information. */
1371 SetLastError(0xdeadbeef);
1372 ret = GetIconInfo(handle, &icon_info);
1373 ok(ret, "GetIconInfo() failed.\n");
1374 error = GetLastError();
1375 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1377 if (ret)
1379 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1380 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1381 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1382 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1383 "No hbmColor!\n");
1384 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1387 if (pGetIconInfoExA)
1389 ICONINFOEXA infoex;
1390 infoex.cbSize = sizeof(infoex);
1391 ret = pGetIconInfoExA( handle, &infoex );
1392 ok( ret, "GetIconInfoEx failed err %d\n", GetLastError() );
1393 ok( infoex.wResID == 0, "GetIconInfoEx wrong resid %x\n", infoex.wResID );
1394 ok( infoex.szModName[0] == 0, "GetIconInfoEx wrong module %s\n", infoex.szModName );
1395 ok( infoex.szResName[0] == 0, "GetIconInfoEx wrong name %s\n", infoex.szResName );
1398 /* Clean up. */
1399 SetLastError(0xdeadbeef);
1400 ret = DestroyCursor(handle);
1401 ok(ret, "DestroyCursor() failed.\n");
1402 error = GetLastError();
1403 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1405 /* Test creating an icon. */
1406 SetLastError(0xdeadbeef);
1407 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1408 0x00030000);
1409 ok(handle != NULL, "Create icon failed.\n");
1411 /* Test the icon information. */
1412 SetLastError(0xdeadbeef);
1413 ret = GetIconInfo(handle, &icon_info);
1414 ok(ret, "GetIconInfo() failed.\n");
1415 error = GetLastError();
1416 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1418 if (ret)
1420 ok(icon_info.fIcon == TRUE, "fIcon != TRUE.\n");
1421 /* Icons always have hotspot in the middle */
1422 ok(icon_info.xHotspot == ICON_WIDTH/2, "xHotspot is %u.\n", icon_info.xHotspot);
1423 ok(icon_info.yHotspot == ICON_HEIGHT/2, "yHotspot is %u.\n", icon_info.yHotspot);
1424 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
1425 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1428 /* Clean up. */
1429 SetLastError(0xdeadbeef);
1430 ret = DestroyCursor(handle);
1431 ok(ret, "DestroyCursor() failed.\n");
1432 error = GetLastError();
1433 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1435 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1437 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1438 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1440 HeapFree(GetProcessHeap(), 0, hotspot);
1442 /* Test creating an animated cursor. */
1443 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1444 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1445 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1446 handle = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1447 ok(handle != NULL, "Create cursor failed.\n");
1449 /* Test the animated cursor's information. */
1450 SetLastError(0xdeadbeef);
1451 ret = GetIconInfo(handle, &icon_info);
1452 ok(ret, "GetIconInfo() failed.\n");
1453 error = GetLastError();
1454 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1456 if (ret)
1458 ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
1459 ok(icon_info.xHotspot == 3, "xHotspot is %u.\n", icon_info.xHotspot);
1460 ok(icon_info.yHotspot == 3, "yHotspot is %u.\n", icon_info.yHotspot);
1461 ok(icon_info.hbmColor != NULL || broken(!icon_info.hbmColor) /* no color cursor support */,
1462 "No hbmColor!\n");
1463 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1466 /* Clean up. */
1467 SetLastError(0xdeadbeef);
1468 ret = DestroyCursor(handle);
1469 ok(ret, "DestroyCursor() failed.\n");
1470 error = GetLastError();
1471 ok(error == 0xdeadbeef, "Last error: %u\n", error);
1474 static int check_cursor_data( HDC hdc, HCURSOR hCursor, void *data, int length)
1476 char *image = NULL;
1477 BITMAPINFO *info;
1478 ICONINFO iinfo;
1479 DWORD ret;
1480 int i;
1482 ret = GetIconInfo( hCursor, &iinfo );
1483 ok(ret, "GetIconInfo() failed\n");
1484 if (!ret) return 0;
1485 ret = 0;
1486 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ));
1487 ok(info != NULL, "HeapAlloc() failed\n");
1488 if (!info) return 0;
1490 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1491 info->bmiHeader.biWidth = 32;
1492 info->bmiHeader.biHeight = 32;
1493 info->bmiHeader.biPlanes = 1;
1494 info->bmiHeader.biBitCount = 32;
1495 info->bmiHeader.biCompression = BI_RGB;
1496 info->bmiHeader.biSizeImage = 32 * 32 * 4;
1497 info->bmiHeader.biXPelsPerMeter = 0;
1498 info->bmiHeader.biYPelsPerMeter = 0;
1499 info->bmiHeader.biClrUsed = 0;
1500 info->bmiHeader.biClrImportant = 0;
1501 image = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage );
1502 ok(image != NULL, "HeapAlloc() failed\n");
1503 if (!image) goto cleanup;
1504 ret = GetDIBits( hdc, iinfo.hbmColor, 0, 32, image, info, DIB_RGB_COLORS );
1505 ok(ret, "GetDIBits() failed\n");
1506 for (i = 0; ret && i < length / sizeof(COLORREF); i++)
1508 ret = color_match( ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1509 ok(ret, "%04x: Expected 0x%x, actually 0x%x\n", i, ((COLORREF *)data)[i], ((COLORREF *)image)[i] );
1511 cleanup:
1512 HeapFree( GetProcessHeap(), 0, image );
1513 HeapFree( GetProcessHeap(), 0, info );
1514 return ret;
1517 static HCURSOR (WINAPI *pGetCursorFrameInfo)(HCURSOR hCursor, DWORD unk1, DWORD istep, DWORD *rate, DWORD *steps);
1518 static void test_GetCursorFrameInfo(void)
1520 DWORD frame_identifier[] = { 0x10Ad, 0xc001, 0x1c05 };
1521 HBITMAP bmp = NULL, bmpOld = NULL;
1522 DWORD rate, steps;
1523 BITMAPINFOHEADER *icon_header;
1524 BITMAPINFO bitmapInfo;
1525 HDC hdc = NULL;
1526 void *bits = 0;
1527 INT16 *hotspot;
1528 HANDLE h1, h2;
1529 BOOL ret;
1530 int i;
1532 if (!pGetCursorFrameInfo)
1534 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1535 return;
1538 hdc = CreateCompatibleDC(0);
1539 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1540 if (!hdc)
1541 return;
1543 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1544 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1545 bitmapInfo.bmiHeader.biWidth = 3;
1546 bitmapInfo.bmiHeader.biHeight = 3;
1547 bitmapInfo.bmiHeader.biBitCount = 32;
1548 bitmapInfo.bmiHeader.biPlanes = 1;
1549 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1550 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1551 bmp = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1552 ok (bmp && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1553 if (!bmp || !bits)
1554 goto cleanup;
1555 bmpOld = SelectObject(hdc, bmp);
1557 #define ICON_RES_WIDTH 32
1558 #define ICON_RES_HEIGHT 32
1559 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1560 #define ICON_RES_BPP 32
1561 #define ICON_RES_SIZE \
1562 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1563 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1565 /* Set icon data. */
1566 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1568 /* Cursor resources have an extra hotspot, icon resources not. */
1569 hotspot[0] = 3;
1570 hotspot[1] = 3;
1572 icon_header = (BITMAPINFOHEADER *) (hotspot + 2);
1573 icon_header->biSize = sizeof(BITMAPINFOHEADER);
1574 icon_header->biWidth = ICON_WIDTH;
1575 icon_header->biHeight = ICON_HEIGHT*2;
1576 icon_header->biPlanes = 1;
1577 icon_header->biBitCount = ICON_BPP;
1578 icon_header->biSizeImage = 0; /* Uncompressed bitmap. */
1580 /* Creating a static cursor. */
1581 SetLastError(0xdeadbeef);
1582 h1 = CreateIconFromResource((PBYTE) hotspot, CRSR_RES_SIZE, FALSE, 0x00030000);
1583 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1585 /* Check GetCursorFrameInfo behavior on a static cursor */
1586 rate = steps = 0xdead;
1587 h2 = pGetCursorFrameInfo(h1, 0xdead, 0xdead, &rate, &steps);
1588 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1589 ok(rate == 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1590 ok(steps == 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1592 /* Clean up static cursor. */
1593 SetLastError(0xdeadbeef);
1594 ret = DestroyCursor(h1);
1595 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1597 /* Creating a single-frame animated cursor. */
1598 empty_anicursor.frames[0].data.icon_info.idType = 2; /* type: cursor */
1599 empty_anicursor.frames[0].data.icon_info.idEntries[0].xHotspot = 3;
1600 empty_anicursor.frames[0].data.icon_info.idEntries[0].yHotspot = 3;
1601 memcpy( &empty_anicursor.frames[0].data.bmi_data.data[0], &frame_identifier[0], sizeof(DWORD) );
1602 SetLastError(0xdeadbeef);
1603 h1 = CreateIconFromResource((PBYTE) &empty_anicursor, sizeof(empty_anicursor), FALSE, 0x00030000);
1604 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1606 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1607 rate = steps = 0xdead;
1608 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1609 ok(h1 == h2, "GetCursorFrameInfo() failed: (%p != %p).\n", h1, h2);
1610 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1611 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1612 ok(rate == 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate);
1613 ok(steps == empty_anicursor.header.header.num_steps,
1614 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps);
1616 /* Clean up single-frame animated cursor. */
1617 SetLastError(0xdeadbeef);
1618 ret = DestroyCursor(h1);
1619 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1621 /* Creating a multi-frame animated cursor. */
1622 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1624 empty_anicursor3.frames[i].data.icon_info.idType = 2; /* type: cursor */
1625 empty_anicursor3.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1626 empty_anicursor3.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1627 memcpy( &empty_anicursor3.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1629 SetLastError(0xdeadbeef);
1630 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1631 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1633 /* Check number of steps in multi-frame animated cursor */
1634 i=0;
1635 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1636 i++;
1637 ok(i == empty_anicursor3.header.header.num_steps,
1638 "Unexpected number of steps in cursor (%d != %d)\n",
1639 i, empty_anicursor3.header.header.num_steps);
1641 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1642 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1644 rate = steps = 0xdead;
1645 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1646 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1647 ret = check_cursor_data( hdc, h2, &frame_identifier[i], sizeof(DWORD) );
1648 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1649 ok(rate == empty_anicursor3.header.header.display_rate,
1650 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1651 rate, empty_anicursor3.header.header.display_rate);
1652 ok(steps == empty_anicursor3.header.header.num_steps,
1653 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1654 steps, empty_anicursor3.header.header.num_steps);
1657 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1658 rate = steps = 0xdead;
1659 h2 = pGetCursorFrameInfo(h1, 0xdead, 3, &rate, &steps);
1660 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1661 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1662 || broken(rate == ~0) /*win2k (sporadic)*/,
1663 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1664 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1665 || broken(steps == 0) /*win2k (sporadic)*/,
1666 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps);
1668 /* Clean up multi-frame animated cursor. */
1669 SetLastError(0xdeadbeef);
1670 ret = DestroyCursor(h1);
1671 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1673 /* Create a multi-frame animated cursor with num_steps == 1 */
1674 empty_anicursor3.header.header.num_steps = 1;
1675 SetLastError(0xdeadbeef);
1676 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3, sizeof(empty_anicursor3), FALSE, 0x00030000);
1677 ok(h1 != NULL, "Create cursor failed (error = %d).\n", GetLastError());
1679 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1680 i=0;
1681 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1682 i++;
1683 ok(i == empty_anicursor3.header.header.num_steps,
1684 "Unexpected number of steps in cursor (%d != %d)\n",
1685 i, empty_anicursor3.header.header.num_steps);
1687 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1688 rate = steps = 0xdead;
1689 h2 = pGetCursorFrameInfo(h1, 0xdead, 0, &rate, &steps);
1690 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1691 ret = check_cursor_data( hdc, h2, &frame_identifier[0], sizeof(DWORD) );
1692 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1693 ok(rate == empty_anicursor3.header.header.display_rate,
1694 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1695 rate, empty_anicursor3.header.header.display_rate);
1696 ok(steps == ~0 || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/,
1697 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps);
1699 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1700 rate = steps = 0xdead;
1701 h2 = pGetCursorFrameInfo(h1, 0xdead, 1, &rate, &steps);
1702 ok(h2 == 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1, h2);
1703 ok(rate == 0xdead || broken(rate == empty_anicursor3.header.header.display_rate) /*win2k*/
1704 || broken(rate == ~0) /*win2k (sporadic)*/,
1705 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate);
1706 ok(steps == 0xdead || broken(steps == empty_anicursor3.header.header.num_steps) /*win2k*/
1707 || broken(steps == 0) /*win2k (sporadic)*/,
1708 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps);
1710 /* Clean up multi-frame animated cursor. */
1711 SetLastError(0xdeadbeef);
1712 ret = DestroyCursor(h1);
1713 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1715 /* Creating a multi-frame animated cursor with rate data. */
1716 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1718 empty_anicursor3_seq.frames[i].data.icon_info.idType = 2; /* type: cursor */
1719 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].xHotspot = 3;
1720 empty_anicursor3_seq.frames[i].data.icon_info.idEntries[0].yHotspot = 3;
1721 memcpy( &empty_anicursor3_seq.frames[i].data.bmi_data.data[0], &frame_identifier[i], sizeof(DWORD) );
1723 SetLastError(0xdeadbeef);
1724 h1 = CreateIconFromResource((PBYTE) &empty_anicursor3_seq, sizeof(empty_anicursor3_seq), FALSE, 0x00030000);
1725 ok(h1 != NULL, "Create cursor failed (error = %x).\n", GetLastError());
1727 /* Check number of steps in multi-frame animated cursor with rate data */
1728 i=0;
1729 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1730 i++;
1731 ok(i == empty_anicursor3_seq.header.header.num_steps,
1732 "Unexpected number of steps in cursor (%d != %d)\n",
1733 i, empty_anicursor3_seq.header.header.num_steps);
1735 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1736 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1738 int frame_id = empty_anicursor3_seq.seq.order[i];
1740 rate = steps = 0xdead;
1741 h2 = pGetCursorFrameInfo(h1, 0xdead, i, &rate, &steps);
1742 ok(h1 != h2 && h2 != 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1, h1, h2);
1743 ret = check_cursor_data( hdc, h2, &frame_identifier[frame_id], sizeof(DWORD) );
1744 ok(ret, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i);
1745 ok(rate == empty_anicursor3_seq.rates.rate[i],
1746 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1747 rate, empty_anicursor3_seq.rates.rate[i]);
1748 ok(steps == empty_anicursor3_seq.header.header.num_steps,
1749 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1750 steps, empty_anicursor3_seq.header.header.num_steps);
1753 /* Clean up multi-frame animated cursor with rate data. */
1754 SetLastError(0xdeadbeef);
1755 ret = DestroyCursor(h1);
1756 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1758 HeapFree(GetProcessHeap(), 0, hotspot);
1759 cleanup:
1760 if(bmpOld) SelectObject(hdc, bmpOld);
1761 if(bmp) DeleteObject(bmp);
1762 if(hdc) DeleteDC(hdc);
1765 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1766 BOOL maskvalue, UINT32 *color, int colorSize)
1768 ICONINFO iconInfo;
1769 BITMAPINFO bitmapInfo;
1770 void *buffer = NULL;
1771 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1773 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1774 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1775 bitmapInfo.bmiHeader.biWidth = width;
1776 bitmapInfo.bmiHeader.biHeight = height;
1777 bitmapInfo.bmiHeader.biPlanes = 1;
1778 bitmapInfo.bmiHeader.biBitCount = bpp;
1779 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1780 bitmapInfo.bmiHeader.biSizeImage = colorSize;
1782 iconInfo.fIcon = TRUE;
1783 iconInfo.xHotspot = 0;
1784 iconInfo.yHotspot = 0;
1786 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1787 if(!iconInfo.hbmMask) return NULL;
1789 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1790 if(!iconInfo.hbmColor || !buffer)
1792 DeleteObject(iconInfo.hbmMask);
1793 return NULL;
1796 memcpy(buffer, color, colorSize);
1798 return CreateIconIndirect(&iconInfo);
1801 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1803 HICON hicon;
1804 UINT32 color[2];
1805 COLORREF modern_expected, legacy_expected, result;
1807 color[0] = 0x00A0B0C0;
1808 color[1] = alpha ? 0xFF000000 : 0x00000000;
1809 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1810 legacy_expected = 0x00C0B0A0;
1812 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1813 if (!hicon) return;
1815 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1817 if(drawiconex)
1818 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1819 else
1820 DrawIcon(hdc, 0, 0, hicon);
1822 result = GetPixel(hdc, 0, 0);
1823 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1824 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1825 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1826 "Got %06X from line %d\n",
1827 alpha ? "Alpha blending" : "Not alpha blending", modern_expected, legacy_expected,
1828 drawiconex ? "DrawIconEx" : "DrawIcon", result, line);
1831 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1832 COLORREF modern_expected, COLORREF legacy_expected, int line)
1834 COLORREF result;
1835 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1836 if (!hicon) return;
1837 SetPixelV(hdc, 0, 0, background);
1838 SetPixelV(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1, background);
1839 SetPixelV(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), background);
1840 DrawIcon(hdc, 0, 0, hicon);
1841 result = GetPixel(hdc, 0, 0);
1843 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1844 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1845 "Overlaying Mask %d on Color %06X with DrawIcon. "
1846 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1847 maskvalue, color, modern_expected, legacy_expected, result, line);
1849 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1851 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1852 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1853 "Overlaying Mask %d on Color %06X with DrawIcon. "
1854 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1855 maskvalue, color, modern_expected, legacy_expected, result, line);
1857 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1859 ok (color_match(result, background),
1860 "Overlaying Mask %d on Color %06X with DrawIcon. "
1861 "Expected unchanged background color %06X. Got %06X from line %d\n",
1862 maskvalue, color, background, result, line);
1865 static void test_DrawIcon(void)
1867 BITMAPINFO bitmapInfo;
1868 HDC hdcDst = NULL;
1869 HBITMAP bmpDst = NULL;
1870 HBITMAP bmpOld = NULL;
1871 void *bits = 0;
1873 hdcDst = CreateCompatibleDC(0);
1874 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1875 if (!hdcDst)
1876 return;
1878 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1880 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1881 goto cleanup;
1884 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1885 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1886 bitmapInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXICON)+1;
1887 bitmapInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYICON)+1;
1888 bitmapInfo.bmiHeader.biBitCount = 32;
1889 bitmapInfo.bmiHeader.biPlanes = 1;
1890 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1891 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1893 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1894 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1895 if (!bmpDst || !bits)
1896 goto cleanup;
1897 bmpOld = SelectObject(hdcDst, bmpDst);
1899 /* Mask is only heeded if alpha channel is always zero */
1900 check_DrawIcon(hdcDst, FALSE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1901 check_DrawIcon(hdcDst, TRUE, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1903 /* Test alpha blending */
1904 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1905 check_DrawIcon(hdcDst, FALSE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1906 check_DrawIcon(hdcDst, TRUE, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
1908 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1909 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
1910 check_DrawIcon(hdcDst, FALSE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
1911 check_DrawIcon(hdcDst, TRUE, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
1913 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1914 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1916 /* Test detecting of alpha channel */
1917 /* If a single pixel's alpha channel is non-zero, the icon
1918 will be alpha blended, otherwise it will be draw with
1919 and + xor blts. */
1920 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1921 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1923 cleanup:
1924 if(bmpOld)
1925 SelectObject(hdcDst, bmpOld);
1926 if(bmpDst)
1927 DeleteObject(bmpDst);
1928 if(hdcDst)
1929 DeleteDC(hdcDst);
1932 static void check_DrawIconEx(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, UINT flags, COLORREF background,
1933 COLORREF modern_expected, COLORREF legacy_expected, int line)
1935 COLORREF result;
1936 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1937 if (!hicon) return;
1938 SetPixelV(hdc, 0, 0, background);
1939 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1940 result = GetPixel(hdc, 0, 0);
1942 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
1943 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
1944 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1945 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1946 maskvalue, color, flags, modern_expected, legacy_expected, result, line);
1949 static void test_DrawIconEx(void)
1951 BITMAPINFO bitmapInfo;
1952 HDC hdcDst = NULL;
1953 HBITMAP bmpDst = NULL;
1954 HBITMAP bmpOld = NULL;
1955 void *bits = 0;
1957 hdcDst = CreateCompatibleDC(0);
1958 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1959 if (!hdcDst)
1960 return;
1962 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1964 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1965 goto cleanup;
1968 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
1969 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1970 bitmapInfo.bmiHeader.biWidth = 1;
1971 bitmapInfo.bmiHeader.biHeight = 1;
1972 bitmapInfo.bmiHeader.biBitCount = 32;
1973 bitmapInfo.bmiHeader.biPlanes = 1;
1974 bitmapInfo.bmiHeader.biCompression = BI_RGB;
1975 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
1976 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
1977 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1978 if (!bmpDst || !bits)
1979 goto cleanup;
1980 bmpOld = SelectObject(hdcDst, bmpDst);
1982 /* Test null, image only, and mask only drawing */
1983 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1984 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__);
1986 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_MASK, 0x00123456, 0x00000000, 0x00000000, __LINE__);
1987 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_MASK, 0x00123456, 0x00FFFFFF, 0x00FFFFFF, __LINE__);
1989 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1990 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_IMAGE, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1992 /* Test normal drawing */
1993 check_DrawIconEx(hdcDst, FALSE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1994 check_DrawIconEx(hdcDst, TRUE, 0x00A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__);
1995 check_DrawIconEx(hdcDst, FALSE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
1997 /* Test alpha blending */
1998 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1999 check_DrawIconEx(hdcDst, TRUE, 0xFFA0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__);
2001 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
2002 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__);
2003 check_DrawIconEx(hdcDst, FALSE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__);
2004 check_DrawIconEx(hdcDst, TRUE, 0x80A0B0C0, 32, DI_NORMAL, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__);
2006 check_DrawIconEx(hdcDst, FALSE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
2007 check_DrawIconEx(hdcDst, TRUE, 0x01FFFFFF, 32, DI_NORMAL, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
2009 /* Test detecting of alpha channel */
2010 /* If a single pixel's alpha channel is non-zero, the icon
2011 will be alpha blended, otherwise it will be draw with
2012 and + xor blts. */
2013 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
2014 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
2016 cleanup:
2017 if(bmpOld)
2018 SelectObject(hdcDst, bmpOld);
2019 if(bmpDst)
2020 DeleteObject(bmpDst);
2021 if(hdcDst)
2022 DeleteDC(hdcDst);
2025 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
2027 COLORREF result, background;
2028 BOOL passed[2];
2029 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2030 background = 0x00FFFFFF;
2031 /* Set color of the 2 pixels that will be checked afterwards */
2032 SetPixelV(hdc, 0, 0, background);
2033 SetPixelV(hdc, 2, 2, background);
2035 /* Let DrawState calculate the size of the icon (it's 1x1) */
2036 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
2038 result = GetPixel(hdc, 0, 0);
2039 passed[0] = color_match(result, background);
2040 result = GetPixel(hdc, 2, 2);
2041 passed[0] = passed[0] & color_match(result, background);
2043 /* Check if manually specifying the icon size DOESN'T work */
2045 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
2046 * size in which it should be ultimately drawn. Therefore giving
2047 * width/height 2x2 if the icon is only 1x1 pixels in size should
2048 * result in drawing it with size 1x1. The size parameters must be
2049 * ignored if a Icon has to be drawn! */
2050 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
2052 result = GetPixel(hdc, 0, 0);
2053 passed[1] = color_match(result, background);
2054 result = GetPixel(hdc, 2, 2);
2055 passed[1] = passed[0] & color_match(result, background);
2057 if(!passed[0]&&!passed[1])
2058 ok (passed[1],
2059 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
2060 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
2061 "Color %06X with flags %08X. Line %d\n",
2062 maskvalue, color, (DST_ICON | flags), line);
2063 else if(!passed[1])
2064 ok (passed[1],
2065 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2066 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
2067 "Mask %d on Color %06X with flags %08X. Line %d\n",
2068 maskvalue, color, (DST_ICON | flags), line);
2069 else
2070 ok (passed[0],
2071 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2072 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
2073 "Color %06X with flags %08X. Line %d\n",
2074 maskvalue, color, (DST_ICON | flags), line);
2077 static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags,
2078 COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
2080 COLORREF result;
2081 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2082 if (!hicon) return;
2083 /* Set color of the pixel that will be checked afterwards */
2084 SetPixelV(hdc, 1, 1, background);
2086 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
2088 /* Check the color of the pixel is correct */
2089 result = GetPixel(hdc, 1, 1);
2091 ok (color_match(result, modern_expected) || /* Windows 2000 and up */
2092 broken(color_match(result, legacy_expected)), /* Windows NT 4.0, 9X and below */
2093 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2094 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2095 maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
2098 static void test_DrawState(void)
2100 BITMAPINFO bitmapInfo;
2101 HDC hdcDst = NULL;
2102 HBITMAP bmpDst = NULL;
2103 HBITMAP bmpOld = NULL;
2104 void *bits = 0;
2106 hdcDst = CreateCompatibleDC(0);
2107 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2108 if (!hdcDst)
2109 return;
2111 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
2113 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2114 goto cleanup;
2117 memset(&bitmapInfo, 0, sizeof(bitmapInfo));
2118 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2119 bitmapInfo.bmiHeader.biWidth = 3;
2120 bitmapInfo.bmiHeader.biHeight = 3;
2121 bitmapInfo.bmiHeader.biBitCount = 32;
2122 bitmapInfo.bmiHeader.biPlanes = 1;
2123 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2124 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2125 bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0);
2126 ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2127 if (!bmpDst || !bits)
2128 goto cleanup;
2129 bmpOld = SelectObject(hdcDst, bmpDst);
2131 /* potential flags to test with DrawState are: */
2132 /* DSS_DISABLED embosses the icon */
2133 /* DSS_MONO draw Icon using a brush as parameter 5 */
2134 /* DSS_NORMAL draw Icon without any modifications */
2135 /* DSS_UNION draw the Icon dithered */
2137 check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
2138 check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
2140 cleanup:
2141 if(bmpOld)
2142 SelectObject(hdcDst, bmpOld);
2143 if(bmpDst)
2144 DeleteObject(bmpDst);
2145 if(hdcDst)
2146 DeleteDC(hdcDst);
2149 static DWORD parent_id;
2151 static DWORD CALLBACK set_cursor_thread( void *arg )
2153 HCURSOR ret;
2155 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2156 if (parent_id)
2158 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2159 ok( ret, "AttachThreadInput failed\n" );
2161 if (arg) ret = SetCursor( (HCURSOR)arg );
2162 else ret = GetCursor();
2163 return (DWORD_PTR)ret;
2166 static void test_SetCursor(void)
2168 static const BYTE bmp_bits[4096];
2169 ICONINFO cursorInfo;
2170 HCURSOR cursor, old_cursor, global_cursor = 0;
2171 DWORD error, id, result;
2172 UINT display_bpp;
2173 HDC hdc;
2174 HANDLE thread;
2175 CURSORINFO info;
2177 if (pGetCursorInfo)
2179 memset( &info, 0, sizeof(info) );
2180 info.cbSize = sizeof(info);
2181 if (!pGetCursorInfo( &info ))
2183 win_skip( "GetCursorInfo not working\n" );
2184 pGetCursorInfo = NULL;
2186 else global_cursor = info.hCursor;
2188 cursor = GetCursor();
2189 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2190 WaitForSingleObject( thread, 1000 );
2191 GetExitCodeThread( thread, &result );
2192 ok( result == (DWORD_PTR)cursor, "wrong thread cursor %x/%p\n", result, cursor );
2194 hdc = GetDC(0);
2195 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2196 ReleaseDC(0, hdc);
2198 cursorInfo.fIcon = FALSE;
2199 cursorInfo.xHotspot = 0;
2200 cursorInfo.yHotspot = 0;
2201 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2202 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2204 cursor = CreateIconIndirect(&cursorInfo);
2205 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2206 old_cursor = SetCursor( cursor );
2208 if (pGetCursorInfo)
2210 info.cbSize = sizeof(info);
2211 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2212 /* global cursor doesn't change since we don't have a window */
2213 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2214 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2216 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2217 WaitForSingleObject( thread, 1000 );
2218 GetExitCodeThread( thread, &result );
2219 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2221 SetCursor( 0 );
2222 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2223 thread = CreateThread( NULL, 0, set_cursor_thread, 0, 0, &id );
2224 WaitForSingleObject( thread, 1000 );
2225 GetExitCodeThread( thread, &result );
2226 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2228 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2229 WaitForSingleObject( thread, 1000 );
2230 GetExitCodeThread( thread, &result );
2231 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2232 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2234 parent_id = GetCurrentThreadId();
2235 thread = CreateThread( NULL, 0, set_cursor_thread, cursor, 0, &id );
2236 WaitForSingleObject( thread, 1000 );
2237 GetExitCodeThread( thread, &result );
2238 ok( result == (DWORD_PTR)old_cursor, "wrong thread cursor %x/%p\n", result, old_cursor );
2239 ok( GetCursor() == cursor, "wrong cursor %p/0\n", cursor );
2241 if (pGetCursorInfo)
2243 info.cbSize = sizeof(info);
2244 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2245 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2246 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2248 SetCursor( old_cursor );
2249 DestroyCursor( cursor );
2251 SetLastError( 0xdeadbeef );
2252 cursor = SetCursor( (HCURSOR)0xbadbad );
2253 error = GetLastError();
2254 ok( cursor == 0, "wrong cursor %p/0\n", cursor );
2255 ok( error == ERROR_INVALID_CURSOR_HANDLE || broken( error == 0xdeadbeef ), /* win9x */
2256 "wrong error %u\n", error );
2258 if (pGetCursorInfo)
2260 info.cbSize = sizeof(info);
2261 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2262 ok( info.hCursor == global_cursor || broken(info.hCursor != cursor), /* win9x */
2263 "wrong info cursor %p/%p\n", info.hCursor, global_cursor );
2267 static HANDLE event_start, event_next;
2269 static DWORD CALLBACK show_cursor_thread( void *arg )
2271 DWORD count = (DWORD_PTR)arg;
2272 int ret;
2274 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2275 if (parent_id)
2277 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2278 ok( ret, "AttachThreadInput failed\n" );
2280 if (!count) ret = ShowCursor( FALSE );
2281 else while (count--) ret = ShowCursor( TRUE );
2282 SetEvent( event_start );
2283 WaitForSingleObject( event_next, 2000 );
2284 return ret;
2287 static void test_ShowCursor(void)
2289 int count;
2290 DWORD id, result;
2291 HANDLE thread;
2292 CURSORINFO info;
2294 if (pGetCursorInfo)
2296 memset( &info, 0, sizeof(info) );
2297 info.cbSize = sizeof(info);
2298 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2299 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2302 event_start = CreateEventW( NULL, FALSE, FALSE, NULL );
2303 event_next = CreateEventW( NULL, FALSE, FALSE, NULL );
2305 count = ShowCursor( TRUE );
2306 ok( count == 1, "wrong count %d\n", count );
2307 count = ShowCursor( TRUE );
2308 ok( count == 2, "wrong count %d\n", count );
2309 count = ShowCursor( FALSE );
2310 ok( count == 1, "wrong count %d\n", count );
2311 count = ShowCursor( FALSE );
2312 ok( count == 0, "wrong count %d\n", count );
2313 count = ShowCursor( FALSE );
2314 ok( count == -1, "wrong count %d\n", count );
2315 count = ShowCursor( FALSE );
2316 ok( count == -2, "wrong count %d\n", count );
2318 if (pGetCursorInfo)
2320 info.cbSize = sizeof(info);
2321 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2322 /* global show count is not affected since we don't have a window */
2323 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2326 parent_id = 0;
2327 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2328 WaitForSingleObject( event_start, 1000 );
2329 count = ShowCursor( FALSE );
2330 ok( count == -3, "wrong count %d\n", count );
2331 SetEvent( event_next );
2332 WaitForSingleObject( thread, 1000 );
2333 GetExitCodeThread( thread, &result );
2334 ok( result == -1, "wrong thread count %d\n", result );
2335 count = ShowCursor( FALSE );
2336 ok( count == -4, "wrong count %d\n", count );
2338 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)1, 0, &id );
2339 WaitForSingleObject( event_start, 1000 );
2340 count = ShowCursor( TRUE );
2341 ok( count == -3, "wrong count %d\n", count );
2342 SetEvent( event_next );
2343 WaitForSingleObject( thread, 1000 );
2344 GetExitCodeThread( thread, &result );
2345 ok( result == 1, "wrong thread count %d\n", result );
2346 count = ShowCursor( TRUE );
2347 ok( count == -2, "wrong count %d\n", count );
2349 parent_id = GetCurrentThreadId();
2350 thread = CreateThread( NULL, 0, show_cursor_thread, NULL, 0, &id );
2351 WaitForSingleObject( event_start, 1000 );
2352 count = ShowCursor( TRUE );
2353 ok( count == -2, "wrong count %d\n", count );
2354 SetEvent( event_next );
2355 WaitForSingleObject( thread, 1000 );
2356 GetExitCodeThread( thread, &result );
2357 ok( result == -3, "wrong thread count %d\n", result );
2358 count = ShowCursor( FALSE );
2359 ok( count == -2, "wrong count %d\n", count );
2361 thread = CreateThread( NULL, 0, show_cursor_thread, (void *)3, 0, &id );
2362 WaitForSingleObject( event_start, 1000 );
2363 count = ShowCursor( TRUE );
2364 ok( count == 2, "wrong count %d\n", count );
2365 SetEvent( event_next );
2366 WaitForSingleObject( thread, 1000 );
2367 GetExitCodeThread( thread, &result );
2368 ok( result == 1, "wrong thread count %d\n", result );
2369 count = ShowCursor( FALSE );
2370 ok( count == -2, "wrong count %d\n", count );
2372 if (pGetCursorInfo)
2374 info.cbSize = sizeof(info);
2375 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2376 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2379 count = ShowCursor( TRUE );
2380 ok( count == -1, "wrong count %d\n", count );
2381 count = ShowCursor( TRUE );
2382 ok( count == 0, "wrong count %d\n", count );
2384 if (pGetCursorInfo)
2386 info.cbSize = sizeof(info);
2387 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2388 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2393 static void test_DestroyCursor(void)
2395 static const BYTE bmp_bits[4096];
2396 ICONINFO cursorInfo, new_info;
2397 HCURSOR cursor, cursor2, new_cursor;
2398 BOOL ret;
2399 DWORD error;
2400 UINT display_bpp;
2401 HDC hdc;
2403 hdc = GetDC(0);
2404 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2405 ReleaseDC(0, hdc);
2407 cursorInfo.fIcon = FALSE;
2408 cursorInfo.xHotspot = 0;
2409 cursorInfo.yHotspot = 0;
2410 cursorInfo.hbmMask = CreateBitmap(32, 32, 1, 1, bmp_bits);
2411 cursorInfo.hbmColor = CreateBitmap(32, 32, 1, display_bpp, bmp_bits);
2413 cursor = CreateIconIndirect(&cursorInfo);
2414 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2415 if(!cursor) {
2416 return;
2418 SetCursor(cursor);
2420 SetLastError(0xdeadbeef);
2421 ret = DestroyCursor(cursor);
2422 ok(!ret || broken(ret) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2423 error = GetLastError();
2424 ok(error == 0xdeadbeef, "Last error: %u\n", error);
2426 new_cursor = GetCursor();
2427 if (ret) /* win9x replaces cursor by another one on destroy */
2428 ok(new_cursor != cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2429 else
2430 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2432 SetLastError(0xdeadbeef);
2433 ret = GetIconInfo( cursor, &new_info );
2434 ok( !ret || broken(ret), /* nt4 */ "GetIconInfo succeeded\n" );
2435 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2436 broken(GetLastError() == 0xdeadbeef), /* win9x */
2437 "wrong error %u\n", GetLastError() );
2439 if (ret) /* nt4 delays destruction until cursor changes */
2441 DeleteObject( new_info.hbmColor );
2442 DeleteObject( new_info.hbmMask );
2444 SetLastError(0xdeadbeef);
2445 ret = DestroyCursor( cursor );
2446 ok( !ret, "DestroyCursor succeeded\n" );
2447 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2448 "wrong error %u\n", GetLastError() );
2450 SetLastError(0xdeadbeef);
2451 cursor2 = SetCursor( cursor );
2452 ok( cursor2 == cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2453 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2454 "wrong error %u\n", GetLastError() );
2456 else
2458 SetLastError(0xdeadbeef);
2459 cursor2 = CopyCursor( cursor );
2460 ok(!cursor2, "CopyCursor succeeded\n" );
2461 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE ||
2462 broken(GetLastError() == 0xdeadbeef), /* win9x */
2463 "wrong error %u\n", GetLastError() );
2465 SetLastError(0xdeadbeef);
2466 ret = DestroyCursor( cursor );
2467 if (new_cursor != cursor) /* win9x */
2468 ok( ret, "DestroyCursor succeeded\n" );
2469 else
2470 ok( !ret, "DestroyCursor succeeded\n" );
2471 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2472 "wrong error %u\n", GetLastError() );
2474 SetLastError(0xdeadbeef);
2475 cursor2 = SetCursor( cursor );
2476 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2477 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2478 "wrong error %u\n", GetLastError() );
2481 cursor2 = GetCursor();
2482 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2484 SetLastError(0xdeadbeef);
2485 cursor2 = SetCursor( 0 );
2486 if (new_cursor != cursor) /* win9x */
2487 ok(cursor2 == new_cursor, "SetCursor returned %p/%p\n", cursor2, cursor);
2488 else
2489 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2490 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2492 cursor2 = GetCursor();
2493 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2495 SetLastError(0xdeadbeef);
2496 ret = DestroyCursor(cursor);
2497 if (new_cursor != cursor) /* win9x */
2498 ok( ret, "DestroyCursor succeeded\n" );
2499 else
2500 ok( !ret, "DestroyCursor succeeded\n" );
2501 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2502 "wrong error %u\n", GetLastError() );
2504 DeleteObject(cursorInfo.hbmMask);
2505 DeleteObject(cursorInfo.hbmColor);
2507 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2508 cursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
2510 SetLastError(0xdeadbeef);
2511 ret = DestroyCursor(cursor);
2512 ok(ret || broken(!ret) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2513 error = GetLastError();
2514 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2516 /* Try setting the cursor to a destroyed OEM cursor. */
2517 SetLastError(0xdeadbeef);
2518 SetCursor(cursor);
2519 error = GetLastError();
2520 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2522 /* Check if LoadCursor() returns the same handle with the same icon. */
2523 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
2524 ok(cursor2 == cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2526 /* Check if LoadCursor() returns the same handle with a different icon. */
2527 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_WAIT);
2528 ok(cursor2 != cursor, "cursor == %p, cursor2 == %p\n", cursor, cursor2);
2531 static void test_PrivateExtractIcons(void)
2533 HICON icon;
2534 UINT ret;
2536 static const test_icon_entries_t icon_desc[] = {{0,0,TRUE}, {16,16,TRUE}, {32,32}, {64,64,TRUE}};
2538 create_ico_file("extract.ico", icon_desc, sizeof(icon_desc)/sizeof(*icon_desc));
2540 ret = PrivateExtractIconsA("extract.ico", 0, 32, 32, &icon, NULL, 1, 0);
2541 ok(ret == 1, "PrivateExtractIconsA returned %u\n", ret);
2542 ok(icon != NULL, "icon == NULL\n");
2544 test_icon_info(icon, 32, 32, 32, 32);
2545 DestroyIcon(icon);
2547 DeleteFileA("extract.ico");
2550 static void test_monochrome_icon(void)
2552 HANDLE handle;
2553 BOOL ret;
2554 DWORD bytes_written;
2555 CURSORICONFILEDIR *icon_data;
2556 CURSORICONFILEDIRENTRY *icon_entry;
2557 BITMAPINFO *bitmap_info;
2558 BITMAPCOREINFO *core_info;
2559 ICONINFO icon_info;
2560 ULONG icon_size;
2561 BOOL monochrome, use_core_info;
2563 icon_data = HeapAlloc(GetProcessHeap(), 0, sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) +
2564 2 * sizeof(RGBQUAD) + sizeof(ULONG));
2566 for (monochrome = FALSE; monochrome <= TRUE; monochrome++)
2567 for (use_core_info = FALSE; use_core_info <= TRUE; use_core_info++)
2569 trace("%s, %s\n",
2570 monochrome ? "monochrome" : "colored",
2571 use_core_info ? "core info" : "bitmap info");
2573 icon_size = sizeof(CURSORICONFILEDIR) +
2574 (use_core_info ? sizeof(BITMAPCOREHEADER) : sizeof(BITMAPINFOHEADER)) +
2575 /* 2 * sizeof(RGBTRIPLE) + padding comes out the same */
2576 2 * sizeof(RGBQUAD) +
2577 sizeof(ULONG);
2578 ZeroMemory(icon_data, icon_size);
2579 icon_data->idReserved = 0;
2580 icon_data->idType = 1;
2581 icon_data->idCount = 1;
2583 icon_entry = icon_data->idEntries;
2584 icon_entry->bWidth = 1;
2585 icon_entry->bHeight = 1;
2586 icon_entry->bColorCount = 0;
2587 icon_entry->bReserved = 0;
2588 icon_entry->xHotspot = 0;
2589 icon_entry->yHotspot = 0;
2590 icon_entry->dwDIBSize = icon_size - sizeof(CURSORICONFILEDIR);
2591 icon_entry->dwDIBOffset = sizeof(CURSORICONFILEDIR);
2593 if (use_core_info)
2595 core_info = (BITMAPCOREINFO *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
2596 core_info->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2597 core_info->bmciHeader.bcWidth = 1;
2598 core_info->bmciHeader.bcHeight = 2;
2599 core_info->bmciHeader.bcPlanes = 1;
2600 core_info->bmciHeader.bcBitCount = 1;
2601 core_info->bmciColors[0].rgbtBlue = monochrome ? 0x00 : 0xff;
2602 core_info->bmciColors[0].rgbtGreen = 0x00;
2603 core_info->bmciColors[0].rgbtRed = 0x00;
2604 core_info->bmciColors[1].rgbtBlue = 0xff;
2605 core_info->bmciColors[1].rgbtGreen = 0xff;
2606 core_info->bmciColors[1].rgbtRed = 0xff;
2608 else
2610 bitmap_info = (BITMAPINFO *) ((BYTE *) icon_data + icon_entry->dwDIBOffset);
2611 bitmap_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2612 bitmap_info->bmiHeader.biWidth = 1;
2613 bitmap_info->bmiHeader.biHeight = 2;
2614 bitmap_info->bmiHeader.biPlanes = 1;
2615 bitmap_info->bmiHeader.biBitCount = 1;
2616 bitmap_info->bmiHeader.biSizeImage = 0; /* Uncompressed bitmap. */
2617 bitmap_info->bmiColors[0].rgbBlue = monochrome ? 0x00 : 0xff;
2618 bitmap_info->bmiColors[0].rgbGreen = 0x00;
2619 bitmap_info->bmiColors[0].rgbRed = 0x00;
2620 bitmap_info->bmiColors[1].rgbBlue = 0xff;
2621 bitmap_info->bmiColors[1].rgbGreen = 0xff;
2622 bitmap_info->bmiColors[1].rgbRed = 0xff;
2625 handle = CreateFileA("icon.ico", GENERIC_WRITE, 0, NULL, CREATE_NEW,
2626 FILE_ATTRIBUTE_NORMAL, NULL);
2627 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError());
2628 ret = WriteFile(handle, icon_data, icon_size, &bytes_written, NULL);
2629 ok(ret && bytes_written == icon_size, "icon.ico created improperly.\n");
2630 CloseHandle(handle);
2632 handle = LoadImageA(NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
2633 ok(handle != NULL ||
2634 broken(use_core_info && handle == NULL), /* Win 8, 10 */
2635 "LoadImage() failed with %u.\n", GetLastError());
2636 if (handle == NULL)
2638 skip("Icon failed to load: %s, %s\n",
2639 monochrome ? "monochrome" : "colored",
2640 use_core_info ? "core info" : "bitmap info");
2641 DeleteFileA("icon.ico");
2642 continue;
2645 ret = GetIconInfo(handle, &icon_info);
2646 ok(ret, "GetIconInfo() failed with %u.\n", GetLastError());
2647 if (ret)
2649 ok(icon_info.fIcon == TRUE, "fIcon is %u.\n", icon_info.fIcon);
2650 ok(icon_info.xHotspot == 0, "xHotspot is %u.\n", icon_info.xHotspot);
2651 ok(icon_info.yHotspot == 0, "yHotspot is %u.\n", icon_info.yHotspot);
2652 if (monochrome)
2653 ok(icon_info.hbmColor == NULL, "Got hbmColor %p!\n", icon_info.hbmColor);
2654 else
2655 ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
2656 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
2659 ret = DestroyIcon(handle);
2660 ok(ret, "DestroyIcon() failed with %u.\n", GetLastError());
2661 DeleteFileA("icon.ico");
2664 HeapFree(GetProcessHeap(), 0, icon_data);
2667 START_TEST(cursoricon)
2669 pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2670 pGetIconInfoExA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2671 pGetIconInfoExW = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2672 pGetCursorFrameInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2673 test_argc = winetest_get_mainargs(&test_argv);
2675 if (test_argc >= 3)
2677 /* Child process. */
2678 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2680 ok(parent != NULL, "Parent not found.\n");
2681 if (parent == NULL)
2682 ExitProcess(1);
2684 do_child();
2685 return;
2688 test_CopyImage_Bitmap(1);
2689 test_CopyImage_Bitmap(4);
2690 test_CopyImage_Bitmap(8);
2691 test_CopyImage_Bitmap(16);
2692 test_CopyImage_Bitmap(24);
2693 test_CopyImage_Bitmap(32);
2694 test_initial_cursor();
2695 test_CreateIcon();
2696 test_LoadImage();
2697 test_CreateIconFromResource();
2698 test_GetCursorFrameInfo();
2699 test_DrawIcon();
2700 test_DrawIconEx();
2701 test_DrawState();
2702 test_SetCursor();
2703 test_ShowCursor();
2704 test_DestroyCursor();
2705 test_PrivateExtractIcons();
2706 test_monochrome_icon();
2707 do_parent();
2708 test_child_process();
2709 finish_child_process();