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
37 } CURSORICONFILEDIRENTRY
;
44 CURSORICONFILEDIRENTRY idEntries
[1];
47 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
48 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
49 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
51 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
52 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
53 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
54 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
55 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
56 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
57 #define ANI_icon_ID RIFF_FOURCC('i', 'c', 'o', 'n')
58 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
60 #define ANI_FLAG_ICON 0x1
61 #define ANI_FLAG_SEQUENCE 0x2
77 BYTE mask_data
[32*32/8];
81 CURSORICONFILEDIR icon_info
; /* animated cursor frame information */
82 BITMAPINFOHEADER bmi_header
; /* animated cursor frame header */
83 ani_data32x32x32 bmi_data
; /* animated cursor frame DIB data */
87 DWORD chunk_id
; /* ANI_anih_ID */
88 DWORD chunk_size
; /* actual size of data */
89 ani_header header
; /* animated cursor header */
93 DWORD chunk_id
; /* ANI_LIST_ID */
94 DWORD chunk_size
; /* actual size of data */
95 DWORD chunk_type
; /* ANI_fram_ID */
99 DWORD chunk_id
; /* ANI_icon_ID */
100 DWORD chunk_size
; /* actual size of data */
101 ani_frame32x32x32 data
; /* animated cursor frame */
102 } riff_icon32x32x32_t
;
105 DWORD chunk_id
; /* ANI_RIFF_ID */
106 DWORD chunk_size
; /* actual size of data */
107 DWORD chunk_type
; /* ANI_ACON_ID */
108 riff_header_t header
; /* RIFF animated cursor header */
109 riff_list_t frame_list
; /* RIFF animated cursor frame list info */
110 riff_icon32x32x32_t frames
[1]; /* array of animated cursor frames */
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
[3]; /* array of three animated cursor frames */
123 DWORD chunk_id
; /* ANI_rate_ID */
124 DWORD chunk_size
; /* actual size of data */
125 DWORD rate
[3]; /* animated cursor rate data */
129 DWORD chunk_id
; /* ANI_seq__ID */
130 DWORD chunk_size
; /* actual size of data */
131 DWORD order
[3]; /* animated cursor sequence data */
135 DWORD chunk_id
; /* ANI_RIFF_ID */
136 DWORD chunk_size
; /* actual size of data */
137 DWORD chunk_type
; /* ANI_ACON_ID */
138 riff_header_t header
; /* RIFF animated cursor header */
139 riff_seq3_t seq
; /* sequence data for three cursor frames */
140 riff_rate3_t rates
; /* rate data for three cursor frames */
141 riff_list_t frame_list
; /* RIFF animated cursor frame list info */
142 riff_icon32x32x32_t frames
[3]; /* array of three animated cursor frames */
143 } riff_cursor3_seq_t
;
145 #define EMPTY_ICON32 \
148 sizeof(ani_frame32x32x32), \
151 0x0, /* reserved */ \
152 0, /* type: icon(1), cursor(2) */ \
158 0, /* color count */ \
159 0x0, /* reserved */ \
160 16, /* x hotspot */ \
161 16, /* y hotspot */ \
162 sizeof(ani_data32x32x32), /* DIB size */ \
163 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
168 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
170 32*2, /* actual height times two */ \
173 BI_RGB, /* compression */ \
174 0, /* image size */ \
175 0, /* biXPelsPerMeter */ \
176 0, /* biYPelsPerMeter */ \
178 0 /* biClrImportant */ \
180 /* DIB data: left uninitialized */ \
184 riff_cursor1_t empty_anicursor
= {
186 sizeof(empty_anicursor
) - sizeof(DWORD
)*2,
199 10, /* display rate in jiffies */
200 ANI_FLAG_ICON
/* flags */
205 sizeof(riff_icon32x32x32_t
)*(1 /*frames*/) + sizeof(DWORD
),
213 riff_cursor3_t empty_anicursor3
= {
215 sizeof(empty_anicursor3
) - sizeof(DWORD
)*2,
228 0xbeef, /* display rate in jiffies */
229 ANI_FLAG_ICON
/* flags */
234 sizeof(riff_icon32x32x32_t
)*(3 /*frames*/) + sizeof(DWORD
),
244 riff_cursor3_seq_t empty_anicursor3_seq
= {
246 sizeof(empty_anicursor3_seq
) - sizeof(DWORD
)*2,
259 0xbeef, /* display rate in jiffies */
260 ANI_FLAG_ICON
|ANI_FLAG_SEQUENCE
/* flags */
265 sizeof(riff_seq3_t
) - sizeof(DWORD
)*2,
266 { 2, 0, 1} /* show frames in a uniquely identifiable order */
270 sizeof(riff_rate3_t
) - sizeof(DWORD
)*2,
271 { 0xc0de, 0xcafe, 0xbabe}
275 sizeof(riff_icon32x32x32_t
)*(3 /*frames*/) + sizeof(DWORD
),
287 static char **test_argv
;
288 static int test_argc
;
289 static HWND child
= 0;
290 static HWND parent
= 0;
291 static HANDLE child_process
;
293 #define PROC_INIT (WM_USER+1)
295 static BOOL (WINAPI
*pGetCursorInfo
)(CURSORINFO
*);
296 static BOOL (WINAPI
*pGetIconInfoExA
)(HICON
,ICONINFOEXA
*);
297 static BOOL (WINAPI
*pGetIconInfoExW
)(HICON
,ICONINFOEXW
*);
299 static const BOOL is_win64
= (sizeof(void *) > sizeof(int));
301 static LRESULT CALLBACK
callback_child(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
305 /* Destroy the cursor. */
308 HCURSOR cursor
= (HCURSOR
)lParam
;
313 memset(&info
, 0, sizeof(info
));
314 ret
= GetIconInfo(cursor
, &info
);
315 todo_wine
ok(ret
, "GetIconInfoEx failed with error %u\n", GetLastError());
316 todo_wine
ok(info
.hbmColor
!= NULL
, "info.hmbColor was not set\n");
317 todo_wine
ok(info
.hbmMask
!= NULL
, "info.hmbColor was not set\n");
318 DeleteObject(info
.hbmColor
);
319 DeleteObject(info
.hbmMask
);
321 SetLastError(0xdeadbeef);
322 ret
= DestroyCursor(cursor
);
323 error
= GetLastError();
324 ok(!ret
|| broken(ret
) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
325 ok(error
== ERROR_DESTROY_OBJECT_OF_OTHER_THREAD
||
326 error
== 0xdeadbeef, /* vista */
327 "Last error: %u\n", error
);
335 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
338 static LRESULT CALLBACK
callback_parent(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
340 if (msg
== PROC_INIT
)
342 child
= (HWND
) wParam
;
346 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
349 static void do_child(void)
355 /* Register a new class. */
356 class.style
= CS_GLOBALCLASS
;
357 class.lpfnWndProc
= callback_child
;
358 class.cbClsExtra
= 0;
359 class.cbWndExtra
= 0;
360 class.hInstance
= GetModuleHandleA(NULL
);
362 class.hCursor
= NULL
;
363 class.hbrBackground
= NULL
;
364 class.lpszMenuName
= NULL
;
365 class.lpszClassName
= "cursor_child";
367 SetLastError(0xdeadbeef);
368 ret
= RegisterClassA(&class);
369 ok(ret
, "Failed to register window class. Error: %u\n", GetLastError());
371 /* Create a window. */
372 child
= CreateWindowA("cursor_child", "cursor_child", WS_POPUP
| WS_VISIBLE
,
373 0, 0, 200, 200, 0, 0, 0, NULL
);
374 ok(child
!= 0, "CreateWindowA failed. Error: %u\n", GetLastError());
376 /* Let the parent know our HWND. */
377 PostMessageA(parent
, PROC_INIT
, (WPARAM
) child
, 0);
379 /* Receive messages. */
380 while ((ret
= GetMessageA(&msg
, 0, 0, 0)))
382 ok(ret
!= -1, "GetMessage failed. Error: %u\n", GetLastError());
383 TranslateMessage(&msg
);
384 DispatchMessageA(&msg
);
388 static void do_parent(void)
390 char path_name
[MAX_PATH
];
391 PROCESS_INFORMATION info
;
392 STARTUPINFOA startup
;
397 /* Register a new class. */
398 class.style
= CS_GLOBALCLASS
;
399 class.lpfnWndProc
= callback_parent
;
400 class.cbClsExtra
= 0;
401 class.cbWndExtra
= 0;
402 class.hInstance
= GetModuleHandleA(NULL
);
404 class.hCursor
= NULL
;
405 class.hbrBackground
= NULL
;
406 class.lpszMenuName
= NULL
;
407 class.lpszClassName
= "cursor_parent";
409 SetLastError(0xdeadbeef);
410 ret
= RegisterClassA(&class);
411 ok(ret
, "Failed to register window class. Error: %u\n", GetLastError());
413 /* Create a window. */
414 parent
= CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP
| WS_VISIBLE
,
415 0, 0, 200, 200, 0, 0, 0, NULL
);
416 ok(parent
!= 0, "CreateWindowA failed. Error: %u\n", GetLastError());
418 /* Start child process. */
419 memset(&startup
, 0, sizeof(startup
));
420 startup
.cb
= sizeof(startup
);
421 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
422 startup
.wShowWindow
= SW_SHOWNORMAL
;
424 sprintf(path_name
, "%s cursoricon %lx", test_argv
[0], (INT_PTR
)parent
);
425 ok(CreateProcessA(NULL
, path_name
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess failed.\n");
426 child_process
= info
.hProcess
;
428 /* Wait for child window handle. */
429 while ((child
== 0) && (ret
= GetMessageA(&msg
, parent
, 0, 0)))
431 ok(ret
!= -1, "GetMessage failed. Error: %u\n", GetLastError());
432 TranslateMessage(&msg
);
433 DispatchMessageA(&msg
);
437 static void finish_child_process(void)
439 SendMessageA(child
, WM_CLOSE
, 0, 0);
440 winetest_wait_child_process( child_process
);
441 CloseHandle(child_process
);
444 static void test_child_process(void)
446 static const BYTE bmp_bits
[4096];
452 /* Create and set a dummy cursor. */
454 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
457 cursorInfo
.fIcon
= FALSE
;
458 cursorInfo
.xHotspot
= 0;
459 cursorInfo
.yHotspot
= 0;
460 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
461 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
463 cursor
= CreateIconIndirect(&cursorInfo
);
464 ok(cursor
!= NULL
, "CreateIconIndirect returned %p.\n", cursor
);
468 /* Destroy the cursor. */
469 SendMessageA(child
, WM_USER
+1, 0, (LPARAM
) cursor
);
472 static BOOL
color_match(COLORREF a
, COLORREF b
)
474 /* 5-bit accuracy is a sufficient test. This will match as long as
475 * colors are never truncated to less that 3x5-bit accuracy i.e.
477 return (a
& 0x00F8F8F8) == (b
& 0x00F8F8F8);
480 static void test_CopyImage_Check(HBITMAP bitmap
, UINT flags
, INT copyWidth
, INT copyHeight
,
481 INT expectedWidth
, INT expectedHeight
, WORD expectedDepth
, BOOL dibExpected
)
489 copy
= CopyImage(bitmap
, IMAGE_BITMAP
, copyWidth
, copyHeight
, flags
);
490 ok(copy
!= NULL
, "CopyImage() failed\n");
493 GetObjectA(bitmap
, sizeof(origBitmap
), &origBitmap
);
494 GetObjectA(copy
, sizeof(copyBitmap
), ©Bitmap
);
495 orig_is_dib
= (origBitmap
.bmBits
!= NULL
);
496 copy_is_dib
= (copyBitmap
.bmBits
!= NULL
);
498 if (copy_is_dib
&& dibExpected
499 && copyBitmap
.bmBitsPixel
== 24
500 && (expectedDepth
== 16 || expectedDepth
== 32))
502 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
503 if (GetVersion() & 0x80000000)
509 if (copy_is_dib
&& !dibExpected
&& !(flags
& LR_CREATEDIBSECTION
))
511 /* It's not forbidden to create a DIB section if the flag
512 LR_CREATEDIBSECTION is absent.
513 Windows 9x does this if the bitmap has a depth that doesn't
514 match the screen depth, Windows NT doesn't */
516 expectedDepth
= origBitmap
.bmBitsPixel
;
519 ok((!(dibExpected
^ copy_is_dib
)
520 && (copyBitmap
.bmWidth
== expectedWidth
)
521 && (copyBitmap
.bmHeight
== expectedHeight
)
522 && (copyBitmap
.bmBitsPixel
== expectedDepth
)),
523 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
524 orig_is_dib
? "DIB" : "DDB", origBitmap
.bmWidth
, origBitmap
.bmHeight
, origBitmap
.bmBitsPixel
,
525 copyWidth
, copyHeight
, flags
,
526 dibExpected
? "DIB" : "DDB", expectedWidth
, expectedHeight
, expectedDepth
,
527 copy_is_dib
? "DIB" : "DDB", copyBitmap
.bmWidth
, copyBitmap
.bmHeight
, copyBitmap
.bmBitsPixel
);
533 static void test_CopyImage_Bitmap(int depth
)
542 /* Create a device-independent bitmap (DIB) */
543 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
544 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
545 info
->bmiHeader
.biWidth
= 2;
546 info
->bmiHeader
.biHeight
= 2;
547 info
->bmiHeader
.biPlanes
= 1;
548 info
->bmiHeader
.biBitCount
= depth
;
549 info
->bmiHeader
.biCompression
= BI_RGB
;
551 for (i
=0; i
< 256; i
++)
553 info
->bmiColors
[i
].rgbRed
= i
;
554 info
->bmiColors
[i
].rgbGreen
= i
;
555 info
->bmiColors
[i
].rgbBlue
= 255 - i
;
556 info
->bmiColors
[i
].rgbReserved
= 0;
559 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
561 /* Create a device-dependent bitmap (DDB) */
562 screenDC
= GetDC(NULL
);
563 screen_depth
= GetDeviceCaps(screenDC
, BITSPIXEL
);
564 if (depth
== 1 || depth
== screen_depth
)
566 ddb
= CreateBitmap(2, 2, 1, depth
, NULL
);
572 ReleaseDC(NULL
, screenDC
);
576 test_CopyImage_Check(ddb
, 0, 0, 0, 2, 2, depth
== 1 ? 1 : screen_depth
, FALSE
);
577 test_CopyImage_Check(ddb
, 0, 0, 5, 2, 5, depth
== 1 ? 1 : screen_depth
, FALSE
);
578 test_CopyImage_Check(ddb
, 0, 5, 0, 5, 2, depth
== 1 ? 1 : screen_depth
, FALSE
);
579 test_CopyImage_Check(ddb
, 0, 5, 5, 5, 5, depth
== 1 ? 1 : screen_depth
, FALSE
);
581 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 0, 0, 2, 2, 1, FALSE
);
582 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 5, 0, 5, 2, 1, FALSE
);
583 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 0, 5, 2, 5, 1, FALSE
);
584 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 5, 5, 5, 5, 1, FALSE
);
586 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
587 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
588 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
589 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
591 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
592 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
593 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
594 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
595 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
602 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, screen_depth
, FALSE
);
603 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, screen_depth
, FALSE
);
604 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, screen_depth
, FALSE
);
605 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, screen_depth
, FALSE
);
608 test_CopyImage_Check(dib
, LR_MONOCHROME
, 0, 0, 2, 2, 1, FALSE
);
609 test_CopyImage_Check(dib
, LR_MONOCHROME
, 5, 0, 5, 2, 1, FALSE
);
610 test_CopyImage_Check(dib
, LR_MONOCHROME
, 0, 5, 2, 5, 1, FALSE
);
611 test_CopyImage_Check(dib
, LR_MONOCHROME
, 5, 5, 5, 5, 1, FALSE
);
613 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
614 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
615 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
616 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
618 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
619 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
620 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
621 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
622 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
628 /* Special case: A monochrome DIB is converted to a monochrome DDB if
629 the colors in the color table are black and white.
631 Skip this test on Windows 95, it always creates a monochrome DDB
634 if (!(GetVersion() & 0x80000000))
636 info
->bmiHeader
.biBitCount
= 1;
637 info
->bmiColors
[0].rgbRed
= 0xFF;
638 info
->bmiColors
[0].rgbGreen
= 0;
639 info
->bmiColors
[0].rgbBlue
= 0;
640 info
->bmiColors
[1].rgbRed
= 0;
641 info
->bmiColors
[1].rgbGreen
= 0xFF;
642 info
->bmiColors
[1].rgbBlue
= 0;
644 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
645 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, screen_depth
, FALSE
);
646 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, screen_depth
, FALSE
);
647 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, screen_depth
, FALSE
);
648 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, screen_depth
, FALSE
);
651 info
->bmiHeader
.biBitCount
= 1;
652 info
->bmiColors
[0].rgbRed
= 0;
653 info
->bmiColors
[0].rgbGreen
= 0;
654 info
->bmiColors
[0].rgbBlue
= 0;
655 info
->bmiColors
[1].rgbRed
= 0xFF;
656 info
->bmiColors
[1].rgbGreen
= 0xFF;
657 info
->bmiColors
[1].rgbBlue
= 0xFF;
659 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
660 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, 1, FALSE
);
661 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, 1, FALSE
);
662 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, 1, FALSE
);
663 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, 1, FALSE
);
666 info
->bmiHeader
.biBitCount
= 1;
667 info
->bmiColors
[0].rgbRed
= 0xFF;
668 info
->bmiColors
[0].rgbGreen
= 0xFF;
669 info
->bmiColors
[0].rgbBlue
= 0xFF;
670 info
->bmiColors
[1].rgbRed
= 0;
671 info
->bmiColors
[1].rgbGreen
= 0;
672 info
->bmiColors
[1].rgbBlue
= 0;
674 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
675 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, 1, FALSE
);
676 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, 1, FALSE
);
677 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, 1, FALSE
);
678 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, 1, FALSE
);
683 HeapFree(GetProcessHeap(), 0, info
);
686 static void test_initial_cursor(void)
688 HCURSOR cursor
, cursor2
;
691 cursor
= GetCursor();
693 /* Check what handle GetCursor() returns if a cursor is not set yet. */
694 SetLastError(0xdeadbeef);
695 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_WAIT
);
697 ok(cursor
== cursor2
, "cursor (%p) is not IDC_WAIT (%p).\n", cursor
, cursor2
);
699 error
= GetLastError();
700 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
703 static void test_icon_info_dbg(HICON hIcon
, UINT exp_cx
, UINT exp_cy
, UINT exp_mask_cy
, UINT exp_bpp
, int line
)
707 BITMAP bmMask
, bmColor
;
709 ret
= GetIconInfo(hIcon
, &info
);
710 ok_(__FILE__
, line
)(ret
, "GetIconInfo failed\n");
712 /* CreateIcon under XP causes info.fIcon to be 0 */
713 ok_(__FILE__
, line
)(info
.xHotspot
== exp_cx
/2, "info.xHotspot = %u\n", info
.xHotspot
);
714 ok_(__FILE__
, line
)(info
.yHotspot
== exp_cy
/2, "info.yHotspot = %u\n", info
.yHotspot
);
715 ok_(__FILE__
, line
)(info
.hbmMask
!= 0, "info.hbmMask is NULL\n");
717 ret
= GetObjectA(info
.hbmMask
, sizeof(bmMask
), &bmMask
);
718 ok_(__FILE__
, line
)(ret
== sizeof(bmMask
), "GetObject(info.hbmMask) failed, ret %u\n", ret
);
721 ok_(__FILE__
, line
)(info
.hbmColor
== 0, "info.hbmColor should be NULL\n");
729 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
732 ret
= GetObjectA(info
.hbmColor
, sizeof(bmColor
), &bmColor
);
733 ok_(__FILE__
, line
)(ret
== sizeof(bmColor
), "GetObject(info.hbmColor) failed, ret %u\n", ret
);
735 ok_(__FILE__
, line
)(bmColor
.bmBitsPixel
== display_bpp
/* XP */ ||
736 bmColor
.bmBitsPixel
== exp_bpp
/* Win98 */,
737 "bmColor.bmBitsPixel = %d\n", bmColor
.bmBitsPixel
);
738 ok_(__FILE__
, line
)(bmColor
.bmWidth
== exp_cx
, "bmColor.bmWidth = %d\n", bmColor
.bmWidth
);
739 ok_(__FILE__
, line
)(bmColor
.bmHeight
== exp_cy
, "bmColor.bmHeight = %d\n", bmColor
.bmHeight
);
741 ok_(__FILE__
, line
)(bmMask
.bmBitsPixel
== 1, "bmMask.bmBitsPixel = %d\n", bmMask
.bmBitsPixel
);
742 ok_(__FILE__
, line
)(bmMask
.bmWidth
== exp_cx
, "bmMask.bmWidth = %d\n", bmMask
.bmWidth
);
743 ok_(__FILE__
, line
)(bmMask
.bmHeight
== exp_mask_cy
, "bmMask.bmHeight = %d\n", bmMask
.bmHeight
);
747 ok_(__FILE__
, line
)(bmMask
.bmBitsPixel
== 1, "bmMask.bmBitsPixel = %d\n", bmMask
.bmBitsPixel
);
748 ok_(__FILE__
, line
)(bmMask
.bmWidth
== exp_cx
, "bmMask.bmWidth = %d\n", bmMask
.bmWidth
);
749 ok_(__FILE__
, line
)(bmMask
.bmHeight
== exp_mask_cy
, "bmMask.bmHeight = %d\n", bmMask
.bmHeight
);
755 memset( &infoex
, 0xcc, sizeof(infoex
) );
756 SetLastError( 0xdeadbeef );
757 infoex
.cbSize
= sizeof(infoex
) - 1;
758 ret
= pGetIconInfoExA( hIcon
, &infoex
);
759 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
760 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %d\n", GetLastError());
762 SetLastError( 0xdeadbeef );
763 infoex
.cbSize
= sizeof(infoex
) + 1;
764 ret
= pGetIconInfoExA( hIcon
, &infoex
);
765 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
766 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %d\n", GetLastError());
768 SetLastError( 0xdeadbeef );
769 infoex
.cbSize
= sizeof(infoex
);
770 ret
= pGetIconInfoExA( (HICON
)0xdeadbabe, &infoex
);
771 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
772 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE
,
773 "wrong error %d\n", GetLastError());
775 infoex
.cbSize
= sizeof(infoex
);
776 ret
= pGetIconInfoExA( hIcon
, &infoex
);
777 ok_(__FILE__
, line
)(ret
, "GetIconInfoEx failed err %d\n", GetLastError());
778 ok_(__FILE__
, line
)(infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
779 ok_(__FILE__
, line
)(infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
780 ok_(__FILE__
, line
)(infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
784 #define test_icon_info(a,b,c,d,e) test_icon_info_dbg((a),(b),(c),(d),(e),__LINE__)
786 static void test_CreateIcon(void)
788 static const BYTE bmp_bits
[1024];
790 HBITMAP hbmMask
, hbmColor
;
799 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
801 /* these crash under XP
802 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
803 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
806 hIcon
= CreateIcon(0, 16, 16, 1, 1, bmp_bits
, bmp_bits
);
807 ok(hIcon
!= 0, "CreateIcon failed\n");
808 test_icon_info(hIcon
, 16, 16, 32, 1);
811 hIcon
= CreateIcon(0, 16, 16, 1, display_bpp
, bmp_bits
, bmp_bits
);
812 ok(hIcon
!= 0, "CreateIcon failed\n");
813 test_icon_info(hIcon
, 16, 16, 16, display_bpp
);
816 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
817 ok(hbmMask
!= 0, "CreateBitmap failed\n");
818 hbmColor
= CreateBitmap(16, 16, 1, display_bpp
, bmp_bits
);
819 ok(hbmColor
!= 0, "CreateBitmap failed\n");
826 SetLastError(0xdeadbeaf);
827 hIcon
= CreateIconIndirect(&info
);
828 ok(!hIcon
, "CreateIconIndirect should fail\n");
829 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
835 info
.hbmColor
= hbmColor
;
836 SetLastError(0xdeadbeaf);
837 hIcon
= CreateIconIndirect(&info
);
838 ok(!hIcon
, "CreateIconIndirect should fail\n");
839 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
844 info
.hbmMask
= hbmMask
;
845 info
.hbmColor
= hbmColor
;
846 hIcon
= CreateIconIndirect(&info
);
847 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
848 test_icon_info(hIcon
, 16, 16, 16, display_bpp
);
851 DeleteObject(hbmMask
);
852 DeleteObject(hbmColor
);
854 hbmMask
= CreateBitmap(16, 32, 1, 1, bmp_bits
);
855 ok(hbmMask
!= 0, "CreateBitmap failed\n");
860 info
.hbmMask
= hbmMask
;
862 SetLastError(0xdeadbeaf);
863 hIcon
= CreateIconIndirect(&info
);
864 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
865 test_icon_info(hIcon
, 16, 16, 32, 1);
867 DeleteObject(hbmMask
);
869 for (i
= 0; i
<= 4; i
++)
871 hbmMask
= CreateBitmap(1, i
, 1, 1, bmp_bits
);
872 ok(hbmMask
!= 0, "CreateBitmap failed\n");
877 info
.hbmMask
= hbmMask
;
879 SetLastError(0xdeadbeaf);
880 hIcon
= CreateIconIndirect(&info
);
881 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
882 test_icon_info(hIcon
, 1, i
/ 2, max(i
,1), 1);
884 DeleteObject(hbmMask
);
887 /* test creating an icon from a DIB section */
889 bmpinfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, FIELD_OFFSET(BITMAPINFO
,bmiColors
[256]));
890 bmpinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
891 bmpinfo
->bmiHeader
.biWidth
= 32;
892 bmpinfo
->bmiHeader
.biHeight
= 32;
893 bmpinfo
->bmiHeader
.biPlanes
= 1;
894 bmpinfo
->bmiHeader
.biBitCount
= 8;
895 bmpinfo
->bmiHeader
.biCompression
= BI_RGB
;
896 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
897 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
899 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
900 bmpinfo
->bmiHeader
.biBitCount
= 1;
901 hbmMask
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
902 ok(hbmMask
!= NULL
, "Expected a handle to the DIB\n");
904 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
909 info
.hbmMask
= hbmColor
;
910 info
.hbmColor
= hbmMask
;
911 SetLastError(0xdeadbeaf);
912 hIcon
= CreateIconIndirect(&info
);
913 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
914 test_icon_info(hIcon
, 32, 32, 32, 8);
916 DeleteObject(hbmColor
);
918 bmpinfo
->bmiHeader
.biBitCount
= 16;
919 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
920 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
922 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
927 info
.hbmMask
= hbmColor
;
928 info
.hbmColor
= hbmMask
;
929 SetLastError(0xdeadbeaf);
930 hIcon
= CreateIconIndirect(&info
);
931 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
932 test_icon_info(hIcon
, 32, 32, 32, 8);
934 DeleteObject(hbmColor
);
936 bmpinfo
->bmiHeader
.biBitCount
= 32;
937 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
938 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
940 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
945 info
.hbmMask
= hbmColor
;
946 info
.hbmColor
= hbmMask
;
947 SetLastError(0xdeadbeaf);
948 hIcon
= CreateIconIndirect(&info
);
949 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
950 test_icon_info(hIcon
, 32, 32, 32, 8);
953 DeleteObject(hbmMask
);
954 DeleteObject(hbmColor
);
955 HeapFree( GetProcessHeap(), 0, bmpinfo
);
960 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
962 static const unsigned char gifimage
[35] = {
963 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
964 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
969 static const unsigned char jpgimage
[285] = {
970 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
971 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
972 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
973 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
974 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
975 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
976 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
977 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
978 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
979 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
980 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
981 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
982 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
983 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
984 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
985 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
986 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
987 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
991 static const unsigned char pngimage
[285] = {
992 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
993 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
994 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
995 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
996 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
997 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
998 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1001 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
1002 zeroes, gap is 0xFF. */
1003 static unsigned char bmpimage
[70] = {
1004 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
1005 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1006 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1007 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
1008 0xFF,0xFF,0x00,0x00,0x00,0x00
1011 /* 1x1 pixel bmp using BITMAPCOREHEADER */
1012 static const unsigned char bmpcoreimage
[38] = {
1013 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
1014 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
1015 0x55,0x00,0x00,0x00,0x00,0x00
1019 static const unsigned char gif4pixel
[42] = {
1020 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1021 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1022 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1025 static const DWORD biSize_tests
[] = {
1027 sizeof(BITMAPCOREHEADER
) - 1,
1028 sizeof(BITMAPCOREHEADER
) + 1,
1029 sizeof(BITMAPINFOHEADER
) - 1,
1030 sizeof(BITMAPINFOHEADER
) + 1,
1031 sizeof(BITMAPV4HEADER
) - 1,
1032 sizeof(BITMAPV4HEADER
) + 1,
1033 sizeof(BITMAPV5HEADER
) - 1,
1034 sizeof(BITMAPV5HEADER
) + 1,
1035 (sizeof(BITMAPCOREHEADER
) + sizeof(BITMAPINFOHEADER
)) / 2,
1036 (sizeof(BITMAPV4HEADER
) + sizeof(BITMAPV5HEADER
)) / 2,
1041 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1043 static void test_LoadImageBitmap(const char * test_desc
, HBITMAP hbm
)
1047 DWORD ret
, pixel
= 0;
1048 HDC hdc
= GetDC(NULL
);
1050 ret
= GetObjectA(hbm
, sizeof(bm
), &bm
);
1051 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
1053 memset(&bmi
, 0, sizeof(bmi
));
1054 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
1055 bmi
.bmiHeader
.biWidth
= bm
.bmWidth
;
1056 bmi
.bmiHeader
.biHeight
= bm
.bmHeight
;
1057 bmi
.bmiHeader
.biPlanes
= 1;
1058 bmi
.bmiHeader
.biBitCount
= 24;
1059 bmi
.bmiHeader
.biCompression
= BI_RGB
;
1060 ret
= GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, &pixel
, &bmi
, DIB_RGB_COLORS
);
1061 ok(ret
== bm
.bmHeight
, "%s: %d lines were converted, not %d\n", test_desc
, ret
, bm
.bmHeight
);
1063 ok(color_match(pixel
, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc
, pixel
);
1066 static void test_LoadImageFile(const char * test_desc
, const unsigned char * image_data
,
1067 unsigned int image_size
, const char * ext
, BOOL expect_success
)
1071 DWORD error
, bytes_written
;
1074 strcpy(filename
, "test.");
1075 strcat(filename
, ext
);
1077 /* Create the test image. */
1078 handle
= CreateFileA(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_NEW
,
1079 FILE_ATTRIBUTE_NORMAL
, NULL
);
1080 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileA failed. %u\n", GetLastError());
1081 ret
= WriteFile(handle
, image_data
, image_size
, &bytes_written
, NULL
);
1082 ok(ret
&& bytes_written
== image_size
, "test file created improperly.\n");
1083 CloseHandle(handle
);
1085 /* Load as cursor. For all tested formats, this should fail */
1086 SetLastError(0xdeadbeef);
1087 handle
= LoadImageA(NULL
, filename
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
1088 ok(handle
== NULL
, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc
);
1089 error
= GetLastError();
1091 broken(error
== 0xdeadbeef) || /* Win9x */
1092 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1093 "Last error: %u\n", error
);
1094 if (handle
!= NULL
) DestroyCursor(handle
);
1096 /* Load as icon. For all tested formats, this should fail */
1097 SetLastError(0xdeadbeef);
1098 handle
= LoadImageA(NULL
, filename
, IMAGE_ICON
, 0, 0, LR_LOADFROMFILE
);
1099 ok(handle
== NULL
, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc
);
1100 error
= GetLastError();
1102 broken(error
== 0xdeadbeef) || /* Win9x */
1103 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1104 "Last error: %u\n", error
);
1105 if (handle
!= NULL
) DestroyIcon(handle
);
1107 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1108 SetLastError(0xdeadbeef);
1109 handle
= LoadImageA(NULL
, filename
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
1110 error
= GetLastError();
1112 error
== 0xdeadbeef, /* Win9x, WinMe */
1113 "Last error: %u\n", error
);
1115 if (expect_success
) {
1116 ok(handle
!= NULL
, "%s: IMAGE_BITMAP failed.\n", test_desc
);
1117 if (handle
!= NULL
) test_LoadImageBitmap(test_desc
, handle
);
1119 else ok(handle
== NULL
, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc
);
1121 if (handle
!= NULL
) DeleteObject(handle
);
1122 DeleteFileA(filename
);
1128 BOOL invalid_offset
;
1129 } test_icon_entries_t
;
1131 static void create_ico_file(const char *filename
, const test_icon_entries_t
*test_icon_entries
, unsigned entry_cnt
)
1133 CURSORICONFILEDIRENTRY
*icon_entry
;
1134 BITMAPINFOHEADER
*icon_header
;
1135 CURSORICONFILEDIR
*dir
;
1136 BYTE
*buf
, *bitmap_ptr
;
1137 DWORD bytes_written
;
1143 const unsigned icon_bpp
= 32;
1145 icon_size
= FIELD_OFFSET(CURSORICONFILEDIR
, idEntries
[entry_cnt
]) + sizeof(BITMAPINFOHEADER
)*entry_cnt
;
1146 for(i
=0; i
<entry_cnt
; i
++)
1147 icon_size
+= icon_bpp
* test_icon_entries
[i
].width
* test_icon_entries
[i
].height
/ 8;
1149 buf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, icon_size
);
1150 dir
= (CURSORICONFILEDIR
*)buf
;
1152 dir
->idReserved
= 0;
1154 dir
->idCount
= entry_cnt
;
1156 bitmap_ptr
= buf
+ FIELD_OFFSET(CURSORICONFILEDIR
, idEntries
[entry_cnt
]);
1157 for(i
=0; i
<entry_cnt
; i
++) {
1158 icon_entry
= dir
->idEntries
+i
;
1159 icon_entry
->bWidth
= test_icon_entries
[i
].width
;
1160 icon_entry
->bHeight
= test_icon_entries
[i
].height
;
1161 icon_entry
->bColorCount
= 0;
1162 icon_entry
->bReserved
= 0;
1163 icon_entry
->xHotspot
= 1;
1164 icon_entry
->yHotspot
= 1;
1165 icon_entry
->dwDIBSize
= sizeof(BITMAPINFOHEADER
) + icon_entry
->bWidth
* icon_entry
->bHeight
* icon_bpp
/ 8;
1166 icon_entry
->dwDIBOffset
= test_icon_entries
[i
].invalid_offset
? 0xffffffff : bitmap_ptr
- buf
;
1168 icon_header
= (BITMAPINFOHEADER
*)bitmap_ptr
;
1169 bitmap_ptr
+= icon_entry
->dwDIBSize
;
1171 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1172 icon_header
->biWidth
= icon_entry
->bWidth
;
1173 icon_header
->biHeight
= icon_entry
->bHeight
;
1174 icon_header
->biPlanes
= 1;
1175 icon_header
->biBitCount
= icon_bpp
;
1176 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1179 memset(bitmap_ptr
, 0xf0, buf
+icon_size
-bitmap_ptr
);
1181 /* Create the icon. */
1182 file
= CreateFileA(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1183 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed. %u\n", GetLastError());
1184 ret
= WriteFile(file
, buf
, icon_size
, &bytes_written
, NULL
);
1185 ok(ret
&& bytes_written
== icon_size
, "icon.ico created improperly.\n");
1188 HeapFree(GetProcessHeap(), 0, buf
);
1191 static void test_LoadImage(void)
1196 BITMAPINFOHEADER
*bitmap_header
;
1200 #define ICON_WIDTH 32
1201 #define ICON_HEIGHT 32
1202 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1205 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1206 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1208 static const test_icon_entries_t icon_desc
= {32, 32};
1210 create_ico_file("icon.ico", &icon_desc
, 1);
1212 /* Test loading an icon as a cursor. */
1213 SetLastError(0xdeadbeef);
1214 handle
= LoadImageA(NULL
, "icon.ico", IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
1215 ok(handle
!= NULL
, "LoadImage() failed.\n");
1216 error
= GetLastError();
1218 broken(error
== 0xdeadbeef) || /* Win9x */
1219 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1220 "Last error: %u\n", error
);
1222 /* Test the icon information. */
1223 SetLastError(0xdeadbeef);
1224 ret
= GetIconInfo(handle
, &icon_info
);
1225 ok(ret
, "GetIconInfo() failed.\n");
1226 error
= GetLastError();
1227 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1231 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1232 ok(icon_info
.xHotspot
== 1, "xHotspot is %u.\n", icon_info
.xHotspot
);
1233 ok(icon_info
.yHotspot
== 1, "yHotspot is %u.\n", icon_info
.yHotspot
);
1234 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1236 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1239 if (pGetIconInfoExA
)
1242 infoex
.cbSize
= sizeof(infoex
);
1243 ret
= pGetIconInfoExA( handle
, &infoex
);
1244 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1245 ok( infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
1246 ok( infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
1247 ok( infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
1249 else win_skip( "GetIconInfoEx not available\n" );
1252 SetLastError(0xdeadbeef);
1253 ret
= DestroyCursor(handle
);
1254 ok(ret
, "DestroyCursor() failed.\n");
1255 error
= GetLastError();
1256 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1258 DeleteFileA("icon.ico");
1260 /* Test a system icon */
1261 handle
= LoadIconA( 0, (LPCSTR
)IDI_HAND
);
1262 ok(handle
!= NULL
, "LoadImage() failed.\n");
1263 if (pGetIconInfoExA
)
1265 ICONINFOEXA infoexA
;
1266 ICONINFOEXW infoexW
;
1267 infoexA
.cbSize
= sizeof(infoexA
);
1268 ret
= pGetIconInfoExA( handle
, &infoexA
);
1269 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1270 ok( infoexA
.wResID
== (UINT_PTR
)IDI_HAND
, "GetIconInfoEx wrong resid %x\n", infoexA
.wResID
);
1271 /* the A version is broken on 64-bit, it truncates the string after the first char */
1272 if (is_win64
&& infoexA
.szModName
[0] && infoexA
.szModName
[1] == 0)
1273 trace( "GetIconInfoExA broken on Win64\n" );
1275 ok( GetModuleHandleA(infoexA
.szModName
) == GetModuleHandleA("user32.dll"),
1276 "GetIconInfoEx wrong module %s\n", infoexA
.szModName
);
1277 ok( infoexA
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA
.szResName
);
1278 infoexW
.cbSize
= sizeof(infoexW
);
1279 ret
= pGetIconInfoExW( handle
, &infoexW
);
1280 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1281 ok( infoexW
.wResID
== (UINT_PTR
)IDI_HAND
, "GetIconInfoEx wrong resid %x\n", infoexW
.wResID
);
1282 ok( GetModuleHandleW(infoexW
.szModName
) == GetModuleHandleA("user32.dll"),
1283 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW
.szModName
) );
1284 ok( infoexW
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW
.szResName
) );
1286 SetLastError(0xdeadbeef);
1287 DestroyIcon(handle
);
1289 test_LoadImageFile("BMP", bmpimage
, sizeof(bmpimage
), "bmp", 1);
1290 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage
, sizeof(bmpcoreimage
), "bmp", 1);
1291 test_LoadImageFile("GIF", gifimage
, sizeof(gifimage
), "gif", 0);
1292 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel
, sizeof(gif4pixel
), "gif", 0);
1293 test_LoadImageFile("JPG", jpgimage
, sizeof(jpgimage
), "jpg", 0);
1294 test_LoadImageFile("PNG", pngimage
, sizeof(pngimage
), "png", 0);
1296 /* Check failure for broken BMP images */
1297 bitmap_header
= (BITMAPINFOHEADER
*)(bmpimage
+ sizeof(BITMAPFILEHEADER
));
1299 bitmap_header
->biHeight
= 65536;
1300 test_LoadImageFile("BMP (too high)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1301 bitmap_header
->biHeight
= 1;
1303 bitmap_header
->biWidth
= 65536;
1304 test_LoadImageFile("BMP (too wide)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1305 bitmap_header
->biWidth
= 1;
1307 for (i
= 0; i
< ARRAY_SIZE(biSize_tests
); i
++) {
1308 bitmap_header
->biSize
= biSize_tests
[i
];
1309 test_LoadImageFile("BMP (broken biSize)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1311 bitmap_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1316 static void test_CreateIconFromResource(void)
1321 BITMAPINFOHEADER
*icon_header
;
1325 #define ICON_RES_WIDTH 32
1326 #define ICON_RES_HEIGHT 32
1327 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1328 #define ICON_RES_BPP 32
1329 #define ICON_RES_SIZE \
1330 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1331 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1333 /* Set icon data. */
1334 hotspot
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, CRSR_RES_SIZE
);
1336 /* Cursor resources have an extra hotspot, icon resources not. */
1340 icon_header
= (BITMAPINFOHEADER
*) (hotspot
+ 2);
1341 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1342 icon_header
->biWidth
= ICON_WIDTH
;
1343 icon_header
->biHeight
= ICON_HEIGHT
*2;
1344 icon_header
->biPlanes
= 1;
1345 icon_header
->biBitCount
= ICON_BPP
;
1346 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1348 /* Test creating a cursor. */
1349 SetLastError(0xdeadbeef);
1350 handle
= CreateIconFromResource((PBYTE
) hotspot
, CRSR_RES_SIZE
, FALSE
, 0x00030000);
1351 ok(handle
!= NULL
, "Create cursor failed.\n");
1353 /* Test the icon information. */
1354 SetLastError(0xdeadbeef);
1355 ret
= GetIconInfo(handle
, &icon_info
);
1356 ok(ret
, "GetIconInfo() failed.\n");
1357 error
= GetLastError();
1358 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1362 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1363 ok(icon_info
.xHotspot
== 3, "xHotspot is %u.\n", icon_info
.xHotspot
);
1364 ok(icon_info
.yHotspot
== 3, "yHotspot is %u.\n", icon_info
.yHotspot
);
1365 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1367 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1370 if (pGetIconInfoExA
)
1373 infoex
.cbSize
= sizeof(infoex
);
1374 ret
= pGetIconInfoExA( handle
, &infoex
);
1375 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1376 ok( infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
1377 ok( infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
1378 ok( infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
1382 SetLastError(0xdeadbeef);
1383 ret
= DestroyCursor(handle
);
1384 ok(ret
, "DestroyCursor() failed.\n");
1385 error
= GetLastError();
1386 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1388 /* Test creating an icon. */
1389 SetLastError(0xdeadbeef);
1390 handle
= CreateIconFromResource((PBYTE
) icon_header
, ICON_RES_SIZE
, TRUE
,
1392 ok(handle
!= NULL
, "Create icon failed.\n");
1394 /* Test the icon information. */
1395 SetLastError(0xdeadbeef);
1396 ret
= GetIconInfo(handle
, &icon_info
);
1397 ok(ret
, "GetIconInfo() failed.\n");
1398 error
= GetLastError();
1399 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1403 ok(icon_info
.fIcon
== TRUE
, "fIcon != TRUE.\n");
1404 /* Icons always have hotspot in the middle */
1405 ok(icon_info
.xHotspot
== ICON_WIDTH
/2, "xHotspot is %u.\n", icon_info
.xHotspot
);
1406 ok(icon_info
.yHotspot
== ICON_HEIGHT
/2, "yHotspot is %u.\n", icon_info
.yHotspot
);
1407 ok(icon_info
.hbmColor
!= NULL
, "No hbmColor!\n");
1408 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1412 SetLastError(0xdeadbeef);
1413 ret
= DestroyCursor(handle
);
1414 ok(ret
, "DestroyCursor() failed.\n");
1415 error
= GetLastError();
1416 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1418 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1420 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1421 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1423 HeapFree(GetProcessHeap(), 0, hotspot
);
1425 /* Test creating an animated cursor. */
1426 empty_anicursor
.frames
[0].data
.icon_info
.idType
= 2; /* type: cursor */
1427 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1428 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1429 handle
= CreateIconFromResource((PBYTE
) &empty_anicursor
, sizeof(empty_anicursor
), FALSE
, 0x00030000);
1430 ok(handle
!= NULL
, "Create cursor failed.\n");
1432 /* Test the animated cursor's information. */
1433 SetLastError(0xdeadbeef);
1434 ret
= GetIconInfo(handle
, &icon_info
);
1435 ok(ret
, "GetIconInfo() failed.\n");
1436 error
= GetLastError();
1437 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1441 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1442 ok(icon_info
.xHotspot
== 3, "xHotspot is %u.\n", icon_info
.xHotspot
);
1443 ok(icon_info
.yHotspot
== 3, "yHotspot is %u.\n", icon_info
.yHotspot
);
1444 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1446 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1450 SetLastError(0xdeadbeef);
1451 ret
= DestroyCursor(handle
);
1452 ok(ret
, "DestroyCursor() failed.\n");
1453 error
= GetLastError();
1454 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1457 static int check_cursor_data( HDC hdc
, HCURSOR hCursor
, void *data
, int length
)
1465 ret
= GetIconInfo( hCursor
, &iinfo
);
1466 ok(ret
, "GetIconInfo() failed\n");
1469 info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] ));
1470 ok(info
!= NULL
, "HeapAlloc() failed\n");
1471 if (!info
) return 0;
1473 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1474 info
->bmiHeader
.biWidth
= 32;
1475 info
->bmiHeader
.biHeight
= 32;
1476 info
->bmiHeader
.biPlanes
= 1;
1477 info
->bmiHeader
.biBitCount
= 32;
1478 info
->bmiHeader
.biCompression
= BI_RGB
;
1479 info
->bmiHeader
.biSizeImage
= 32 * 32 * 4;
1480 info
->bmiHeader
.biXPelsPerMeter
= 0;
1481 info
->bmiHeader
.biYPelsPerMeter
= 0;
1482 info
->bmiHeader
.biClrUsed
= 0;
1483 info
->bmiHeader
.biClrImportant
= 0;
1484 image
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
);
1485 ok(image
!= NULL
, "HeapAlloc() failed\n");
1486 if (!image
) goto cleanup
;
1487 ret
= GetDIBits( hdc
, iinfo
.hbmColor
, 0, 32, image
, info
, DIB_RGB_COLORS
);
1488 ok(ret
, "GetDIBits() failed\n");
1489 for (i
= 0; ret
&& i
< length
/ sizeof(COLORREF
); i
++)
1491 ret
= color_match( ((COLORREF
*)data
)[i
], ((COLORREF
*)image
)[i
] );
1492 ok(ret
, "%04x: Expected 0x%x, actually 0x%x\n", i
, ((COLORREF
*)data
)[i
], ((COLORREF
*)image
)[i
] );
1495 HeapFree( GetProcessHeap(), 0, image
);
1496 HeapFree( GetProcessHeap(), 0, info
);
1500 static HCURSOR (WINAPI
*pGetCursorFrameInfo
)(HCURSOR hCursor
, DWORD unk1
, DWORD istep
, DWORD
*rate
, DWORD
*steps
);
1501 static void test_GetCursorFrameInfo(void)
1503 DWORD frame_identifier
[] = { 0x10Ad, 0xc001, 0x1c05 };
1504 HBITMAP bmp
= NULL
, bmpOld
= NULL
;
1506 BITMAPINFOHEADER
*icon_header
;
1507 BITMAPINFO bitmapInfo
;
1515 if (!pGetCursorFrameInfo
)
1517 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1521 hdc
= CreateCompatibleDC(0);
1522 ok(hdc
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1526 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1527 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1528 bitmapInfo
.bmiHeader
.biWidth
= 3;
1529 bitmapInfo
.bmiHeader
.biHeight
= 3;
1530 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1531 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1532 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1533 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1534 bmp
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1535 ok (bmp
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1538 bmpOld
= SelectObject(hdc
, bmp
);
1540 #define ICON_RES_WIDTH 32
1541 #define ICON_RES_HEIGHT 32
1542 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1543 #define ICON_RES_BPP 32
1544 #define ICON_RES_SIZE \
1545 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1546 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1548 /* Set icon data. */
1549 hotspot
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, CRSR_RES_SIZE
);
1551 /* Cursor resources have an extra hotspot, icon resources not. */
1555 icon_header
= (BITMAPINFOHEADER
*) (hotspot
+ 2);
1556 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1557 icon_header
->biWidth
= ICON_WIDTH
;
1558 icon_header
->biHeight
= ICON_HEIGHT
*2;
1559 icon_header
->biPlanes
= 1;
1560 icon_header
->biBitCount
= ICON_BPP
;
1561 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1563 /* Creating a static cursor. */
1564 SetLastError(0xdeadbeef);
1565 h1
= CreateIconFromResource((PBYTE
) hotspot
, CRSR_RES_SIZE
, FALSE
, 0x00030000);
1566 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1568 /* Check GetCursorFrameInfo behavior on a static cursor */
1569 rate
= steps
= 0xdead;
1570 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0xdead, &rate
, &steps
);
1571 ok(h1
== h2
, "GetCursorFrameInfo() failed: (%p != %p).\n", h1
, h2
);
1572 ok(rate
== 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate
);
1573 ok(steps
== 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps
);
1575 /* Clean up static cursor. */
1576 SetLastError(0xdeadbeef);
1577 ret
= DestroyCursor(h1
);
1578 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1580 /* Creating a single-frame animated cursor. */
1581 empty_anicursor
.frames
[0].data
.icon_info
.idType
= 2; /* type: cursor */
1582 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1583 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1584 memcpy( &empty_anicursor
.frames
[0].data
.bmi_data
.data
[0], &frame_identifier
[0], sizeof(DWORD
) );
1585 SetLastError(0xdeadbeef);
1586 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor
, sizeof(empty_anicursor
), FALSE
, 0x00030000);
1587 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1589 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1590 rate
= steps
= 0xdead;
1591 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0, &rate
, &steps
);
1592 ok(h1
== h2
, "GetCursorFrameInfo() failed: (%p != %p).\n", h1
, h2
);
1593 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[0], sizeof(DWORD
) );
1594 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1595 ok(rate
== 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate
);
1596 ok(steps
== empty_anicursor
.header
.header
.num_steps
,
1597 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps
);
1599 /* Clean up single-frame animated cursor. */
1600 SetLastError(0xdeadbeef);
1601 ret
= DestroyCursor(h1
);
1602 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1604 /* Creating a multi-frame animated cursor. */
1605 for (i
=0; i
<empty_anicursor3
.header
.header
.num_frames
; i
++)
1607 empty_anicursor3
.frames
[i
].data
.icon_info
.idType
= 2; /* type: cursor */
1608 empty_anicursor3
.frames
[i
].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1609 empty_anicursor3
.frames
[i
].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1610 memcpy( &empty_anicursor3
.frames
[i
].data
.bmi_data
.data
[0], &frame_identifier
[i
], sizeof(DWORD
) );
1612 SetLastError(0xdeadbeef);
1613 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3
, sizeof(empty_anicursor3
), FALSE
, 0x00030000);
1614 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1616 /* Check number of steps in multi-frame animated cursor */
1618 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1620 ok(i
== empty_anicursor3
.header
.header
.num_steps
,
1621 "Unexpected number of steps in cursor (%d != %d)\n",
1622 i
, empty_anicursor3
.header
.header
.num_steps
);
1624 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1625 for (i
=0; i
<empty_anicursor3
.header
.header
.num_frames
; i
++)
1627 rate
= steps
= 0xdead;
1628 h2
= pGetCursorFrameInfo(h1
, 0xdead, i
, &rate
, &steps
);
1629 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1630 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[i
], sizeof(DWORD
) );
1631 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i
);
1632 ok(rate
== empty_anicursor3
.header
.header
.display_rate
,
1633 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1634 rate
, empty_anicursor3
.header
.header
.display_rate
);
1635 ok(steps
== empty_anicursor3
.header
.header
.num_steps
,
1636 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1637 steps
, empty_anicursor3
.header
.header
.num_steps
);
1640 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1641 rate
= steps
= 0xdead;
1642 h2
= pGetCursorFrameInfo(h1
, 0xdead, 3, &rate
, &steps
);
1643 ok(h2
== 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1
, h2
);
1644 ok(rate
== 0xdead || broken(rate
== empty_anicursor3
.header
.header
.display_rate
) /*win2k*/
1645 || broken(rate
== ~0) /*win2k (sporadic)*/,
1646 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate
);
1647 ok(steps
== 0xdead || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/
1648 || broken(steps
== 0) /*win2k (sporadic)*/,
1649 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps
);
1651 /* Clean up multi-frame animated cursor. */
1652 SetLastError(0xdeadbeef);
1653 ret
= DestroyCursor(h1
);
1654 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1656 /* Create a multi-frame animated cursor with num_steps == 1 */
1657 empty_anicursor3
.header
.header
.num_steps
= 1;
1658 SetLastError(0xdeadbeef);
1659 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3
, sizeof(empty_anicursor3
), FALSE
, 0x00030000);
1660 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1662 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1664 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1666 ok(i
== empty_anicursor3
.header
.header
.num_steps
,
1667 "Unexpected number of steps in cursor (%d != %d)\n",
1668 i
, empty_anicursor3
.header
.header
.num_steps
);
1670 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1671 rate
= steps
= 0xdead;
1672 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0, &rate
, &steps
);
1673 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1674 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[0], sizeof(DWORD
) );
1675 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1676 ok(rate
== empty_anicursor3
.header
.header
.display_rate
,
1677 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1678 rate
, empty_anicursor3
.header
.header
.display_rate
);
1679 ok(steps
== ~0 || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/,
1680 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps
);
1682 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1683 rate
= steps
= 0xdead;
1684 h2
= pGetCursorFrameInfo(h1
, 0xdead, 1, &rate
, &steps
);
1685 ok(h2
== 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1
, h2
);
1686 ok(rate
== 0xdead || broken(rate
== empty_anicursor3
.header
.header
.display_rate
) /*win2k*/
1687 || broken(rate
== ~0) /*win2k (sporadic)*/,
1688 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate
);
1689 ok(steps
== 0xdead || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/
1690 || broken(steps
== 0) /*win2k (sporadic)*/,
1691 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps
);
1693 /* Clean up multi-frame animated cursor. */
1694 SetLastError(0xdeadbeef);
1695 ret
= DestroyCursor(h1
);
1696 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1698 /* Creating a multi-frame animated cursor with rate data. */
1699 for (i
=0; i
<empty_anicursor3_seq
.header
.header
.num_frames
; i
++)
1701 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idType
= 2; /* type: cursor */
1702 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1703 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1704 memcpy( &empty_anicursor3_seq
.frames
[i
].data
.bmi_data
.data
[0], &frame_identifier
[i
], sizeof(DWORD
) );
1706 SetLastError(0xdeadbeef);
1707 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3_seq
, sizeof(empty_anicursor3_seq
), FALSE
, 0x00030000);
1708 ok(h1
!= NULL
, "Create cursor failed (error = %x).\n", GetLastError());
1710 /* Check number of steps in multi-frame animated cursor with rate data */
1712 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1714 ok(i
== empty_anicursor3_seq
.header
.header
.num_steps
,
1715 "Unexpected number of steps in cursor (%d != %d)\n",
1716 i
, empty_anicursor3_seq
.header
.header
.num_steps
);
1718 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1719 for (i
=0; i
<empty_anicursor3_seq
.header
.header
.num_frames
; i
++)
1721 int frame_id
= empty_anicursor3_seq
.seq
.order
[i
];
1723 rate
= steps
= 0xdead;
1724 h2
= pGetCursorFrameInfo(h1
, 0xdead, i
, &rate
, &steps
);
1725 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1726 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[frame_id
], sizeof(DWORD
) );
1727 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i
);
1728 ok(rate
== empty_anicursor3_seq
.rates
.rate
[i
],
1729 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1730 rate
, empty_anicursor3_seq
.rates
.rate
[i
]);
1731 ok(steps
== empty_anicursor3_seq
.header
.header
.num_steps
,
1732 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1733 steps
, empty_anicursor3_seq
.header
.header
.num_steps
);
1736 /* Clean up multi-frame animated cursor with rate data. */
1737 SetLastError(0xdeadbeef);
1738 ret
= DestroyCursor(h1
);
1739 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1741 HeapFree(GetProcessHeap(), 0, hotspot
);
1743 if(bmpOld
) SelectObject(hdc
, bmpOld
);
1744 if(bmp
) DeleteObject(bmp
);
1745 if(hdc
) DeleteDC(hdc
);
1748 static HICON
create_test_icon(HDC hdc
, int width
, int height
, int bpp
,
1749 BOOL maskvalue
, UINT32
*color
, int colorSize
)
1752 BITMAPINFO bitmapInfo
;
1753 void *buffer
= NULL
;
1754 UINT32 mask
= maskvalue
? 0xFFFFFFFF : 0x00000000;
1756 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1757 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1758 bitmapInfo
.bmiHeader
.biWidth
= width
;
1759 bitmapInfo
.bmiHeader
.biHeight
= height
;
1760 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1761 bitmapInfo
.bmiHeader
.biBitCount
= bpp
;
1762 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1763 bitmapInfo
.bmiHeader
.biSizeImage
= colorSize
;
1765 iconInfo
.fIcon
= TRUE
;
1766 iconInfo
.xHotspot
= 0;
1767 iconInfo
.yHotspot
= 0;
1769 iconInfo
.hbmMask
= CreateBitmap( width
, height
, 1, 1, &mask
);
1770 if(!iconInfo
.hbmMask
) return NULL
;
1772 iconInfo
.hbmColor
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, &buffer
, NULL
, 0);
1773 if(!iconInfo
.hbmColor
|| !buffer
)
1775 DeleteObject(iconInfo
.hbmMask
);
1779 memcpy(buffer
, color
, colorSize
);
1781 return CreateIconIndirect(&iconInfo
);
1784 static void check_alpha_draw(HDC hdc
, BOOL drawiconex
, BOOL alpha
, int bpp
, int line
)
1788 COLORREF modern_expected
, legacy_expected
, result
;
1790 color
[0] = 0x00A0B0C0;
1791 color
[1] = alpha
? 0xFF000000 : 0x00000000;
1792 modern_expected
= alpha
? 0x00FFFFFF : 0x00C0B0A0;
1793 legacy_expected
= 0x00C0B0A0;
1795 hicon
= create_test_icon(hdc
, 2, 1, bpp
, 0, color
, sizeof(color
));
1798 SetPixelV(hdc
, 0, 0, 0x00FFFFFF);
1801 DrawIconEx(hdc
, 0, 0, hicon
, 2, 1, 0, NULL
, DI_NORMAL
);
1803 DrawIcon(hdc
, 0, 0, hicon
);
1805 result
= GetPixel(hdc
, 0, 0);
1806 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1807 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1808 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1809 "Got %06X from line %d\n",
1810 alpha
? "Alpha blending" : "Not alpha blending", modern_expected
, legacy_expected
,
1811 drawiconex
? "DrawIconEx" : "DrawIcon", result
, line
);
1814 static void check_DrawIcon(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, COLORREF background
,
1815 COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
1818 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
1820 SetPixelV(hdc
, 0, 0, background
);
1821 SetPixelV(hdc
, GetSystemMetrics(SM_CXICON
)-1, GetSystemMetrics(SM_CYICON
)-1, background
);
1822 SetPixelV(hdc
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
), background
);
1823 DrawIcon(hdc
, 0, 0, hicon
);
1824 result
= GetPixel(hdc
, 0, 0);
1826 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1827 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1828 "Overlaying Mask %d on Color %06X with DrawIcon. "
1829 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1830 maskvalue
, color
, modern_expected
, legacy_expected
, result
, line
);
1832 result
= GetPixel(hdc
, GetSystemMetrics(SM_CXICON
)-1, GetSystemMetrics(SM_CYICON
)-1);
1834 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1835 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1836 "Overlaying Mask %d on Color %06X with DrawIcon. "
1837 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1838 maskvalue
, color
, modern_expected
, legacy_expected
, result
, line
);
1840 result
= GetPixel(hdc
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
));
1842 ok (color_match(result
, background
),
1843 "Overlaying Mask %d on Color %06X with DrawIcon. "
1844 "Expected unchanged background color %06X. Got %06X from line %d\n",
1845 maskvalue
, color
, background
, result
, line
);
1848 static void test_DrawIcon(void)
1850 BITMAPINFO bitmapInfo
;
1852 HBITMAP bmpDst
= NULL
;
1853 HBITMAP bmpOld
= NULL
;
1856 hdcDst
= CreateCompatibleDC(0);
1857 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1861 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
1863 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1867 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1868 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1869 bitmapInfo
.bmiHeader
.biWidth
= GetSystemMetrics(SM_CXICON
)+1;
1870 bitmapInfo
.bmiHeader
.biHeight
= GetSystemMetrics(SM_CYICON
)+1;
1871 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1872 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1873 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1874 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1876 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1877 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1878 if (!bmpDst
|| !bits
)
1880 bmpOld
= SelectObject(hdcDst
, bmpDst
);
1882 /* Mask is only heeded if alpha channel is always zero */
1883 check_DrawIcon(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1884 check_DrawIcon(hdcDst
, TRUE
, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__
);
1886 /* Test alpha blending */
1887 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1888 check_DrawIcon(hdcDst
, FALSE
, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1889 check_DrawIcon(hdcDst
, TRUE
, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__
);
1891 check_DrawIcon(hdcDst
, FALSE
, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1892 check_DrawIcon(hdcDst
, TRUE
, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1893 check_DrawIcon(hdcDst
, FALSE
, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__
);
1894 check_DrawIcon(hdcDst
, TRUE
, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__
);
1896 check_DrawIcon(hdcDst
, FALSE
, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1897 check_DrawIcon(hdcDst
, TRUE
, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1899 /* Test detecting of alpha channel */
1900 /* If a single pixel's alpha channel is non-zero, the icon
1901 will be alpha blended, otherwise it will be draw with
1903 check_alpha_draw(hdcDst
, FALSE
, FALSE
, 32, __LINE__
);
1904 check_alpha_draw(hdcDst
, FALSE
, TRUE
, 32, __LINE__
);
1908 SelectObject(hdcDst
, bmpOld
);
1910 DeleteObject(bmpDst
);
1915 static void check_DrawIconEx(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, UINT flags
, COLORREF background
,
1916 COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
1919 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
1921 SetPixelV(hdc
, 0, 0, background
);
1922 DrawIconEx(hdc
, 0, 0, hicon
, 1, 1, 0, NULL
, flags
);
1923 result
= GetPixel(hdc
, 0, 0);
1925 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1926 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1927 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1928 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1929 maskvalue
, color
, flags
, modern_expected
, legacy_expected
, result
, line
);
1932 static void test_DrawIconEx(void)
1934 BITMAPINFO bitmapInfo
;
1936 HBITMAP bmpDst
= NULL
;
1937 HBITMAP bmpOld
= NULL
;
1940 hdcDst
= CreateCompatibleDC(0);
1941 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1945 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
1947 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1951 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1952 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1953 bitmapInfo
.bmiHeader
.biWidth
= 1;
1954 bitmapInfo
.bmiHeader
.biHeight
= 1;
1955 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1956 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1957 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1958 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1959 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1960 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1961 if (!bmpDst
|| !bits
)
1963 bmpOld
= SelectObject(hdcDst
, bmpDst
);
1965 /* Test null, image only, and mask only drawing */
1966 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__
);
1967 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__
);
1969 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_MASK
, 0x00123456, 0x00000000, 0x00000000, __LINE__
);
1970 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_MASK
, 0x00123456, 0x00FFFFFF, 0x00FFFFFF, __LINE__
);
1972 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, DI_IMAGE
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1973 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, DI_IMAGE
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1975 /* Test normal drawing */
1976 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1977 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__
);
1978 check_DrawIconEx(hdcDst
, FALSE
, 0xFFA0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1980 /* Test alpha blending */
1981 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1982 check_DrawIconEx(hdcDst
, TRUE
, 0xFFA0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__
);
1984 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1985 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1986 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__
);
1987 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__
);
1989 check_DrawIconEx(hdcDst
, FALSE
, 0x01FFFFFF, 32, DI_NORMAL
, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1990 check_DrawIconEx(hdcDst
, TRUE
, 0x01FFFFFF, 32, DI_NORMAL
, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1992 /* Test detecting of alpha channel */
1993 /* If a single pixel's alpha channel is non-zero, the icon
1994 will be alpha blended, otherwise it will be draw with
1996 check_alpha_draw(hdcDst
, TRUE
, FALSE
, 32, __LINE__
);
1997 check_alpha_draw(hdcDst
, TRUE
, TRUE
, 32, __LINE__
);
2001 SelectObject(hdcDst
, bmpOld
);
2003 DeleteObject(bmpDst
);
2008 static void check_DrawState_Size(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, HBRUSH hbr
, UINT flags
, int line
)
2010 COLORREF result
, background
;
2012 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
2013 background
= 0x00FFFFFF;
2014 /* Set color of the 2 pixels that will be checked afterwards */
2015 SetPixelV(hdc
, 0, 0, background
);
2016 SetPixelV(hdc
, 2, 2, background
);
2018 /* Let DrawState calculate the size of the icon (it's 1x1) */
2019 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 0, 0, (DST_ICON
| flags
));
2021 result
= GetPixel(hdc
, 0, 0);
2022 passed
[0] = color_match(result
, background
);
2023 result
= GetPixel(hdc
, 2, 2);
2024 passed
[0] = passed
[0] & color_match(result
, background
);
2026 /* Check if manually specifying the icon size DOESN'T work */
2028 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
2029 * size in which it should be ultimately drawn. Therefore giving
2030 * width/height 2x2 if the icon is only 1x1 pixels in size should
2031 * result in drawing it with size 1x1. The size parameters must be
2032 * ignored if a Icon has to be drawn! */
2033 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 2, 2, (DST_ICON
| flags
));
2035 result
= GetPixel(hdc
, 0, 0);
2036 passed
[1] = color_match(result
, background
);
2037 result
= GetPixel(hdc
, 2, 2);
2038 passed
[1] = passed
[0] & color_match(result
, background
);
2040 if(!passed
[0]&&!passed
[1])
2042 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
2043 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
2044 "Color %06X with flags %08X. Line %d\n",
2045 maskvalue
, color
, (DST_ICON
| flags
), line
);
2048 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2049 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
2050 "Mask %d on Color %06X with flags %08X. Line %d\n",
2051 maskvalue
, color
, (DST_ICON
| flags
), line
);
2054 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2055 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
2056 "Color %06X with flags %08X. Line %d\n",
2057 maskvalue
, color
, (DST_ICON
| flags
), line
);
2060 static void check_DrawState_Color(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, HBRUSH hbr
, UINT flags
,
2061 COLORREF background
, COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
2064 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
2066 /* Set color of the pixel that will be checked afterwards */
2067 SetPixelV(hdc
, 1, 1, background
);
2069 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 0, 0, ( DST_ICON
| flags
));
2071 /* Check the color of the pixel is correct */
2072 result
= GetPixel(hdc
, 1, 1);
2074 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
2075 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
2076 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2077 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2078 maskvalue
, color
, (DST_ICON
| flags
), modern_expected
, legacy_expected
, result
, line
);
2081 static void test_DrawState(void)
2083 BITMAPINFO bitmapInfo
;
2085 HBITMAP bmpDst
= NULL
;
2086 HBITMAP bmpOld
= NULL
;
2089 hdcDst
= CreateCompatibleDC(0);
2090 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2094 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
2096 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2100 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
2101 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2102 bitmapInfo
.bmiHeader
.biWidth
= 3;
2103 bitmapInfo
.bmiHeader
.biHeight
= 3;
2104 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2105 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2106 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2107 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
2108 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2109 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2110 if (!bmpDst
|| !bits
)
2112 bmpOld
= SelectObject(hdcDst
, bmpDst
);
2114 /* potential flags to test with DrawState are: */
2115 /* DSS_DISABLED embosses the icon */
2116 /* DSS_MONO draw Icon using a brush as parameter 5 */
2117 /* DSS_NORMAL draw Icon without any modifications */
2118 /* DSS_UNION draw the Icon dithered */
2120 check_DrawState_Size(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, DSS_NORMAL
, __LINE__
);
2121 check_DrawState_Color(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, DSS_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
2125 SelectObject(hdcDst
, bmpOld
);
2127 DeleteObject(bmpDst
);
2132 static DWORD parent_id
;
2134 static DWORD CALLBACK
set_cursor_thread( void *arg
)
2138 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE
); /* create a msg queue */
2141 BOOL ret
= AttachThreadInput( GetCurrentThreadId(), parent_id
, TRUE
);
2142 ok( ret
, "AttachThreadInput failed\n" );
2144 if (arg
) ret
= SetCursor( (HCURSOR
)arg
);
2145 else ret
= GetCursor();
2146 return (DWORD_PTR
)ret
;
2149 static void test_SetCursor(void)
2151 static const BYTE bmp_bits
[4096];
2152 ICONINFO cursorInfo
;
2153 HCURSOR cursor
, old_cursor
, global_cursor
= 0;
2154 DWORD error
, id
, result
;
2162 memset( &info
, 0, sizeof(info
) );
2163 info
.cbSize
= sizeof(info
);
2164 if (!pGetCursorInfo( &info
))
2166 win_skip( "GetCursorInfo not working\n" );
2167 pGetCursorInfo
= NULL
;
2169 else global_cursor
= info
.hCursor
;
2171 cursor
= GetCursor();
2172 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2173 WaitForSingleObject( thread
, 1000 );
2174 GetExitCodeThread( thread
, &result
);
2175 ok( result
== (DWORD_PTR
)cursor
, "wrong thread cursor %x/%p\n", result
, cursor
);
2178 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
2181 cursorInfo
.fIcon
= FALSE
;
2182 cursorInfo
.xHotspot
= 0;
2183 cursorInfo
.yHotspot
= 0;
2184 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
2185 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
2187 cursor
= CreateIconIndirect(&cursorInfo
);
2188 ok(cursor
!= NULL
, "CreateIconIndirect returned %p\n", cursor
);
2189 old_cursor
= SetCursor( cursor
);
2193 info
.cbSize
= sizeof(info
);
2194 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2195 /* global cursor doesn't change since we don't have a window */
2196 ok( info
.hCursor
== global_cursor
|| broken(info
.hCursor
!= cursor
), /* win9x */
2197 "wrong info cursor %p/%p\n", info
.hCursor
, global_cursor
);
2199 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2200 WaitForSingleObject( thread
, 1000 );
2201 GetExitCodeThread( thread
, &result
);
2202 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2205 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2206 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2207 WaitForSingleObject( thread
, 1000 );
2208 GetExitCodeThread( thread
, &result
);
2209 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2211 thread
= CreateThread( NULL
, 0, set_cursor_thread
, cursor
, 0, &id
);
2212 WaitForSingleObject( thread
, 1000 );
2213 GetExitCodeThread( thread
, &result
);
2214 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2215 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2217 parent_id
= GetCurrentThreadId();
2218 thread
= CreateThread( NULL
, 0, set_cursor_thread
, cursor
, 0, &id
);
2219 WaitForSingleObject( thread
, 1000 );
2220 GetExitCodeThread( thread
, &result
);
2221 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2222 ok( GetCursor() == cursor
, "wrong cursor %p/0\n", cursor
);
2226 info
.cbSize
= sizeof(info
);
2227 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2228 ok( info
.hCursor
== global_cursor
|| broken(info
.hCursor
!= cursor
), /* win9x */
2229 "wrong info cursor %p/%p\n", info
.hCursor
, global_cursor
);
2231 SetCursor( old_cursor
);
2232 DestroyCursor( cursor
);
2234 SetLastError( 0xdeadbeef );
2235 cursor
= SetCursor( (HCURSOR
)0xbadbad );
2236 error
= GetLastError();
2237 ok( cursor
== 0, "wrong cursor %p/0\n", cursor
);
2238 ok( error
== ERROR_INVALID_CURSOR_HANDLE
|| broken( error
== 0xdeadbeef ), /* win9x */
2239 "wrong error %u\n", error
);
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
);
2250 static HANDLE event_start
, event_next
;
2252 static DWORD CALLBACK
show_cursor_thread( void *arg
)
2254 DWORD count
= (DWORD_PTR
)arg
;
2257 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE
); /* create a msg queue */
2260 BOOL ret
= AttachThreadInput( GetCurrentThreadId(), parent_id
, TRUE
);
2261 ok( ret
, "AttachThreadInput failed\n" );
2263 if (!count
) ret
= ShowCursor( FALSE
);
2264 else while (count
--) ret
= ShowCursor( TRUE
);
2265 SetEvent( event_start
);
2266 WaitForSingleObject( event_next
, 2000 );
2270 static void test_ShowCursor(void)
2279 memset( &info
, 0, sizeof(info
) );
2280 info
.cbSize
= sizeof(info
);
2281 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2282 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2285 event_start
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
2286 event_next
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
2288 count
= ShowCursor( TRUE
);
2289 ok( count
== 1, "wrong count %d\n", count
);
2290 count
= ShowCursor( TRUE
);
2291 ok( count
== 2, "wrong count %d\n", count
);
2292 count
= ShowCursor( FALSE
);
2293 ok( count
== 1, "wrong count %d\n", count
);
2294 count
= ShowCursor( FALSE
);
2295 ok( count
== 0, "wrong count %d\n", count
);
2296 count
= ShowCursor( FALSE
);
2297 ok( count
== -1, "wrong count %d\n", count
);
2298 count
= ShowCursor( FALSE
);
2299 ok( count
== -2, "wrong count %d\n", count
);
2303 info
.cbSize
= sizeof(info
);
2304 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2305 /* global show count is not affected since we don't have a window */
2306 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2310 thread
= CreateThread( NULL
, 0, show_cursor_thread
, NULL
, 0, &id
);
2311 WaitForSingleObject( event_start
, 1000 );
2312 count
= ShowCursor( FALSE
);
2313 ok( count
== -3, "wrong count %d\n", count
);
2314 SetEvent( event_next
);
2315 WaitForSingleObject( thread
, 1000 );
2316 GetExitCodeThread( thread
, &result
);
2317 ok( result
== -1, "wrong thread count %d\n", result
);
2318 count
= ShowCursor( FALSE
);
2319 ok( count
== -4, "wrong count %d\n", count
);
2321 thread
= CreateThread( NULL
, 0, show_cursor_thread
, (void *)1, 0, &id
);
2322 WaitForSingleObject( event_start
, 1000 );
2323 count
= ShowCursor( TRUE
);
2324 ok( count
== -3, "wrong count %d\n", count
);
2325 SetEvent( event_next
);
2326 WaitForSingleObject( thread
, 1000 );
2327 GetExitCodeThread( thread
, &result
);
2328 ok( result
== 1, "wrong thread count %d\n", result
);
2329 count
= ShowCursor( TRUE
);
2330 ok( count
== -2, "wrong count %d\n", count
);
2332 parent_id
= GetCurrentThreadId();
2333 thread
= CreateThread( NULL
, 0, show_cursor_thread
, NULL
, 0, &id
);
2334 WaitForSingleObject( event_start
, 1000 );
2335 count
= ShowCursor( TRUE
);
2336 ok( count
== -2, "wrong count %d\n", count
);
2337 SetEvent( event_next
);
2338 WaitForSingleObject( thread
, 1000 );
2339 GetExitCodeThread( thread
, &result
);
2340 ok( result
== -3, "wrong thread count %d\n", result
);
2341 count
= ShowCursor( FALSE
);
2342 ok( count
== -2, "wrong count %d\n", count
);
2344 thread
= CreateThread( NULL
, 0, show_cursor_thread
, (void *)3, 0, &id
);
2345 WaitForSingleObject( event_start
, 1000 );
2346 count
= ShowCursor( TRUE
);
2347 ok( count
== 2, "wrong count %d\n", count
);
2348 SetEvent( event_next
);
2349 WaitForSingleObject( thread
, 1000 );
2350 GetExitCodeThread( thread
, &result
);
2351 ok( result
== 1, "wrong thread count %d\n", result
);
2352 count
= ShowCursor( FALSE
);
2353 ok( count
== -2, "wrong count %d\n", count
);
2357 info
.cbSize
= sizeof(info
);
2358 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2359 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2362 count
= ShowCursor( TRUE
);
2363 ok( count
== -1, "wrong count %d\n", count
);
2364 count
= ShowCursor( TRUE
);
2365 ok( count
== 0, "wrong count %d\n", count
);
2369 info
.cbSize
= sizeof(info
);
2370 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2371 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2376 static void test_DestroyCursor(void)
2378 static const BYTE bmp_bits
[4096];
2379 ICONINFO cursorInfo
, new_info
;
2380 HCURSOR cursor
, cursor2
, new_cursor
;
2387 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
2390 cursorInfo
.fIcon
= FALSE
;
2391 cursorInfo
.xHotspot
= 0;
2392 cursorInfo
.yHotspot
= 0;
2393 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
2394 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
2396 cursor
= CreateIconIndirect(&cursorInfo
);
2397 ok(cursor
!= NULL
, "CreateIconIndirect returned %p\n", cursor
);
2403 SetLastError(0xdeadbeef);
2404 ret
= DestroyCursor(cursor
);
2405 ok(!ret
|| broken(ret
) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2406 error
= GetLastError();
2407 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
2409 new_cursor
= GetCursor();
2410 if (ret
) /* win9x replaces cursor by another one on destroy */
2411 ok(new_cursor
!= cursor
, "GetCursor returned %p/%p\n", new_cursor
, cursor
);
2413 ok(new_cursor
== cursor
, "GetCursor returned %p/%p\n", new_cursor
, cursor
);
2415 SetLastError(0xdeadbeef);
2416 ret
= GetIconInfo( cursor
, &new_info
);
2417 ok( !ret
|| broken(ret
), /* nt4 */ "GetIconInfo succeeded\n" );
2418 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
||
2419 broken(GetLastError() == 0xdeadbeef), /* win9x */
2420 "wrong error %u\n", GetLastError() );
2422 if (ret
) /* nt4 delays destruction until cursor changes */
2424 DeleteObject( new_info
.hbmColor
);
2425 DeleteObject( new_info
.hbmMask
);
2427 SetLastError(0xdeadbeef);
2428 ret
= DestroyCursor( cursor
);
2429 ok( !ret
, "DestroyCursor succeeded\n" );
2430 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2431 "wrong error %u\n", GetLastError() );
2433 SetLastError(0xdeadbeef);
2434 cursor2
= SetCursor( cursor
);
2435 ok( cursor2
== cursor
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2436 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2437 "wrong error %u\n", GetLastError() );
2441 SetLastError(0xdeadbeef);
2442 cursor2
= CopyCursor( cursor
);
2443 ok(!cursor2
, "CopyCursor succeeded\n" );
2444 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
||
2445 broken(GetLastError() == 0xdeadbeef), /* win9x */
2446 "wrong error %u\n", GetLastError() );
2448 SetLastError(0xdeadbeef);
2449 ret
= DestroyCursor( cursor
);
2450 if (new_cursor
!= cursor
) /* win9x */
2451 ok( ret
, "DestroyCursor succeeded\n" );
2453 ok( !ret
, "DestroyCursor succeeded\n" );
2454 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2455 "wrong error %u\n", GetLastError() );
2457 SetLastError(0xdeadbeef);
2458 cursor2
= SetCursor( cursor
);
2459 ok(!cursor2
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2460 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2461 "wrong error %u\n", GetLastError() );
2464 cursor2
= GetCursor();
2465 ok(cursor2
== new_cursor
, "GetCursor returned %p/%p\n", cursor2
, new_cursor
);
2467 SetLastError(0xdeadbeef);
2468 cursor2
= SetCursor( 0 );
2469 if (new_cursor
!= cursor
) /* win9x */
2470 ok(cursor2
== new_cursor
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2472 ok(!cursor2
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2473 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2475 cursor2
= GetCursor();
2476 ok(!cursor2
, "GetCursor returned %p/%p\n", cursor2
, cursor
);
2478 SetLastError(0xdeadbeef);
2479 ret
= DestroyCursor(cursor
);
2480 if (new_cursor
!= cursor
) /* win9x */
2481 ok( ret
, "DestroyCursor succeeded\n" );
2483 ok( !ret
, "DestroyCursor succeeded\n" );
2484 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2485 "wrong error %u\n", GetLastError() );
2487 DeleteObject(cursorInfo
.hbmMask
);
2488 DeleteObject(cursorInfo
.hbmColor
);
2490 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2491 cursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2493 SetLastError(0xdeadbeef);
2494 ret
= DestroyCursor(cursor
);
2495 ok(ret
|| broken(!ret
) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2496 error
= GetLastError();
2497 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
2499 /* Try setting the cursor to a destroyed OEM cursor. */
2500 SetLastError(0xdeadbeef);
2502 error
= GetLastError();
2503 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
2505 /* Check if LoadCursor() returns the same handle with the same icon. */
2506 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2507 ok(cursor2
== cursor
, "cursor == %p, cursor2 == %p\n", cursor
, cursor2
);
2509 /* Check if LoadCursor() returns the same handle with a different icon. */
2510 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_WAIT
);
2511 ok(cursor2
!= cursor
, "cursor == %p, cursor2 == %p\n", cursor
, cursor2
);
2514 static void test_PrivateExtractIcons(void)
2519 static const test_icon_entries_t icon_desc
[] = {{0,0,TRUE
}, {16,16,TRUE
}, {32,32}, {64,64,TRUE
}};
2521 create_ico_file("extract.ico", icon_desc
, sizeof(icon_desc
)/sizeof(*icon_desc
));
2523 ret
= PrivateExtractIconsA("extract.ico", 0, 32, 32, &icon
, NULL
, 1, 0);
2524 ok(ret
== 1, "PrivateExtractIconsA returned %u\n", ret
);
2525 ok(icon
!= NULL
, "icon == NULL\n");
2527 test_icon_info(icon
, 32, 32, 32, 32);
2530 DeleteFileA("extract.ico");
2533 static void test_monochrome_icon(void)
2537 DWORD bytes_written
;
2538 CURSORICONFILEDIR
*icon_data
;
2539 CURSORICONFILEDIRENTRY
*icon_entry
;
2540 BITMAPINFO
*bitmap_info
;
2541 BITMAPCOREINFO
*core_info
;
2544 BOOL monochrome
, use_core_info
;
2546 icon_data
= HeapAlloc(GetProcessHeap(), 0, sizeof(CURSORICONFILEDIR
) + sizeof(BITMAPINFOHEADER
) +
2547 2 * sizeof(RGBQUAD
) + sizeof(ULONG
));
2549 for (monochrome
= FALSE
; monochrome
<= TRUE
; monochrome
++)
2550 for (use_core_info
= FALSE
; use_core_info
<= TRUE
; use_core_info
++)
2553 monochrome
? "monochrome" : "colored",
2554 use_core_info
? "core info" : "bitmap info");
2556 icon_size
= sizeof(CURSORICONFILEDIR
) +
2557 (use_core_info
? sizeof(BITMAPCOREHEADER
) : sizeof(BITMAPINFOHEADER
)) +
2558 /* 2 * sizeof(RGBTRIPLE) + padding comes out the same */
2559 2 * sizeof(RGBQUAD
) +
2561 ZeroMemory(icon_data
, icon_size
);
2562 icon_data
->idReserved
= 0;
2563 icon_data
->idType
= 1;
2564 icon_data
->idCount
= 1;
2566 icon_entry
= icon_data
->idEntries
;
2567 icon_entry
->bWidth
= 1;
2568 icon_entry
->bHeight
= 1;
2569 icon_entry
->bColorCount
= 0;
2570 icon_entry
->bReserved
= 0;
2571 icon_entry
->xHotspot
= 0;
2572 icon_entry
->yHotspot
= 0;
2573 icon_entry
->dwDIBSize
= icon_size
- sizeof(CURSORICONFILEDIR
);
2574 icon_entry
->dwDIBOffset
= sizeof(CURSORICONFILEDIR
);
2578 core_info
= (BITMAPCOREINFO
*) ((BYTE
*) icon_data
+ icon_entry
->dwDIBOffset
);
2579 core_info
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2580 core_info
->bmciHeader
.bcWidth
= 1;
2581 core_info
->bmciHeader
.bcHeight
= 2;
2582 core_info
->bmciHeader
.bcPlanes
= 1;
2583 core_info
->bmciHeader
.bcBitCount
= 1;
2584 core_info
->bmciColors
[0].rgbtBlue
= monochrome
? 0x00 : 0xff;
2585 core_info
->bmciColors
[0].rgbtGreen
= 0x00;
2586 core_info
->bmciColors
[0].rgbtRed
= 0x00;
2587 core_info
->bmciColors
[1].rgbtBlue
= 0xff;
2588 core_info
->bmciColors
[1].rgbtGreen
= 0xff;
2589 core_info
->bmciColors
[1].rgbtRed
= 0xff;
2593 bitmap_info
= (BITMAPINFO
*) ((BYTE
*) icon_data
+ icon_entry
->dwDIBOffset
);
2594 bitmap_info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2595 bitmap_info
->bmiHeader
.biWidth
= 1;
2596 bitmap_info
->bmiHeader
.biHeight
= 2;
2597 bitmap_info
->bmiHeader
.biPlanes
= 1;
2598 bitmap_info
->bmiHeader
.biBitCount
= 1;
2599 bitmap_info
->bmiHeader
.biSizeImage
= 0; /* Uncompressed bitmap. */
2600 bitmap_info
->bmiColors
[0].rgbBlue
= monochrome
? 0x00 : 0xff;
2601 bitmap_info
->bmiColors
[0].rgbGreen
= 0x00;
2602 bitmap_info
->bmiColors
[0].rgbRed
= 0x00;
2603 bitmap_info
->bmiColors
[1].rgbBlue
= 0xff;
2604 bitmap_info
->bmiColors
[1].rgbGreen
= 0xff;
2605 bitmap_info
->bmiColors
[1].rgbRed
= 0xff;
2608 handle
= CreateFileA("icon.ico", GENERIC_WRITE
, 0, NULL
, CREATE_NEW
,
2609 FILE_ATTRIBUTE_NORMAL
, NULL
);
2610 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileA failed. %u\n", GetLastError());
2611 ret
= WriteFile(handle
, icon_data
, icon_size
, &bytes_written
, NULL
);
2612 ok(ret
&& bytes_written
== icon_size
, "icon.ico created improperly.\n");
2613 CloseHandle(handle
);
2615 handle
= LoadImageA(NULL
, "icon.ico", IMAGE_ICON
, 0, 0, LR_LOADFROMFILE
);
2616 ok(handle
!= NULL
||
2617 broken(use_core_info
&& handle
== NULL
), /* Win 8, 10 */
2618 "LoadImage() failed with %u.\n", GetLastError());
2621 skip("Icon failed to load: %s, %s\n",
2622 monochrome
? "monochrome" : "colored",
2623 use_core_info
? "core info" : "bitmap info");
2624 DeleteFileA("icon.ico");
2628 ret
= GetIconInfo(handle
, &icon_info
);
2629 ok(ret
, "GetIconInfo() failed with %u.\n", GetLastError());
2632 ok(icon_info
.fIcon
== TRUE
, "fIcon is %u.\n", icon_info
.fIcon
);
2633 ok(icon_info
.xHotspot
== 0, "xHotspot is %u.\n", icon_info
.xHotspot
);
2634 ok(icon_info
.yHotspot
== 0, "yHotspot is %u.\n", icon_info
.yHotspot
);
2636 ok(icon_info
.hbmColor
== NULL
, "Got hbmColor %p!\n", icon_info
.hbmColor
);
2638 ok(icon_info
.hbmColor
!= NULL
, "No hbmColor!\n");
2639 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
2642 ret
= DestroyIcon(handle
);
2643 ok(ret
, "DestroyIcon() failed with %u.\n", GetLastError());
2644 DeleteFileA("icon.ico");
2647 HeapFree(GetProcessHeap(), 0, icon_data
);
2650 START_TEST(cursoricon
)
2652 pGetCursorInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2653 pGetIconInfoExA
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2654 pGetIconInfoExW
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2655 pGetCursorFrameInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2656 test_argc
= winetest_get_mainargs(&test_argv
);
2660 /* Child process. */
2661 sscanf (test_argv
[2], "%x", (unsigned int *) &parent
);
2663 ok(parent
!= NULL
, "Parent not found.\n");
2671 test_CopyImage_Bitmap(1);
2672 test_CopyImage_Bitmap(4);
2673 test_CopyImage_Bitmap(8);
2674 test_CopyImage_Bitmap(16);
2675 test_CopyImage_Bitmap(24);
2676 test_CopyImage_Bitmap(32);
2677 test_initial_cursor();
2680 test_CreateIconFromResource();
2681 test_GetCursorFrameInfo();
2687 test_DestroyCursor();
2688 test_PrivateExtractIcons();
2689 test_monochrome_icon();
2691 test_child_process();
2692 finish_child_process();