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
27 #include "wine/test.h"
46 } CURSORICONFILEDIRENTRY
;
53 CURSORICONFILEDIRENTRY idEntries
[1];
56 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
57 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
58 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
60 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
61 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
62 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
63 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
64 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
65 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
66 #define ANI_icon_ID RIFF_FOURCC('i', 'c', 'o', 'n')
67 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
69 #define ANI_FLAG_ICON 0x1
70 #define ANI_FLAG_SEQUENCE 0x2
89 CURSORICONFILEDIR icon_info
; /* animated cursor frame information */
90 BITMAPINFOHEADER bmi_header
; /* animated cursor frame header */
91 ani_data32x32x32 bmi_data
; /* animated cursor frame DIB data */
95 DWORD chunk_id
; /* ANI_anih_ID */
96 DWORD chunk_size
; /* actual size of data */
97 ani_header header
; /* animated cursor header */
101 DWORD chunk_id
; /* ANI_LIST_ID */
102 DWORD chunk_size
; /* actual size of data */
103 DWORD chunk_type
; /* ANI_fram_ID */
107 DWORD chunk_id
; /* ANI_icon_ID */
108 DWORD chunk_size
; /* actual size of data */
109 ani_frame32x32x32 data
; /* animated cursor frame */
110 } riff_icon32x32x32_t
;
113 DWORD chunk_id
; /* ANI_RIFF_ID */
114 DWORD chunk_size
; /* actual size of data */
115 DWORD chunk_type
; /* ANI_ACON_ID */
116 riff_header_t header
; /* RIFF animated cursor header */
117 riff_list_t frame_list
; /* RIFF animated cursor frame list info */
118 riff_icon32x32x32_t frames
[1]; /* array of animated cursor frames */
122 DWORD chunk_id
; /* ANI_RIFF_ID */
123 DWORD chunk_size
; /* actual size of data */
124 DWORD chunk_type
; /* ANI_ACON_ID */
125 riff_header_t header
; /* RIFF animated cursor header */
126 riff_list_t frame_list
; /* RIFF animated cursor frame list info */
127 riff_icon32x32x32_t frames
[3]; /* array of three animated cursor frames */
131 DWORD chunk_id
; /* ANI_rate_ID */
132 DWORD chunk_size
; /* actual size of data */
133 DWORD rate
[3]; /* animated cursor rate data */
137 DWORD chunk_id
; /* ANI_seq__ID */
138 DWORD chunk_size
; /* actual size of data */
139 DWORD order
[3]; /* animated cursor sequence data */
143 DWORD chunk_id
; /* ANI_RIFF_ID */
144 DWORD chunk_size
; /* actual size of data */
145 DWORD chunk_type
; /* ANI_ACON_ID */
146 riff_header_t header
; /* RIFF animated cursor header */
147 riff_seq3_t seq
; /* sequence data for three cursor frames */
148 riff_rate3_t rates
; /* rate data for three cursor frames */
149 riff_list_t frame_list
; /* RIFF animated cursor frame list info */
150 riff_icon32x32x32_t frames
[3]; /* array of three animated cursor frames */
151 } riff_cursor3_seq_t
;
153 #define EMPTY_ICON32 \
156 sizeof(ani_frame32x32x32), \
159 0x0, /* reserved */ \
160 0, /* type: icon(1), cursor(2) */ \
166 0, /* color count */ \
167 0x0, /* reserved */ \
168 16, /* x hotspot */ \
169 16, /* y hotspot */ \
170 sizeof(ani_data32x32x32), /* DIB size */ \
171 sizeof(CURSORICONFILEDIR) /* DIB offset */ \
176 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
178 32*2, /* actual height times two */ \
181 BI_RGB, /* compression */ \
182 0, /* image size */ \
183 0, /* biXPelsPerMeter */ \
184 0, /* biYPelsPerMeter */ \
186 0 /* biClrImportant */ \
188 /* DIB data: left uninitialized */ \
192 riff_cursor1_t empty_anicursor
= {
194 sizeof(empty_anicursor
) - sizeof(DWORD
)*2,
207 10, /* display rate in jiffies */
208 ANI_FLAG_ICON
/* flags */
213 sizeof(riff_icon32x32x32_t
)*(1 /*frames*/) + sizeof(DWORD
),
221 riff_cursor3_t empty_anicursor3
= {
223 sizeof(empty_anicursor3
) - sizeof(DWORD
)*2,
236 0xbeef, /* display rate in jiffies */
237 ANI_FLAG_ICON
/* flags */
242 sizeof(riff_icon32x32x32_t
)*(3 /*frames*/) + sizeof(DWORD
),
252 riff_cursor3_seq_t empty_anicursor3_seq
= {
254 sizeof(empty_anicursor3_seq
) - sizeof(DWORD
)*2,
267 0xbeef, /* display rate in jiffies */
268 ANI_FLAG_ICON
|ANI_FLAG_SEQUENCE
/* flags */
273 sizeof(riff_seq3_t
) - sizeof(DWORD
)*2,
274 { 2, 0, 1} /* show frames in a uniquely identifiable order */
278 sizeof(riff_rate3_t
) - sizeof(DWORD
)*2,
279 { 0xc0de, 0xcafe, 0xbabe}
283 sizeof(riff_icon32x32x32_t
)*(3 /*frames*/) + sizeof(DWORD
),
295 static char **test_argv
;
296 static int test_argc
;
297 static HWND child
= 0;
298 static HWND parent
= 0;
299 static HANDLE child_process
;
301 #define PROC_INIT (WM_USER+1)
303 static BOOL (WINAPI
*pGetCursorInfo
)(CURSORINFO
*);
304 static BOOL (WINAPI
*pGetIconInfoExA
)(HICON
,ICONINFOEXA
*);
305 static BOOL (WINAPI
*pGetIconInfoExW
)(HICON
,ICONINFOEXW
*);
307 static const BOOL is_win64
= (sizeof(void *) > sizeof(int));
309 static LRESULT CALLBACK
callback_child(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
313 /* Destroy the cursor. */
316 HCURSOR cursor
= (HCURSOR
)lParam
;
321 memset(&info
, 0, sizeof(info
));
322 ret
= GetIconInfo(cursor
, &info
);
323 todo_wine
ok(ret
, "GetIconInfoEx failed with error %u\n", GetLastError());
324 todo_wine
ok(info
.hbmColor
!= NULL
, "info.hmbColor was not set\n");
325 todo_wine
ok(info
.hbmMask
!= NULL
, "info.hmbColor was not set\n");
326 DeleteObject(info
.hbmColor
);
327 DeleteObject(info
.hbmMask
);
329 SetLastError(0xdeadbeef);
330 ret
= DestroyCursor(cursor
);
331 error
= GetLastError();
332 ok(!ret
|| broken(ret
) /* win9x */, "DestroyCursor on the active cursor succeeded.\n");
333 ok(error
== ERROR_DESTROY_OBJECT_OF_OTHER_THREAD
||
334 error
== 0xdeadbeef, /* vista */
335 "Last error: %u\n", error
);
343 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
346 static LRESULT CALLBACK
callback_parent(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
348 if (msg
== PROC_INIT
)
350 child
= (HWND
) wParam
;
354 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
357 static void do_child(void)
363 /* Register a new class. */
364 class.style
= CS_GLOBALCLASS
;
365 class.lpfnWndProc
= callback_child
;
366 class.cbClsExtra
= 0;
367 class.cbWndExtra
= 0;
368 class.hInstance
= GetModuleHandleA(NULL
);
370 class.hCursor
= NULL
;
371 class.hbrBackground
= NULL
;
372 class.lpszMenuName
= NULL
;
373 class.lpszClassName
= "cursor_child";
375 SetLastError(0xdeadbeef);
376 ret
= RegisterClassA(&class);
377 ok(ret
, "Failed to register window class. Error: %u\n", GetLastError());
379 /* Create a window. */
380 child
= CreateWindowA("cursor_child", "cursor_child", WS_POPUP
| WS_VISIBLE
,
381 0, 0, 200, 200, 0, 0, 0, NULL
);
382 ok(child
!= 0, "CreateWindowA failed. Error: %u\n", GetLastError());
384 /* Let the parent know our HWND. */
385 PostMessageA(parent
, PROC_INIT
, (WPARAM
) child
, 0);
387 /* Receive messages. */
388 while ((ret
= GetMessageA(&msg
, 0, 0, 0)))
390 ok(ret
!= -1, "GetMessage failed. Error: %u\n", GetLastError());
391 TranslateMessage(&msg
);
392 DispatchMessageA(&msg
);
396 static void do_parent(void)
398 char path_name
[MAX_PATH
];
399 PROCESS_INFORMATION info
;
400 STARTUPINFOA startup
;
405 /* Register a new class. */
406 class.style
= CS_GLOBALCLASS
;
407 class.lpfnWndProc
= callback_parent
;
408 class.cbClsExtra
= 0;
409 class.cbWndExtra
= 0;
410 class.hInstance
= GetModuleHandleA(NULL
);
412 class.hCursor
= NULL
;
413 class.hbrBackground
= NULL
;
414 class.lpszMenuName
= NULL
;
415 class.lpszClassName
= "cursor_parent";
417 SetLastError(0xdeadbeef);
418 ret
= RegisterClassA(&class);
419 ok(ret
, "Failed to register window class. Error: %u\n", GetLastError());
421 /* Create a window. */
422 parent
= CreateWindowA("cursor_parent", "cursor_parent", WS_POPUP
| WS_VISIBLE
,
423 0, 0, 200, 200, 0, 0, 0, NULL
);
424 ok(parent
!= 0, "CreateWindowA failed. Error: %u\n", GetLastError());
426 /* Start child process. */
427 memset(&startup
, 0, sizeof(startup
));
428 startup
.cb
= sizeof(startup
);
429 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
430 startup
.wShowWindow
= SW_SHOWNORMAL
;
432 sprintf(path_name
, "%s cursoricon %lx", test_argv
[0], (INT_PTR
)parent
);
433 ok(CreateProcessA(NULL
, path_name
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess failed.\n");
434 child_process
= info
.hProcess
;
436 /* Wait for child window handle. */
437 while ((child
== 0) && (ret
= GetMessageA(&msg
, parent
, 0, 0)))
439 ok(ret
!= -1, "GetMessage failed. Error: %u\n", GetLastError());
440 TranslateMessage(&msg
);
441 DispatchMessageA(&msg
);
445 static void finish_child_process(void)
447 SendMessageA(child
, WM_CLOSE
, 0, 0);
448 winetest_wait_child_process( child_process
);
449 CloseHandle(child_process
);
452 static void test_child_process(void)
454 static const BYTE bmp_bits
[4096];
460 /* Create and set a dummy cursor. */
462 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
465 cursorInfo
.fIcon
= FALSE
;
466 cursorInfo
.xHotspot
= 0;
467 cursorInfo
.yHotspot
= 0;
468 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
469 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
471 cursor
= CreateIconIndirect(&cursorInfo
);
472 ok(cursor
!= NULL
, "CreateIconIndirect returned %p.\n", cursor
);
476 /* Destroy the cursor. */
477 SendMessageA(child
, WM_USER
+1, 0, (LPARAM
) cursor
);
480 static BOOL
color_match(COLORREF a
, COLORREF b
)
482 /* 5-bit accuracy is a sufficient test. This will match as long as
483 * colors are never truncated to less that 3x5-bit accuracy i.e.
485 return (a
& 0x00F8F8F8) == (b
& 0x00F8F8F8);
488 static void test_CopyImage_Check(HBITMAP bitmap
, UINT flags
, INT copyWidth
, INT copyHeight
,
489 INT expectedWidth
, INT expectedHeight
, WORD expectedDepth
, BOOL dibExpected
)
497 copy
= CopyImage(bitmap
, IMAGE_BITMAP
, copyWidth
, copyHeight
, flags
);
498 ok(copy
!= NULL
, "CopyImage() failed\n");
501 GetObjectA(bitmap
, sizeof(origBitmap
), &origBitmap
);
502 GetObjectA(copy
, sizeof(copyBitmap
), ©Bitmap
);
503 orig_is_dib
= (origBitmap
.bmBits
!= NULL
);
504 copy_is_dib
= (copyBitmap
.bmBits
!= NULL
);
506 if (copy_is_dib
&& dibExpected
507 && copyBitmap
.bmBitsPixel
== 24
508 && (expectedDepth
== 16 || expectedDepth
== 32))
510 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
511 if (GetVersion() & 0x80000000)
517 if (copy_is_dib
&& !dibExpected
&& !(flags
& LR_CREATEDIBSECTION
))
519 /* It's not forbidden to create a DIB section if the flag
520 LR_CREATEDIBSECTION is absent.
521 Windows 9x does this if the bitmap has a depth that doesn't
522 match the screen depth, Windows NT doesn't */
524 expectedDepth
= origBitmap
.bmBitsPixel
;
527 ok((!(dibExpected
^ copy_is_dib
)
528 && (copyBitmap
.bmWidth
== expectedWidth
)
529 && (copyBitmap
.bmHeight
== expectedHeight
)
530 && (copyBitmap
.bmBitsPixel
== expectedDepth
)),
531 "CopyImage ((%s, %dx%d, %u bpp), %d, %d, %#x): Expected (%s, %dx%d, %u bpp), got (%s, %dx%d, %u bpp)\n",
532 orig_is_dib
? "DIB" : "DDB", origBitmap
.bmWidth
, origBitmap
.bmHeight
, origBitmap
.bmBitsPixel
,
533 copyWidth
, copyHeight
, flags
,
534 dibExpected
? "DIB" : "DDB", expectedWidth
, expectedHeight
, expectedDepth
,
535 copy_is_dib
? "DIB" : "DDB", copyBitmap
.bmWidth
, copyBitmap
.bmHeight
, copyBitmap
.bmBitsPixel
);
541 static void test_CopyImage_Bitmap(int depth
)
550 /* Create a device-independent bitmap (DIB) */
551 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
552 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
553 info
->bmiHeader
.biWidth
= 2;
554 info
->bmiHeader
.biHeight
= 2;
555 info
->bmiHeader
.biPlanes
= 1;
556 info
->bmiHeader
.biBitCount
= depth
;
557 info
->bmiHeader
.biCompression
= BI_RGB
;
559 for (i
=0; i
< 256; i
++)
561 info
->bmiColors
[i
].rgbRed
= i
;
562 info
->bmiColors
[i
].rgbGreen
= i
;
563 info
->bmiColors
[i
].rgbBlue
= 255 - i
;
564 info
->bmiColors
[i
].rgbReserved
= 0;
567 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
569 /* Create a device-dependent bitmap (DDB) */
570 screenDC
= GetDC(NULL
);
571 screen_depth
= GetDeviceCaps(screenDC
, BITSPIXEL
);
572 if (depth
== 1 || depth
== screen_depth
)
574 ddb
= CreateBitmap(2, 2, 1, depth
, NULL
);
580 ReleaseDC(NULL
, screenDC
);
584 test_CopyImage_Check(ddb
, 0, 0, 0, 2, 2, depth
== 1 ? 1 : screen_depth
, FALSE
);
585 test_CopyImage_Check(ddb
, 0, 0, 5, 2, 5, depth
== 1 ? 1 : screen_depth
, FALSE
);
586 test_CopyImage_Check(ddb
, 0, 5, 0, 5, 2, depth
== 1 ? 1 : screen_depth
, FALSE
);
587 test_CopyImage_Check(ddb
, 0, 5, 5, 5, 5, depth
== 1 ? 1 : screen_depth
, FALSE
);
589 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 0, 0, 2, 2, 1, FALSE
);
590 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 5, 0, 5, 2, 1, FALSE
);
591 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 0, 5, 2, 5, 1, FALSE
);
592 test_CopyImage_Check(ddb
, LR_MONOCHROME
, 5, 5, 5, 5, 1, FALSE
);
594 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
595 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
596 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
597 test_CopyImage_Check(ddb
, LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
599 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
600 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
601 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
602 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
603 test_CopyImage_Check(ddb
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
610 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, screen_depth
, FALSE
);
611 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, screen_depth
, FALSE
);
612 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, screen_depth
, FALSE
);
613 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, screen_depth
, FALSE
);
616 test_CopyImage_Check(dib
, LR_MONOCHROME
, 0, 0, 2, 2, 1, FALSE
);
617 test_CopyImage_Check(dib
, LR_MONOCHROME
, 5, 0, 5, 2, 1, FALSE
);
618 test_CopyImage_Check(dib
, LR_MONOCHROME
, 0, 5, 2, 5, 1, FALSE
);
619 test_CopyImage_Check(dib
, LR_MONOCHROME
, 5, 5, 5, 5, 1, FALSE
);
621 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
622 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
623 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
624 test_CopyImage_Check(dib
, LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
626 /* LR_MONOCHROME is ignored if LR_CREATEDIBSECTION is present */
627 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 0, 2, 2, depth
, TRUE
);
628 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 0, 5, 2, depth
, TRUE
);
629 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 0, 5, 2, 5, depth
, TRUE
);
630 test_CopyImage_Check(dib
, LR_MONOCHROME
| LR_CREATEDIBSECTION
, 5, 5, 5, 5, depth
, TRUE
);
636 /* Special case: A monochrome DIB is converted to a monochrome DDB if
637 the colors in the color table are black and white.
639 Skip this test on Windows 95, it always creates a monochrome DDB
642 if (!(GetVersion() & 0x80000000))
644 info
->bmiHeader
.biBitCount
= 1;
645 info
->bmiColors
[0].rgbRed
= 0xFF;
646 info
->bmiColors
[0].rgbGreen
= 0;
647 info
->bmiColors
[0].rgbBlue
= 0;
648 info
->bmiColors
[1].rgbRed
= 0;
649 info
->bmiColors
[1].rgbGreen
= 0xFF;
650 info
->bmiColors
[1].rgbBlue
= 0;
652 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
653 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, screen_depth
, FALSE
);
654 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, screen_depth
, FALSE
);
655 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, screen_depth
, FALSE
);
656 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, screen_depth
, FALSE
);
659 info
->bmiHeader
.biBitCount
= 1;
660 info
->bmiColors
[0].rgbRed
= 0;
661 info
->bmiColors
[0].rgbGreen
= 0;
662 info
->bmiColors
[0].rgbBlue
= 0;
663 info
->bmiColors
[1].rgbRed
= 0xFF;
664 info
->bmiColors
[1].rgbGreen
= 0xFF;
665 info
->bmiColors
[1].rgbBlue
= 0xFF;
667 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
668 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, 1, FALSE
);
669 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, 1, FALSE
);
670 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, 1, FALSE
);
671 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, 1, FALSE
);
674 info
->bmiHeader
.biBitCount
= 1;
675 info
->bmiColors
[0].rgbRed
= 0xFF;
676 info
->bmiColors
[0].rgbGreen
= 0xFF;
677 info
->bmiColors
[0].rgbBlue
= 0xFF;
678 info
->bmiColors
[1].rgbRed
= 0;
679 info
->bmiColors
[1].rgbGreen
= 0;
680 info
->bmiColors
[1].rgbBlue
= 0;
682 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
683 test_CopyImage_Check(dib
, 0, 0, 0, 2, 2, 1, FALSE
);
684 test_CopyImage_Check(dib
, 0, 5, 0, 5, 2, 1, FALSE
);
685 test_CopyImage_Check(dib
, 0, 0, 5, 2, 5, 1, FALSE
);
686 test_CopyImage_Check(dib
, 0, 5, 5, 5, 5, 1, FALSE
);
691 HeapFree(GetProcessHeap(), 0, info
);
694 static void test_initial_cursor(void)
696 HCURSOR cursor
, cursor2
;
699 cursor
= GetCursor();
701 /* Check what handle GetCursor() returns if a cursor is not set yet. */
702 SetLastError(0xdeadbeef);
703 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_WAIT
);
705 ok(cursor
== cursor2
, "cursor (%p) is not IDC_WAIT (%p).\n", cursor
, cursor2
);
707 error
= GetLastError();
708 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
711 static void test_icon_info_dbg(HICON hIcon
, UINT exp_cx
, UINT exp_cy
, UINT exp_mask_cy
, UINT exp_bpp
, int line
)
715 BITMAP bmMask
, bmColor
;
717 ret
= GetIconInfo(hIcon
, &info
);
718 ok_(__FILE__
, line
)(ret
, "GetIconInfo failed\n");
720 /* CreateIcon under XP causes info.fIcon to be 0 */
721 ok_(__FILE__
, line
)(info
.xHotspot
== exp_cx
/2, "info.xHotspot = %u\n", info
.xHotspot
);
722 ok_(__FILE__
, line
)(info
.yHotspot
== exp_cy
/2, "info.yHotspot = %u\n", info
.yHotspot
);
723 ok_(__FILE__
, line
)(info
.hbmMask
!= 0, "info.hbmMask is NULL\n");
725 ret
= GetObjectA(info
.hbmMask
, sizeof(bmMask
), &bmMask
);
726 ok_(__FILE__
, line
)(ret
== sizeof(bmMask
), "GetObject(info.hbmMask) failed, ret %u\n", ret
);
729 ok_(__FILE__
, line
)(info
.hbmColor
== 0, "info.hbmColor should be NULL\n");
737 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
740 ret
= GetObjectA(info
.hbmColor
, sizeof(bmColor
), &bmColor
);
741 ok_(__FILE__
, line
)(ret
== sizeof(bmColor
), "GetObject(info.hbmColor) failed, ret %u\n", ret
);
743 ok_(__FILE__
, line
)(bmColor
.bmBitsPixel
== display_bpp
/* XP */ ||
744 bmColor
.bmBitsPixel
== exp_bpp
/* Win98 */,
745 "bmColor.bmBitsPixel = %d\n", bmColor
.bmBitsPixel
);
746 ok_(__FILE__
, line
)(bmColor
.bmWidth
== exp_cx
, "bmColor.bmWidth = %d\n", bmColor
.bmWidth
);
747 ok_(__FILE__
, line
)(bmColor
.bmHeight
== exp_cy
, "bmColor.bmHeight = %d\n", bmColor
.bmHeight
);
749 ok_(__FILE__
, line
)(bmMask
.bmBitsPixel
== 1, "bmMask.bmBitsPixel = %d\n", bmMask
.bmBitsPixel
);
750 ok_(__FILE__
, line
)(bmMask
.bmWidth
== exp_cx
, "bmMask.bmWidth = %d\n", bmMask
.bmWidth
);
751 ok_(__FILE__
, line
)(bmMask
.bmHeight
== exp_mask_cy
, "bmMask.bmHeight = %d\n", bmMask
.bmHeight
);
755 ok_(__FILE__
, line
)(bmMask
.bmBitsPixel
== 1, "bmMask.bmBitsPixel = %d\n", bmMask
.bmBitsPixel
);
756 ok_(__FILE__
, line
)(bmMask
.bmWidth
== exp_cx
, "bmMask.bmWidth = %d\n", bmMask
.bmWidth
);
757 ok_(__FILE__
, line
)(bmMask
.bmHeight
== exp_mask_cy
, "bmMask.bmHeight = %d\n", bmMask
.bmHeight
);
763 memset( &infoex
, 0xcc, sizeof(infoex
) );
764 SetLastError( 0xdeadbeef );
765 infoex
.cbSize
= sizeof(infoex
) - 1;
766 ret
= pGetIconInfoExA( hIcon
, &infoex
);
767 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
768 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %d\n", GetLastError());
770 SetLastError( 0xdeadbeef );
771 infoex
.cbSize
= sizeof(infoex
) + 1;
772 ret
= pGetIconInfoExA( hIcon
, &infoex
);
773 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
774 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %d\n", GetLastError());
776 SetLastError( 0xdeadbeef );
777 infoex
.cbSize
= sizeof(infoex
);
778 ret
= pGetIconInfoExA( (HICON
)0xdeadbabe, &infoex
);
779 ok_(__FILE__
, line
)(!ret
, "GetIconInfoEx succeeded\n");
780 ok_(__FILE__
, line
)(GetLastError() == ERROR_INVALID_CURSOR_HANDLE
,
781 "wrong error %d\n", GetLastError());
783 infoex
.cbSize
= sizeof(infoex
);
784 ret
= pGetIconInfoExA( hIcon
, &infoex
);
785 ok_(__FILE__
, line
)(ret
, "GetIconInfoEx failed err %d\n", GetLastError());
786 ok_(__FILE__
, line
)(infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
787 ok_(__FILE__
, line
)(infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
788 ok_(__FILE__
, line
)(infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
792 #define test_icon_info(a,b,c,d,e) test_icon_info_dbg((a),(b),(c),(d),(e),__LINE__)
794 static void test_CreateIcon(void)
796 static const BYTE bmp_bits
[1024];
798 HBITMAP hbmMask
, hbmColor
;
807 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
809 /* these crash under XP
810 hIcon = CreateIcon(0, 16, 16, 1, 1, bmp_bits, NULL);
811 hIcon = CreateIcon(0, 16, 16, 1, 1, NULL, bmp_bits);
814 hIcon
= CreateIcon(0, 16, 16, 1, 1, bmp_bits
, bmp_bits
);
815 ok(hIcon
!= 0, "CreateIcon failed\n");
816 test_icon_info(hIcon
, 16, 16, 32, 1);
819 hIcon
= CreateIcon(0, 16, 16, 1, display_bpp
, bmp_bits
, bmp_bits
);
820 ok(hIcon
!= 0, "CreateIcon failed\n");
821 test_icon_info(hIcon
, 16, 16, 16, display_bpp
);
824 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
825 ok(hbmMask
!= 0, "CreateBitmap failed\n");
826 hbmColor
= CreateBitmap(16, 16, 1, display_bpp
, bmp_bits
);
827 ok(hbmColor
!= 0, "CreateBitmap failed\n");
834 SetLastError(0xdeadbeaf);
835 hIcon
= CreateIconIndirect(&info
);
836 ok(!hIcon
, "CreateIconIndirect should fail\n");
837 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
843 info
.hbmColor
= hbmColor
;
844 SetLastError(0xdeadbeaf);
845 hIcon
= CreateIconIndirect(&info
);
846 ok(!hIcon
, "CreateIconIndirect should fail\n");
847 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
852 info
.hbmMask
= hbmMask
;
853 info
.hbmColor
= hbmColor
;
854 hIcon
= CreateIconIndirect(&info
);
855 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
856 test_icon_info(hIcon
, 16, 16, 16, display_bpp
);
859 DeleteObject(hbmMask
);
860 DeleteObject(hbmColor
);
862 hbmMask
= CreateBitmap(16, 32, 1, 1, bmp_bits
);
863 ok(hbmMask
!= 0, "CreateBitmap failed\n");
868 info
.hbmMask
= hbmMask
;
870 SetLastError(0xdeadbeaf);
871 hIcon
= CreateIconIndirect(&info
);
872 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
873 test_icon_info(hIcon
, 16, 16, 32, 1);
875 DeleteObject(hbmMask
);
877 for (i
= 0; i
<= 4; i
++)
879 hbmMask
= CreateBitmap(1, i
, 1, 1, bmp_bits
);
880 ok(hbmMask
!= 0, "CreateBitmap failed\n");
885 info
.hbmMask
= hbmMask
;
887 SetLastError(0xdeadbeaf);
888 hIcon
= CreateIconIndirect(&info
);
889 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
890 test_icon_info(hIcon
, 1, i
/ 2, max(i
,1), 1);
892 DeleteObject(hbmMask
);
895 /* test creating an icon from a DIB section */
897 bmpinfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, FIELD_OFFSET(BITMAPINFO
,bmiColors
[256]));
898 bmpinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
899 bmpinfo
->bmiHeader
.biWidth
= 32;
900 bmpinfo
->bmiHeader
.biHeight
= 32;
901 bmpinfo
->bmiHeader
.biPlanes
= 1;
902 bmpinfo
->bmiHeader
.biBitCount
= 8;
903 bmpinfo
->bmiHeader
.biCompression
= BI_RGB
;
904 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
905 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
907 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
908 bmpinfo
->bmiHeader
.biBitCount
= 1;
909 hbmMask
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
910 ok(hbmMask
!= NULL
, "Expected a handle to the DIB\n");
912 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
917 info
.hbmMask
= hbmColor
;
918 info
.hbmColor
= hbmMask
;
919 SetLastError(0xdeadbeaf);
920 hIcon
= CreateIconIndirect(&info
);
921 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
922 test_icon_info(hIcon
, 32, 32, 32, 8);
924 DeleteObject(hbmColor
);
926 bmpinfo
->bmiHeader
.biBitCount
= 16;
927 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
928 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
930 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
935 info
.hbmMask
= hbmColor
;
936 info
.hbmColor
= hbmMask
;
937 SetLastError(0xdeadbeaf);
938 hIcon
= CreateIconIndirect(&info
);
939 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
940 test_icon_info(hIcon
, 32, 32, 32, 8);
942 DeleteObject(hbmColor
);
944 bmpinfo
->bmiHeader
.biBitCount
= 32;
945 hbmColor
= CreateDIBSection( hdc
, bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
946 ok(hbmColor
!= NULL
, "Expected a handle to the DIB\n");
948 memset( bits
, 0x55, 32 * 32 * bmpinfo
->bmiHeader
.biBitCount
/ 8 );
953 info
.hbmMask
= hbmColor
;
954 info
.hbmColor
= hbmMask
;
955 SetLastError(0xdeadbeaf);
956 hIcon
= CreateIconIndirect(&info
);
957 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
958 test_icon_info(hIcon
, 32, 32, 32, 8);
961 DeleteObject(hbmMask
);
962 DeleteObject(hbmColor
);
963 HeapFree( GetProcessHeap(), 0, bmpinfo
);
968 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
970 static const unsigned char gifimage
[35] = {
971 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
972 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
977 static const unsigned char jpgimage
[285] = {
978 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
979 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
980 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
981 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
982 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
983 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
984 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
985 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
986 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
987 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
988 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
989 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
990 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
991 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
992 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
993 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
994 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
995 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
999 static const unsigned char pngimage
[285] = {
1000 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1001 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1002 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1003 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1004 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1005 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1006 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1009 /* 1x1 pixel bmp with gap between palette and bitmap. Correct bitmap contains only
1010 zeroes, gap is 0xFF. */
1011 static unsigned char bmpimage
[70] = {
1012 0x42,0x4d,0x46,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x42,0x00,0x00,0x00,0x28,0x00,
1013 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1014 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1015 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0x55,0x55,0x55,0x00,0xFF,0xFF,
1016 0xFF,0xFF,0x00,0x00,0x00,0x00
1019 /* 1x1 pixel bmp using BITMAPCOREHEADER */
1020 static const unsigned char bmpcoreimage
[38] = {
1021 0x42,0x4d,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x0c,0x00,
1022 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xff,0xff,0x00,0x55,0x55,
1023 0x55,0x00,0x00,0x00,0x00,0x00
1027 static const unsigned char gif4pixel
[42] = {
1028 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1029 0x39,0x62,0xfc,0xff,0x1a,0xe5,0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x02,0x00,
1030 0x02,0x00,0x00,0x02,0x03,0x14,0x16,0x05,0x00,0x3b
1033 static const DWORD biSize_tests
[] = {
1035 sizeof(BITMAPCOREHEADER
) - 1,
1036 sizeof(BITMAPCOREHEADER
) + 1,
1037 sizeof(BITMAPINFOHEADER
) - 1,
1038 sizeof(BITMAPINFOHEADER
) + 1,
1039 sizeof(BITMAPV4HEADER
) - 1,
1040 sizeof(BITMAPV4HEADER
) + 1,
1041 sizeof(BITMAPV5HEADER
) - 1,
1042 sizeof(BITMAPV5HEADER
) + 1,
1043 (sizeof(BITMAPCOREHEADER
) + sizeof(BITMAPINFOHEADER
)) / 2,
1044 (sizeof(BITMAPV4HEADER
) + sizeof(BITMAPV5HEADER
)) / 2,
1049 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1051 static void test_LoadImageBitmap(const char * test_desc
, HBITMAP hbm
)
1055 DWORD ret
, pixel
= 0;
1056 HDC hdc
= GetDC(NULL
);
1058 ret
= GetObjectA(hbm
, sizeof(bm
), &bm
);
1059 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
1061 memset(&bmi
, 0, sizeof(bmi
));
1062 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
1063 bmi
.bmiHeader
.biWidth
= bm
.bmWidth
;
1064 bmi
.bmiHeader
.biHeight
= bm
.bmHeight
;
1065 bmi
.bmiHeader
.biPlanes
= 1;
1066 bmi
.bmiHeader
.biBitCount
= 24;
1067 bmi
.bmiHeader
.biCompression
= BI_RGB
;
1068 ret
= GetDIBits(hdc
, hbm
, 0, bm
.bmHeight
, &pixel
, &bmi
, DIB_RGB_COLORS
);
1069 ok(ret
== bm
.bmHeight
, "%s: %d lines were converted, not %d\n", test_desc
, ret
, bm
.bmHeight
);
1071 ok(color_match(pixel
, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc
, pixel
);
1074 static void test_LoadImageFile(const char * test_desc
, const unsigned char * image_data
,
1075 unsigned int image_size
, const char * ext
, BOOL expect_success
)
1079 DWORD error
, bytes_written
;
1082 strcpy(filename
, "test.");
1083 strcat(filename
, ext
);
1085 /* Create the test image. */
1086 handle
= CreateFileA(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_NEW
,
1087 FILE_ATTRIBUTE_NORMAL
, NULL
);
1088 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileA failed. %u\n", GetLastError());
1089 ret
= WriteFile(handle
, image_data
, image_size
, &bytes_written
, NULL
);
1090 ok(ret
&& bytes_written
== image_size
, "test file created improperly.\n");
1091 CloseHandle(handle
);
1093 /* Load as cursor. For all tested formats, this should fail */
1094 SetLastError(0xdeadbeef);
1095 handle
= LoadImageA(NULL
, filename
, IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
1096 ok(handle
== NULL
, "%s: IMAGE_CURSOR succeeded incorrectly.\n", test_desc
);
1097 error
= GetLastError();
1099 broken(error
== 0xdeadbeef) || /* Win9x */
1100 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1101 "Last error: %u\n", error
);
1102 if (handle
!= NULL
) DestroyCursor(handle
);
1104 /* Load as icon. For all tested formats, this should fail */
1105 SetLastError(0xdeadbeef);
1106 handle
= LoadImageA(NULL
, filename
, IMAGE_ICON
, 0, 0, LR_LOADFROMFILE
);
1107 ok(handle
== NULL
, "%s: IMAGE_ICON succeeded incorrectly.\n", test_desc
);
1108 error
= GetLastError();
1110 broken(error
== 0xdeadbeef) || /* Win9x */
1111 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1112 "Last error: %u\n", error
);
1113 if (handle
!= NULL
) DestroyIcon(handle
);
1115 /* Load as bitmap. Should succeed for correct bmp, fail for everything else */
1116 SetLastError(0xdeadbeef);
1117 handle
= LoadImageA(NULL
, filename
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
);
1118 error
= GetLastError();
1120 error
== 0xdeadbeef, /* Win9x, WinMe */
1121 "Last error: %u\n", error
);
1123 if (expect_success
) {
1124 ok(handle
!= NULL
, "%s: IMAGE_BITMAP failed.\n", test_desc
);
1125 if (handle
!= NULL
) test_LoadImageBitmap(test_desc
, handle
);
1127 else ok(handle
== NULL
, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc
);
1129 if (handle
!= NULL
) DeleteObject(handle
);
1130 DeleteFileA(filename
);
1133 static void test_LoadImage(void)
1137 DWORD error
, bytes_written
;
1138 CURSORICONFILEDIR
*icon_data
;
1139 CURSORICONFILEDIRENTRY
*icon_entry
;
1140 BITMAPINFOHEADER
*icon_header
, *bitmap_header
;
1144 #define ICON_WIDTH 32
1145 #define ICON_HEIGHT 32
1146 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1149 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1150 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1152 /* Set icon data. */
1153 icon_data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ICON_SIZE
);
1154 icon_data
->idReserved
= 0;
1155 icon_data
->idType
= 1;
1156 icon_data
->idCount
= 1;
1158 icon_entry
= icon_data
->idEntries
;
1159 icon_entry
->bWidth
= ICON_WIDTH
;
1160 icon_entry
->bHeight
= ICON_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
= ICON_SIZE
- sizeof(CURSORICONFILEDIR
);
1166 icon_entry
->dwDIBOffset
= sizeof(CURSORICONFILEDIR
);
1168 icon_header
= (BITMAPINFOHEADER
*) ((BYTE
*) icon_data
+ icon_entry
->dwDIBOffset
);
1169 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1170 icon_header
->biWidth
= ICON_WIDTH
;
1171 icon_header
->biHeight
= ICON_HEIGHT
*2;
1172 icon_header
->biPlanes
= 1;
1173 icon_header
->biBitCount
= ICON_BPP
;
1174 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1176 /* Create the icon. */
1177 handle
= CreateFileA("icon.ico", GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_NEW
,
1178 FILE_ATTRIBUTE_NORMAL
, NULL
);
1179 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFileA failed. %u\n", GetLastError());
1180 ret
= WriteFile(handle
, icon_data
, ICON_SIZE
, &bytes_written
, NULL
);
1181 ok(ret
&& bytes_written
== ICON_SIZE
, "icon.ico created improperly.\n");
1182 CloseHandle(handle
);
1184 /* Test loading an icon as a cursor. */
1185 SetLastError(0xdeadbeef);
1186 handle
= LoadImageA(NULL
, "icon.ico", IMAGE_CURSOR
, 0, 0, LR_LOADFROMFILE
);
1187 ok(handle
!= NULL
, "LoadImage() failed.\n");
1188 error
= GetLastError();
1190 broken(error
== 0xdeadbeef) || /* Win9x */
1191 broken(error
== ERROR_BAD_PATHNAME
), /* Win98, WinMe */
1192 "Last error: %u\n", error
);
1194 /* Test the icon information. */
1195 SetLastError(0xdeadbeef);
1196 ret
= GetIconInfo(handle
, &icon_info
);
1197 ok(ret
, "GetIconInfo() failed.\n");
1198 error
= GetLastError();
1199 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1203 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1204 ok(icon_info
.xHotspot
== 1, "xHotspot is %u.\n", icon_info
.xHotspot
);
1205 ok(icon_info
.yHotspot
== 1, "yHotspot is %u.\n", icon_info
.yHotspot
);
1206 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1208 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1211 if (pGetIconInfoExA
)
1214 infoex
.cbSize
= sizeof(infoex
);
1215 ret
= pGetIconInfoExA( handle
, &infoex
);
1216 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1217 ok( infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
1218 ok( infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
1219 ok( infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
1221 else win_skip( "GetIconInfoEx not available\n" );
1224 SetLastError(0xdeadbeef);
1225 ret
= DestroyCursor(handle
);
1226 ok(ret
, "DestroyCursor() failed.\n");
1227 error
= GetLastError();
1228 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1230 HeapFree(GetProcessHeap(), 0, icon_data
);
1231 DeleteFileA("icon.ico");
1233 /* Test a system icon */
1234 handle
= LoadIconA( 0, (LPCSTR
)IDI_HAND
);
1235 ok(handle
!= NULL
, "LoadImage() failed.\n");
1236 if (pGetIconInfoExA
)
1238 ICONINFOEXA infoexA
;
1239 ICONINFOEXW infoexW
;
1240 infoexA
.cbSize
= sizeof(infoexA
);
1241 ret
= pGetIconInfoExA( handle
, &infoexA
);
1242 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1243 ok( infoexA
.wResID
== (UINT_PTR
)IDI_HAND
, "GetIconInfoEx wrong resid %x\n", infoexA
.wResID
);
1244 /* the A version is broken on 64-bit, it truncates the string after the first char */
1245 if (is_win64
&& infoexA
.szModName
[0] && infoexA
.szModName
[1] == 0)
1246 trace( "GetIconInfoExA broken on Win64\n" );
1248 ok( GetModuleHandleA(infoexA
.szModName
) == GetModuleHandleA("user32.dll"),
1249 "GetIconInfoEx wrong module %s\n", infoexA
.szModName
);
1250 ok( infoexA
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoexA
.szResName
);
1251 infoexW
.cbSize
= sizeof(infoexW
);
1252 ret
= pGetIconInfoExW( handle
, &infoexW
);
1253 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1254 ok( infoexW
.wResID
== (UINT_PTR
)IDI_HAND
, "GetIconInfoEx wrong resid %x\n", infoexW
.wResID
);
1255 ok( GetModuleHandleW(infoexW
.szModName
) == GetModuleHandleA("user32.dll"),
1256 "GetIconInfoEx wrong module %s\n", wine_dbgstr_w(infoexW
.szModName
) );
1257 ok( infoexW
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", wine_dbgstr_w(infoexW
.szResName
) );
1259 SetLastError(0xdeadbeef);
1260 DestroyIcon(handle
);
1262 test_LoadImageFile("BMP", bmpimage
, sizeof(bmpimage
), "bmp", 1);
1263 test_LoadImageFile("BMP (coreinfo)", bmpcoreimage
, sizeof(bmpcoreimage
), "bmp", 1);
1264 test_LoadImageFile("GIF", gifimage
, sizeof(gifimage
), "gif", 0);
1265 test_LoadImageFile("GIF (2x2 pixel)", gif4pixel
, sizeof(gif4pixel
), "gif", 0);
1266 test_LoadImageFile("JPG", jpgimage
, sizeof(jpgimage
), "jpg", 0);
1267 test_LoadImageFile("PNG", pngimage
, sizeof(pngimage
), "png", 0);
1269 /* Check failure for broken BMP images */
1270 bitmap_header
= (BITMAPINFOHEADER
*)(bmpimage
+ sizeof(BITMAPFILEHEADER
));
1272 bitmap_header
->biHeight
= 65536;
1273 test_LoadImageFile("BMP (too high)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1274 bitmap_header
->biHeight
= 1;
1276 bitmap_header
->biWidth
= 65536;
1277 test_LoadImageFile("BMP (too wide)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1278 bitmap_header
->biWidth
= 1;
1280 for (i
= 0; i
< ARRAY_SIZE(biSize_tests
); i
++) {
1281 bitmap_header
->biSize
= biSize_tests
[i
];
1282 test_LoadImageFile("BMP (broken biSize)", bmpimage
, sizeof(bmpimage
), "bmp", 0);
1284 bitmap_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1289 static void test_CreateIconFromResource(void)
1294 BITMAPINFOHEADER
*icon_header
;
1298 #define ICON_RES_WIDTH 32
1299 #define ICON_RES_HEIGHT 32
1300 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1301 #define ICON_RES_BPP 32
1302 #define ICON_RES_SIZE \
1303 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1304 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1306 /* Set icon data. */
1307 hotspot
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, CRSR_RES_SIZE
);
1309 /* Cursor resources have an extra hotspot, icon resources not. */
1313 icon_header
= (BITMAPINFOHEADER
*) (hotspot
+ 2);
1314 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1315 icon_header
->biWidth
= ICON_WIDTH
;
1316 icon_header
->biHeight
= ICON_HEIGHT
*2;
1317 icon_header
->biPlanes
= 1;
1318 icon_header
->biBitCount
= ICON_BPP
;
1319 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1321 /* Test creating a cursor. */
1322 SetLastError(0xdeadbeef);
1323 handle
= CreateIconFromResource((PBYTE
) hotspot
, CRSR_RES_SIZE
, FALSE
, 0x00030000);
1324 ok(handle
!= NULL
, "Create cursor failed.\n");
1326 /* Test the icon information. */
1327 SetLastError(0xdeadbeef);
1328 ret
= GetIconInfo(handle
, &icon_info
);
1329 ok(ret
, "GetIconInfo() failed.\n");
1330 error
= GetLastError();
1331 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1335 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1336 ok(icon_info
.xHotspot
== 3, "xHotspot is %u.\n", icon_info
.xHotspot
);
1337 ok(icon_info
.yHotspot
== 3, "yHotspot is %u.\n", icon_info
.yHotspot
);
1338 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1340 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1343 if (pGetIconInfoExA
)
1346 infoex
.cbSize
= sizeof(infoex
);
1347 ret
= pGetIconInfoExA( handle
, &infoex
);
1348 ok( ret
, "GetIconInfoEx failed err %d\n", GetLastError() );
1349 ok( infoex
.wResID
== 0, "GetIconInfoEx wrong resid %x\n", infoex
.wResID
);
1350 ok( infoex
.szModName
[0] == 0, "GetIconInfoEx wrong module %s\n", infoex
.szModName
);
1351 ok( infoex
.szResName
[0] == 0, "GetIconInfoEx wrong name %s\n", infoex
.szResName
);
1355 SetLastError(0xdeadbeef);
1356 ret
= DestroyCursor(handle
);
1357 ok(ret
, "DestroyCursor() failed.\n");
1358 error
= GetLastError();
1359 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1361 /* Test creating an icon. */
1362 SetLastError(0xdeadbeef);
1363 handle
= CreateIconFromResource((PBYTE
) icon_header
, ICON_RES_SIZE
, TRUE
,
1365 ok(handle
!= NULL
, "Create icon failed.\n");
1367 /* Test the icon information. */
1368 SetLastError(0xdeadbeef);
1369 ret
= GetIconInfo(handle
, &icon_info
);
1370 ok(ret
, "GetIconInfo() failed.\n");
1371 error
= GetLastError();
1372 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1376 ok(icon_info
.fIcon
== TRUE
, "fIcon != TRUE.\n");
1377 /* Icons always have hotspot in the middle */
1378 ok(icon_info
.xHotspot
== ICON_WIDTH
/2, "xHotspot is %u.\n", icon_info
.xHotspot
);
1379 ok(icon_info
.yHotspot
== ICON_HEIGHT
/2, "yHotspot is %u.\n", icon_info
.yHotspot
);
1380 ok(icon_info
.hbmColor
!= NULL
, "No hbmColor!\n");
1381 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1385 SetLastError(0xdeadbeef);
1386 ret
= DestroyCursor(handle
);
1387 ok(ret
, "DestroyCursor() failed.\n");
1388 error
= GetLastError();
1389 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1391 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1393 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1394 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1396 HeapFree(GetProcessHeap(), 0, hotspot
);
1398 /* Test creating an animated cursor. */
1399 empty_anicursor
.frames
[0].data
.icon_info
.idType
= 2; /* type: cursor */
1400 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1401 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1402 handle
= CreateIconFromResource((PBYTE
) &empty_anicursor
, sizeof(empty_anicursor
), FALSE
, 0x00030000);
1403 ok(handle
!= NULL
, "Create cursor failed.\n");
1405 /* Test the animated cursor's information. */
1406 SetLastError(0xdeadbeef);
1407 ret
= GetIconInfo(handle
, &icon_info
);
1408 ok(ret
, "GetIconInfo() failed.\n");
1409 error
= GetLastError();
1410 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1414 ok(icon_info
.fIcon
== FALSE
, "fIcon != FALSE.\n");
1415 ok(icon_info
.xHotspot
== 3, "xHotspot is %u.\n", icon_info
.xHotspot
);
1416 ok(icon_info
.yHotspot
== 3, "yHotspot is %u.\n", icon_info
.yHotspot
);
1417 ok(icon_info
.hbmColor
!= NULL
|| broken(!icon_info
.hbmColor
) /* no color cursor support */,
1419 ok(icon_info
.hbmMask
!= NULL
, "No hbmMask!\n");
1423 SetLastError(0xdeadbeef);
1424 ret
= DestroyCursor(handle
);
1425 ok(ret
, "DestroyCursor() failed.\n");
1426 error
= GetLastError();
1427 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
1430 static int check_cursor_data( HDC hdc
, HCURSOR hCursor
, void *data
, int length
)
1438 ret
= GetIconInfo( hCursor
, &iinfo
);
1439 ok(ret
, "GetIconInfo() failed\n");
1442 info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] ));
1443 ok(info
!= NULL
, "HeapAlloc() failed\n");
1444 if (!info
) return 0;
1446 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1447 info
->bmiHeader
.biWidth
= 32;
1448 info
->bmiHeader
.biHeight
= 32;
1449 info
->bmiHeader
.biPlanes
= 1;
1450 info
->bmiHeader
.biBitCount
= 32;
1451 info
->bmiHeader
.biCompression
= BI_RGB
;
1452 info
->bmiHeader
.biSizeImage
= 32 * 32 * 4;
1453 info
->bmiHeader
.biXPelsPerMeter
= 0;
1454 info
->bmiHeader
.biYPelsPerMeter
= 0;
1455 info
->bmiHeader
.biClrUsed
= 0;
1456 info
->bmiHeader
.biClrImportant
= 0;
1457 image
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
);
1458 ok(image
!= NULL
, "HeapAlloc() failed\n");
1459 if (!image
) goto cleanup
;
1460 ret
= GetDIBits( hdc
, iinfo
.hbmColor
, 0, 32, image
, info
, DIB_RGB_COLORS
);
1461 ok(ret
, "GetDIBits() failed\n");
1462 for (i
= 0; ret
&& i
< length
/ sizeof(COLORREF
); i
++)
1464 ret
= color_match( ((COLORREF
*)data
)[i
], ((COLORREF
*)image
)[i
] );
1465 ok(ret
, "%04x: Expected 0x%x, actually 0x%x\n", i
, ((COLORREF
*)data
)[i
], ((COLORREF
*)image
)[i
] );
1468 HeapFree( GetProcessHeap(), 0, image
);
1469 HeapFree( GetProcessHeap(), 0, info
);
1473 static HCURSOR (WINAPI
*pGetCursorFrameInfo
)(HCURSOR hCursor
, DWORD unk1
, DWORD istep
, DWORD
*rate
, DWORD
*steps
);
1474 static void test_GetCursorFrameInfo(void)
1476 DWORD frame_identifier
[] = { 0x10Ad, 0xc001, 0x1c05 };
1477 HBITMAP bmp
= NULL
, bmpOld
= NULL
;
1479 BITMAPINFOHEADER
*icon_header
;
1480 BITMAPINFO bitmapInfo
;
1488 if (!pGetCursorFrameInfo
)
1490 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1494 hdc
= CreateCompatibleDC(0);
1495 ok(hdc
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1499 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1500 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1501 bitmapInfo
.bmiHeader
.biWidth
= 3;
1502 bitmapInfo
.bmiHeader
.biHeight
= 3;
1503 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1504 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1505 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1506 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1507 bmp
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1508 ok (bmp
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1511 bmpOld
= SelectObject(hdc
, bmp
);
1513 #define ICON_RES_WIDTH 32
1514 #define ICON_RES_HEIGHT 32
1515 #define ICON_RES_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1516 #define ICON_RES_BPP 32
1517 #define ICON_RES_SIZE \
1518 (sizeof(BITMAPINFOHEADER) + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1519 #define CRSR_RES_SIZE (2*sizeof(INT16) + ICON_RES_SIZE)
1521 /* Set icon data. */
1522 hotspot
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, CRSR_RES_SIZE
);
1524 /* Cursor resources have an extra hotspot, icon resources not. */
1528 icon_header
= (BITMAPINFOHEADER
*) (hotspot
+ 2);
1529 icon_header
->biSize
= sizeof(BITMAPINFOHEADER
);
1530 icon_header
->biWidth
= ICON_WIDTH
;
1531 icon_header
->biHeight
= ICON_HEIGHT
*2;
1532 icon_header
->biPlanes
= 1;
1533 icon_header
->biBitCount
= ICON_BPP
;
1534 icon_header
->biSizeImage
= 0; /* Uncompressed bitmap. */
1536 /* Creating a static cursor. */
1537 SetLastError(0xdeadbeef);
1538 h1
= CreateIconFromResource((PBYTE
) hotspot
, CRSR_RES_SIZE
, FALSE
, 0x00030000);
1539 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1541 /* Check GetCursorFrameInfo behavior on a static cursor */
1542 rate
= steps
= 0xdead;
1543 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0xdead, &rate
, &steps
);
1544 ok(h1
== h2
, "GetCursorFrameInfo() failed: (%p != %p).\n", h1
, h2
);
1545 ok(rate
== 0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate
);
1546 ok(steps
== 1, "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps
);
1548 /* Clean up static cursor. */
1549 SetLastError(0xdeadbeef);
1550 ret
= DestroyCursor(h1
);
1551 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1553 /* Creating a single-frame animated cursor. */
1554 empty_anicursor
.frames
[0].data
.icon_info
.idType
= 2; /* type: cursor */
1555 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1556 empty_anicursor
.frames
[0].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1557 memcpy( &empty_anicursor
.frames
[0].data
.bmi_data
.data
[0], &frame_identifier
[0], sizeof(DWORD
) );
1558 SetLastError(0xdeadbeef);
1559 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor
, sizeof(empty_anicursor
), FALSE
, 0x00030000);
1560 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1562 /* Check GetCursorFrameInfo behavior on a single-frame animated cursor */
1563 rate
= steps
= 0xdead;
1564 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0, &rate
, &steps
);
1565 ok(h1
== h2
, "GetCursorFrameInfo() failed: (%p != %p).\n", h1
, h2
);
1566 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[0], sizeof(DWORD
) );
1567 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1568 ok(rate
== 0x0, "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x0).\n", rate
);
1569 ok(steps
== empty_anicursor
.header
.header
.num_steps
,
1570 "GetCursorFrameInfo() unexpected param 5 value (%d != 1).\n", steps
);
1572 /* Clean up single-frame animated cursor. */
1573 SetLastError(0xdeadbeef);
1574 ret
= DestroyCursor(h1
);
1575 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1577 /* Creating a multi-frame animated cursor. */
1578 for (i
=0; i
<empty_anicursor3
.header
.header
.num_frames
; i
++)
1580 empty_anicursor3
.frames
[i
].data
.icon_info
.idType
= 2; /* type: cursor */
1581 empty_anicursor3
.frames
[i
].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1582 empty_anicursor3
.frames
[i
].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1583 memcpy( &empty_anicursor3
.frames
[i
].data
.bmi_data
.data
[0], &frame_identifier
[i
], sizeof(DWORD
) );
1585 SetLastError(0xdeadbeef);
1586 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3
, sizeof(empty_anicursor3
), FALSE
, 0x00030000);
1587 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1589 /* Check number of steps in multi-frame animated cursor */
1591 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1593 ok(i
== empty_anicursor3
.header
.header
.num_steps
,
1594 "Unexpected number of steps in cursor (%d != %d)\n",
1595 i
, empty_anicursor3
.header
.header
.num_steps
);
1597 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1598 for (i
=0; i
<empty_anicursor3
.header
.header
.num_frames
; i
++)
1600 rate
= steps
= 0xdead;
1601 h2
= pGetCursorFrameInfo(h1
, 0xdead, i
, &rate
, &steps
);
1602 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1603 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[i
], sizeof(DWORD
) );
1604 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i
);
1605 ok(rate
== empty_anicursor3
.header
.header
.display_rate
,
1606 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1607 rate
, empty_anicursor3
.header
.header
.display_rate
);
1608 ok(steps
== empty_anicursor3
.header
.header
.num_steps
,
1609 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1610 steps
, empty_anicursor3
.header
.header
.num_steps
);
1613 /* Check GetCursorFrameInfo behavior on rate 3 of a multi-frame animated cursor */
1614 rate
= steps
= 0xdead;
1615 h2
= pGetCursorFrameInfo(h1
, 0xdead, 3, &rate
, &steps
);
1616 ok(h2
== 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1
, h2
);
1617 ok(rate
== 0xdead || broken(rate
== empty_anicursor3
.header
.header
.display_rate
) /*win2k*/
1618 || broken(rate
== ~0) /*win2k (sporadic)*/,
1619 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate
);
1620 ok(steps
== 0xdead || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/
1621 || broken(steps
== 0) /*win2k (sporadic)*/,
1622 "GetCursorFrameInfo() unexpected param 5 value (0x%x != 0xdead).\n", steps
);
1624 /* Clean up multi-frame animated cursor. */
1625 SetLastError(0xdeadbeef);
1626 ret
= DestroyCursor(h1
);
1627 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1629 /* Create a multi-frame animated cursor with num_steps == 1 */
1630 empty_anicursor3
.header
.header
.num_steps
= 1;
1631 SetLastError(0xdeadbeef);
1632 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3
, sizeof(empty_anicursor3
), FALSE
, 0x00030000);
1633 ok(h1
!= NULL
, "Create cursor failed (error = %d).\n", GetLastError());
1635 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1637 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1639 ok(i
== empty_anicursor3
.header
.header
.num_steps
,
1640 "Unexpected number of steps in cursor (%d != %d)\n",
1641 i
, empty_anicursor3
.header
.header
.num_steps
);
1643 /* Check GetCursorFrameInfo behavior on rate 0 for a multi-frame animated cursor (with num_steps == 1) */
1644 rate
= steps
= 0xdead;
1645 h2
= pGetCursorFrameInfo(h1
, 0xdead, 0, &rate
, &steps
);
1646 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1647 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[0], sizeof(DWORD
) );
1648 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame 0.\n");
1649 ok(rate
== empty_anicursor3
.header
.header
.display_rate
,
1650 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1651 rate
, empty_anicursor3
.header
.header
.display_rate
);
1652 ok(steps
== ~0 || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/,
1653 "GetCursorFrameInfo() unexpected param 5 value (%d != ~0).\n", steps
);
1655 /* Check GetCursorFrameInfo behavior on rate 1 for a multi-frame animated cursor (with num_steps == 1) */
1656 rate
= steps
= 0xdead;
1657 h2
= pGetCursorFrameInfo(h1
, 0xdead, 1, &rate
, &steps
);
1658 ok(h2
== 0, "GetCursorFrameInfo() failed for cursor %p: (%p != 0).\n", h1
, h2
);
1659 ok(rate
== 0xdead || broken(rate
== empty_anicursor3
.header
.header
.display_rate
) /*win2k*/
1660 || broken(rate
== ~0) /*win2k (sporadic)*/,
1661 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0xdead).\n", rate
);
1662 ok(steps
== 0xdead || broken(steps
== empty_anicursor3
.header
.header
.num_steps
) /*win2k*/
1663 || broken(steps
== 0) /*win2k (sporadic)*/,
1664 "GetCursorFrameInfo() unexpected param 5 value (%d != 0xdead).\n", steps
);
1666 /* Clean up multi-frame animated cursor. */
1667 SetLastError(0xdeadbeef);
1668 ret
= DestroyCursor(h1
);
1669 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1671 /* Creating a multi-frame animated cursor with rate data. */
1672 for (i
=0; i
<empty_anicursor3_seq
.header
.header
.num_frames
; i
++)
1674 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idType
= 2; /* type: cursor */
1675 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idEntries
[0].xHotspot
= 3;
1676 empty_anicursor3_seq
.frames
[i
].data
.icon_info
.idEntries
[0].yHotspot
= 3;
1677 memcpy( &empty_anicursor3_seq
.frames
[i
].data
.bmi_data
.data
[0], &frame_identifier
[i
], sizeof(DWORD
) );
1679 SetLastError(0xdeadbeef);
1680 h1
= CreateIconFromResource((PBYTE
) &empty_anicursor3_seq
, sizeof(empty_anicursor3_seq
), FALSE
, 0x00030000);
1681 ok(h1
!= NULL
, "Create cursor failed (error = %x).\n", GetLastError());
1683 /* Check number of steps in multi-frame animated cursor with rate data */
1685 while (DrawIconEx(hdc
, 0, 0, h1
, 32, 32, i
, NULL
, DI_NORMAL
))
1687 ok(i
== empty_anicursor3_seq
.header
.header
.num_steps
,
1688 "Unexpected number of steps in cursor (%d != %d)\n",
1689 i
, empty_anicursor3_seq
.header
.header
.num_steps
);
1691 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor with rate data */
1692 for (i
=0; i
<empty_anicursor3_seq
.header
.header
.num_frames
; i
++)
1694 int frame_id
= empty_anicursor3_seq
.seq
.order
[i
];
1696 rate
= steps
= 0xdead;
1697 h2
= pGetCursorFrameInfo(h1
, 0xdead, i
, &rate
, &steps
);
1698 ok(h1
!= h2
&& h2
!= 0, "GetCursorFrameInfo() failed for cursor %p: (%p, %p).\n", h1
, h1
, h2
);
1699 ret
= check_cursor_data( hdc
, h2
, &frame_identifier
[frame_id
], sizeof(DWORD
) );
1700 ok(ret
, "GetCursorFrameInfo() returned wrong cursor data for frame %d.\n", i
);
1701 ok(rate
== empty_anicursor3_seq
.rates
.rate
[i
],
1702 "GetCursorFrameInfo() unexpected param 4 value (0x%x != 0x%x).\n",
1703 rate
, empty_anicursor3_seq
.rates
.rate
[i
]);
1704 ok(steps
== empty_anicursor3_seq
.header
.header
.num_steps
,
1705 "GetCursorFrameInfo() unexpected param 5 value (%d != %d).\n",
1706 steps
, empty_anicursor3_seq
.header
.header
.num_steps
);
1709 /* Clean up multi-frame animated cursor with rate data. */
1710 SetLastError(0xdeadbeef);
1711 ret
= DestroyCursor(h1
);
1712 ok(ret
, "DestroyCursor() failed (error = %d).\n", GetLastError());
1714 HeapFree(GetProcessHeap(), 0, hotspot
);
1716 if(bmpOld
) SelectObject(hdc
, bmpOld
);
1717 if(bmp
) DeleteObject(bmp
);
1718 if(hdc
) DeleteDC(hdc
);
1721 static HICON
create_test_icon(HDC hdc
, int width
, int height
, int bpp
,
1722 BOOL maskvalue
, UINT32
*color
, int colorSize
)
1725 BITMAPINFO bitmapInfo
;
1726 void *buffer
= NULL
;
1727 UINT32 mask
= maskvalue
? 0xFFFFFFFF : 0x00000000;
1729 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1730 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1731 bitmapInfo
.bmiHeader
.biWidth
= width
;
1732 bitmapInfo
.bmiHeader
.biHeight
= height
;
1733 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1734 bitmapInfo
.bmiHeader
.biBitCount
= bpp
;
1735 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1736 bitmapInfo
.bmiHeader
.biSizeImage
= colorSize
;
1738 iconInfo
.fIcon
= TRUE
;
1739 iconInfo
.xHotspot
= 0;
1740 iconInfo
.yHotspot
= 0;
1742 iconInfo
.hbmMask
= CreateBitmap( width
, height
, 1, 1, &mask
);
1743 if(!iconInfo
.hbmMask
) return NULL
;
1745 iconInfo
.hbmColor
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, &buffer
, NULL
, 0);
1746 if(!iconInfo
.hbmColor
|| !buffer
)
1748 DeleteObject(iconInfo
.hbmMask
);
1752 memcpy(buffer
, color
, colorSize
);
1754 return CreateIconIndirect(&iconInfo
);
1757 static void check_alpha_draw(HDC hdc
, BOOL drawiconex
, BOOL alpha
, int bpp
, int line
)
1761 COLORREF modern_expected
, legacy_expected
, result
;
1763 color
[0] = 0x00A0B0C0;
1764 color
[1] = alpha
? 0xFF000000 : 0x00000000;
1765 modern_expected
= alpha
? 0x00FFFFFF : 0x00C0B0A0;
1766 legacy_expected
= 0x00C0B0A0;
1768 hicon
= create_test_icon(hdc
, 2, 1, bpp
, 0, color
, sizeof(color
));
1771 SetPixelV(hdc
, 0, 0, 0x00FFFFFF);
1774 DrawIconEx(hdc
, 0, 0, hicon
, 2, 1, 0, NULL
, DI_NORMAL
);
1776 DrawIcon(hdc
, 0, 0, hicon
);
1778 result
= GetPixel(hdc
, 0, 0);
1779 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1780 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1781 "%s. Expected a close match to %06X (modern) or %06X (legacy) with %s. "
1782 "Got %06X from line %d\n",
1783 alpha
? "Alpha blending" : "Not alpha blending", modern_expected
, legacy_expected
,
1784 drawiconex
? "DrawIconEx" : "DrawIcon", result
, line
);
1787 static void check_DrawIcon(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, COLORREF background
,
1788 COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
1791 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
1793 SetPixelV(hdc
, 0, 0, background
);
1794 SetPixelV(hdc
, GetSystemMetrics(SM_CXICON
)-1, GetSystemMetrics(SM_CYICON
)-1, background
);
1795 SetPixelV(hdc
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
), background
);
1796 DrawIcon(hdc
, 0, 0, hicon
);
1797 result
= GetPixel(hdc
, 0, 0);
1799 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1800 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1801 "Overlaying Mask %d on Color %06X with DrawIcon. "
1802 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1803 maskvalue
, color
, modern_expected
, legacy_expected
, result
, line
);
1805 result
= GetPixel(hdc
, GetSystemMetrics(SM_CXICON
)-1, GetSystemMetrics(SM_CYICON
)-1);
1807 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1808 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1809 "Overlaying Mask %d on Color %06X with DrawIcon. "
1810 "Expected a close match to %06X (modern), or %06X (legacy). Got %06X from line %d\n",
1811 maskvalue
, color
, modern_expected
, legacy_expected
, result
, line
);
1813 result
= GetPixel(hdc
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
));
1815 ok (color_match(result
, background
),
1816 "Overlaying Mask %d on Color %06X with DrawIcon. "
1817 "Expected unchanged background color %06X. Got %06X from line %d\n",
1818 maskvalue
, color
, background
, result
, line
);
1821 static void test_DrawIcon(void)
1823 BITMAPINFO bitmapInfo
;
1825 HBITMAP bmpDst
= NULL
;
1826 HBITMAP bmpOld
= NULL
;
1829 hdcDst
= CreateCompatibleDC(0);
1830 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1834 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
1836 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1840 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1841 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1842 bitmapInfo
.bmiHeader
.biWidth
= GetSystemMetrics(SM_CXICON
)+1;
1843 bitmapInfo
.bmiHeader
.biHeight
= GetSystemMetrics(SM_CYICON
)+1;
1844 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1845 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1846 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1847 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1849 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1850 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1851 if (!bmpDst
|| !bits
)
1853 bmpOld
= SelectObject(hdcDst
, bmpDst
);
1855 /* Mask is only heeded if alpha channel is always zero */
1856 check_DrawIcon(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1857 check_DrawIcon(hdcDst
, TRUE
, 0x00A0B0C0, 32, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__
);
1859 /* Test alpha blending */
1860 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1861 check_DrawIcon(hdcDst
, FALSE
, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1862 check_DrawIcon(hdcDst
, TRUE
, 0xFFA0B0C0, 32, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__
);
1864 check_DrawIcon(hdcDst
, FALSE
, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1865 check_DrawIcon(hdcDst
, TRUE
, 0x80A0B0C0, 32, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1866 check_DrawIcon(hdcDst
, FALSE
, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__
);
1867 check_DrawIcon(hdcDst
, TRUE
, 0x80A0B0C0, 32, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__
);
1869 check_DrawIcon(hdcDst
, FALSE
, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1870 check_DrawIcon(hdcDst
, TRUE
, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1872 /* Test detecting of alpha channel */
1873 /* If a single pixel's alpha channel is non-zero, the icon
1874 will be alpha blended, otherwise it will be draw with
1876 check_alpha_draw(hdcDst
, FALSE
, FALSE
, 32, __LINE__
);
1877 check_alpha_draw(hdcDst
, FALSE
, TRUE
, 32, __LINE__
);
1881 SelectObject(hdcDst
, bmpOld
);
1883 DeleteObject(bmpDst
);
1888 static void check_DrawIconEx(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, UINT flags
, COLORREF background
,
1889 COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
1892 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
1894 SetPixelV(hdc
, 0, 0, background
);
1895 DrawIconEx(hdc
, 0, 0, hicon
, 1, 1, 0, NULL
, flags
);
1896 result
= GetPixel(hdc
, 0, 0);
1898 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
1899 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
1900 "Overlaying Mask %d on Color %06X with DrawIconEx flags %08X. "
1901 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
1902 maskvalue
, color
, flags
, modern_expected
, legacy_expected
, result
, line
);
1905 static void test_DrawIconEx(void)
1907 BITMAPINFO bitmapInfo
;
1909 HBITMAP bmpDst
= NULL
;
1910 HBITMAP bmpOld
= NULL
;
1913 hdcDst
= CreateCompatibleDC(0);
1914 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1918 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
1920 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1924 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
1925 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1926 bitmapInfo
.bmiHeader
.biWidth
= 1;
1927 bitmapInfo
.bmiHeader
.biHeight
= 1;
1928 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1929 bitmapInfo
.bmiHeader
.biPlanes
= 1;
1930 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
1931 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
1932 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1933 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1934 if (!bmpDst
|| !bits
)
1936 bmpOld
= SelectObject(hdcDst
, bmpDst
);
1938 /* Test null, image only, and mask only drawing */
1939 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__
);
1940 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, 0, 0x00102030, 0x00102030, 0x00102030, __LINE__
);
1942 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_MASK
, 0x00123456, 0x00000000, 0x00000000, __LINE__
);
1943 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_MASK
, 0x00123456, 0x00FFFFFF, 0x00FFFFFF, __LINE__
);
1945 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, DI_IMAGE
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1946 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, DI_IMAGE
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1948 /* Test normal drawing */
1949 check_DrawIconEx(hdcDst
, FALSE
, 0x00A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1950 check_DrawIconEx(hdcDst
, TRUE
, 0x00A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x003F4F5F, 0x003F4F5F, __LINE__
);
1951 check_DrawIconEx(hdcDst
, FALSE
, 0xFFA0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
1953 /* Test alpha blending */
1954 /* Windows 2000 and up will alpha blend, earlier Windows versions will not */
1955 check_DrawIconEx(hdcDst
, TRUE
, 0xFFA0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x003F4F5F, __LINE__
);
1957 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1958 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00000000, 0x00605850, 0x00C0B0A0, __LINE__
);
1959 check_DrawIconEx(hdcDst
, FALSE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00DFD7CF, 0x00C0B0A0, __LINE__
);
1960 check_DrawIconEx(hdcDst
, TRUE
, 0x80A0B0C0, 32, DI_NORMAL
, 0x00FFFFFF, 0x00DFD7CF, 0x003F4F5F, __LINE__
);
1962 check_DrawIconEx(hdcDst
, FALSE
, 0x01FFFFFF, 32, DI_NORMAL
, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1963 check_DrawIconEx(hdcDst
, TRUE
, 0x01FFFFFF, 32, DI_NORMAL
, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__
);
1965 /* Test detecting of alpha channel */
1966 /* If a single pixel's alpha channel is non-zero, the icon
1967 will be alpha blended, otherwise it will be draw with
1969 check_alpha_draw(hdcDst
, TRUE
, FALSE
, 32, __LINE__
);
1970 check_alpha_draw(hdcDst
, TRUE
, TRUE
, 32, __LINE__
);
1974 SelectObject(hdcDst
, bmpOld
);
1976 DeleteObject(bmpDst
);
1981 static void check_DrawState_Size(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, HBRUSH hbr
, UINT flags
, int line
)
1983 COLORREF result
, background
;
1985 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
1986 background
= 0x00FFFFFF;
1987 /* Set color of the 2 pixels that will be checked afterwards */
1988 SetPixelV(hdc
, 0, 0, background
);
1989 SetPixelV(hdc
, 2, 2, background
);
1991 /* Let DrawState calculate the size of the icon (it's 1x1) */
1992 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 0, 0, (DST_ICON
| flags
));
1994 result
= GetPixel(hdc
, 0, 0);
1995 passed
[0] = color_match(result
, background
);
1996 result
= GetPixel(hdc
, 2, 2);
1997 passed
[0] = passed
[0] & color_match(result
, background
);
1999 /* Check if manually specifying the icon size DOESN'T work */
2001 /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
2002 * size in which it should be ultimately drawn. Therefore giving
2003 * width/height 2x2 if the icon is only 1x1 pixels in size should
2004 * result in drawing it with size 1x1. The size parameters must be
2005 * ignored if a Icon has to be drawn! */
2006 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 2, 2, (DST_ICON
| flags
));
2008 result
= GetPixel(hdc
, 0, 0);
2009 passed
[1] = color_match(result
, background
);
2010 result
= GetPixel(hdc
, 2, 2);
2011 passed
[1] = passed
[0] & color_match(result
, background
);
2013 if(!passed
[0]&&!passed
[1])
2015 "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
2016 "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
2017 "Color %06X with flags %08X. Line %d\n",
2018 maskvalue
, color
, (DST_ICON
| flags
), line
);
2021 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2022 "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
2023 "Mask %d on Color %06X with flags %08X. Line %d\n",
2024 maskvalue
, color
, (DST_ICON
| flags
), line
);
2027 "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
2028 "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
2029 "Color %06X with flags %08X. Line %d\n",
2030 maskvalue
, color
, (DST_ICON
| flags
), line
);
2033 static void check_DrawState_Color(HDC hdc
, BOOL maskvalue
, UINT32 color
, int bpp
, HBRUSH hbr
, UINT flags
,
2034 COLORREF background
, COLORREF modern_expected
, COLORREF legacy_expected
, int line
)
2037 HICON hicon
= create_test_icon(hdc
, 1, 1, bpp
, maskvalue
, &color
, sizeof(color
));
2039 /* Set color of the pixel that will be checked afterwards */
2040 SetPixelV(hdc
, 1, 1, background
);
2042 DrawStateA(hdc
, hbr
, NULL
, (LPARAM
) hicon
, 0, 1, 1, 0, 0, ( DST_ICON
| flags
));
2044 /* Check the color of the pixel is correct */
2045 result
= GetPixel(hdc
, 1, 1);
2047 ok (color_match(result
, modern_expected
) || /* Windows 2000 and up */
2048 broken(color_match(result
, legacy_expected
)), /* Windows NT 4.0, 9X and below */
2049 "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
2050 "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
2051 maskvalue
, color
, (DST_ICON
| flags
), modern_expected
, legacy_expected
, result
, line
);
2054 static void test_DrawState(void)
2056 BITMAPINFO bitmapInfo
;
2058 HBITMAP bmpDst
= NULL
;
2059 HBITMAP bmpOld
= NULL
;
2062 hdcDst
= CreateCompatibleDC(0);
2063 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2067 if(GetDeviceCaps(hdcDst
, BITSPIXEL
) <= 8)
2069 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2073 memset(&bitmapInfo
, 0, sizeof(bitmapInfo
));
2074 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2075 bitmapInfo
.bmiHeader
.biWidth
= 3;
2076 bitmapInfo
.bmiHeader
.biHeight
= 3;
2077 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2078 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2079 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2080 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
2081 bmpDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2082 ok (bmpDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
2083 if (!bmpDst
|| !bits
)
2085 bmpOld
= SelectObject(hdcDst
, bmpDst
);
2087 /* potential flags to test with DrawState are: */
2088 /* DSS_DISABLED embosses the icon */
2089 /* DSS_MONO draw Icon using a brush as parameter 5 */
2090 /* DSS_NORMAL draw Icon without any modifications */
2091 /* DSS_UNION draw the Icon dithered */
2093 check_DrawState_Size(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, DSS_NORMAL
, __LINE__
);
2094 check_DrawState_Color(hdcDst
, FALSE
, 0x00A0B0C0, 32, 0, DSS_NORMAL
, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__
);
2098 SelectObject(hdcDst
, bmpOld
);
2100 DeleteObject(bmpDst
);
2105 static DWORD parent_id
;
2107 static DWORD CALLBACK
set_cursor_thread( void *arg
)
2111 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE
); /* create a msg queue */
2114 BOOL ret
= AttachThreadInput( GetCurrentThreadId(), parent_id
, TRUE
);
2115 ok( ret
, "AttachThreadInput failed\n" );
2117 if (arg
) ret
= SetCursor( (HCURSOR
)arg
);
2118 else ret
= GetCursor();
2119 return (DWORD_PTR
)ret
;
2122 static void test_SetCursor(void)
2124 static const BYTE bmp_bits
[4096];
2125 ICONINFO cursorInfo
;
2126 HCURSOR cursor
, old_cursor
, global_cursor
= 0;
2127 DWORD error
, id
, result
;
2135 memset( &info
, 0, sizeof(info
) );
2136 info
.cbSize
= sizeof(info
);
2137 if (!pGetCursorInfo( &info
))
2139 win_skip( "GetCursorInfo not working\n" );
2140 pGetCursorInfo
= NULL
;
2142 else global_cursor
= info
.hCursor
;
2144 cursor
= GetCursor();
2145 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2146 WaitForSingleObject( thread
, 1000 );
2147 GetExitCodeThread( thread
, &result
);
2148 ok( result
== (DWORD_PTR
)cursor
, "wrong thread cursor %x/%p\n", result
, cursor
);
2151 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
2154 cursorInfo
.fIcon
= FALSE
;
2155 cursorInfo
.xHotspot
= 0;
2156 cursorInfo
.yHotspot
= 0;
2157 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
2158 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
2160 cursor
= CreateIconIndirect(&cursorInfo
);
2161 ok(cursor
!= NULL
, "CreateIconIndirect returned %p\n", cursor
);
2162 old_cursor
= SetCursor( cursor
);
2166 info
.cbSize
= sizeof(info
);
2167 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2168 /* global cursor doesn't change since we don't have a window */
2169 ok( info
.hCursor
== global_cursor
|| broken(info
.hCursor
!= cursor
), /* win9x */
2170 "wrong info cursor %p/%p\n", info
.hCursor
, global_cursor
);
2172 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2173 WaitForSingleObject( thread
, 1000 );
2174 GetExitCodeThread( thread
, &result
);
2175 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2178 ok( GetCursor() == 0, "wrong cursor %p\n", GetCursor() );
2179 thread
= CreateThread( NULL
, 0, set_cursor_thread
, 0, 0, &id
);
2180 WaitForSingleObject( thread
, 1000 );
2181 GetExitCodeThread( thread
, &result
);
2182 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2184 thread
= CreateThread( NULL
, 0, set_cursor_thread
, cursor
, 0, &id
);
2185 WaitForSingleObject( thread
, 1000 );
2186 GetExitCodeThread( thread
, &result
);
2187 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2188 ok( GetCursor() == 0, "wrong cursor %p/0\n", GetCursor() );
2190 parent_id
= GetCurrentThreadId();
2191 thread
= CreateThread( NULL
, 0, set_cursor_thread
, cursor
, 0, &id
);
2192 WaitForSingleObject( thread
, 1000 );
2193 GetExitCodeThread( thread
, &result
);
2194 ok( result
== (DWORD_PTR
)old_cursor
, "wrong thread cursor %x/%p\n", result
, old_cursor
);
2195 ok( GetCursor() == cursor
, "wrong cursor %p/0\n", cursor
);
2199 info
.cbSize
= sizeof(info
);
2200 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2201 ok( info
.hCursor
== global_cursor
|| broken(info
.hCursor
!= cursor
), /* win9x */
2202 "wrong info cursor %p/%p\n", info
.hCursor
, global_cursor
);
2204 SetCursor( old_cursor
);
2205 DestroyCursor( cursor
);
2207 SetLastError( 0xdeadbeef );
2208 cursor
= SetCursor( (HCURSOR
)0xbadbad );
2209 error
= GetLastError();
2210 ok( cursor
== 0, "wrong cursor %p/0\n", cursor
);
2211 ok( error
== ERROR_INVALID_CURSOR_HANDLE
|| broken( error
== 0xdeadbeef ), /* win9x */
2212 "wrong error %u\n", error
);
2216 info
.cbSize
= sizeof(info
);
2217 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2218 ok( info
.hCursor
== global_cursor
|| broken(info
.hCursor
!= cursor
), /* win9x */
2219 "wrong info cursor %p/%p\n", info
.hCursor
, global_cursor
);
2223 static HANDLE event_start
, event_next
;
2225 static DWORD CALLBACK
show_cursor_thread( void *arg
)
2227 DWORD count
= (DWORD_PTR
)arg
;
2230 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE
); /* create a msg queue */
2233 BOOL ret
= AttachThreadInput( GetCurrentThreadId(), parent_id
, TRUE
);
2234 ok( ret
, "AttachThreadInput failed\n" );
2236 if (!count
) ret
= ShowCursor( FALSE
);
2237 else while (count
--) ret
= ShowCursor( TRUE
);
2238 SetEvent( event_start
);
2239 WaitForSingleObject( event_next
, 2000 );
2243 static void test_ShowCursor(void)
2252 memset( &info
, 0, sizeof(info
) );
2253 info
.cbSize
= sizeof(info
);
2254 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2255 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2258 event_start
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
2259 event_next
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
2261 count
= ShowCursor( TRUE
);
2262 ok( count
== 1, "wrong count %d\n", count
);
2263 count
= ShowCursor( TRUE
);
2264 ok( count
== 2, "wrong count %d\n", count
);
2265 count
= ShowCursor( FALSE
);
2266 ok( count
== 1, "wrong count %d\n", count
);
2267 count
= ShowCursor( FALSE
);
2268 ok( count
== 0, "wrong count %d\n", count
);
2269 count
= ShowCursor( FALSE
);
2270 ok( count
== -1, "wrong count %d\n", count
);
2271 count
= ShowCursor( FALSE
);
2272 ok( count
== -2, "wrong count %d\n", count
);
2276 info
.cbSize
= sizeof(info
);
2277 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2278 /* global show count is not affected since we don't have a window */
2279 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2283 thread
= CreateThread( NULL
, 0, show_cursor_thread
, NULL
, 0, &id
);
2284 WaitForSingleObject( event_start
, 1000 );
2285 count
= ShowCursor( FALSE
);
2286 ok( count
== -3, "wrong count %d\n", count
);
2287 SetEvent( event_next
);
2288 WaitForSingleObject( thread
, 1000 );
2289 GetExitCodeThread( thread
, &result
);
2290 ok( result
== -1, "wrong thread count %d\n", result
);
2291 count
= ShowCursor( FALSE
);
2292 ok( count
== -4, "wrong count %d\n", count
);
2294 thread
= CreateThread( NULL
, 0, show_cursor_thread
, (void *)1, 0, &id
);
2295 WaitForSingleObject( event_start
, 1000 );
2296 count
= ShowCursor( TRUE
);
2297 ok( count
== -3, "wrong count %d\n", count
);
2298 SetEvent( event_next
);
2299 WaitForSingleObject( thread
, 1000 );
2300 GetExitCodeThread( thread
, &result
);
2301 ok( result
== 1, "wrong thread count %d\n", result
);
2302 count
= ShowCursor( TRUE
);
2303 ok( count
== -2, "wrong count %d\n", count
);
2305 parent_id
= GetCurrentThreadId();
2306 thread
= CreateThread( NULL
, 0, show_cursor_thread
, NULL
, 0, &id
);
2307 WaitForSingleObject( event_start
, 1000 );
2308 count
= ShowCursor( TRUE
);
2309 ok( count
== -2, "wrong count %d\n", count
);
2310 SetEvent( event_next
);
2311 WaitForSingleObject( thread
, 1000 );
2312 GetExitCodeThread( thread
, &result
);
2313 ok( result
== -3, "wrong thread count %d\n", result
);
2314 count
= ShowCursor( FALSE
);
2315 ok( count
== -2, "wrong count %d\n", count
);
2317 thread
= CreateThread( NULL
, 0, show_cursor_thread
, (void *)3, 0, &id
);
2318 WaitForSingleObject( event_start
, 1000 );
2319 count
= ShowCursor( TRUE
);
2320 ok( count
== 2, "wrong count %d\n", count
);
2321 SetEvent( event_next
);
2322 WaitForSingleObject( thread
, 1000 );
2323 GetExitCodeThread( thread
, &result
);
2324 ok( result
== 1, "wrong thread count %d\n", result
);
2325 count
= ShowCursor( FALSE
);
2326 ok( count
== -2, "wrong count %d\n", count
);
2330 info
.cbSize
= sizeof(info
);
2331 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2332 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2335 count
= ShowCursor( TRUE
);
2336 ok( count
== -1, "wrong count %d\n", count
);
2337 count
= ShowCursor( TRUE
);
2338 ok( count
== 0, "wrong count %d\n", count
);
2342 info
.cbSize
= sizeof(info
);
2343 ok( pGetCursorInfo( &info
), "GetCursorInfo failed\n" );
2344 ok( info
.flags
& CURSOR_SHOWING
, "cursor not shown in info\n" );
2349 static void test_DestroyCursor(void)
2351 static const BYTE bmp_bits
[4096];
2352 ICONINFO cursorInfo
, new_info
;
2353 HCURSOR cursor
, cursor2
, new_cursor
;
2360 display_bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
2363 cursorInfo
.fIcon
= FALSE
;
2364 cursorInfo
.xHotspot
= 0;
2365 cursorInfo
.yHotspot
= 0;
2366 cursorInfo
.hbmMask
= CreateBitmap(32, 32, 1, 1, bmp_bits
);
2367 cursorInfo
.hbmColor
= CreateBitmap(32, 32, 1, display_bpp
, bmp_bits
);
2369 cursor
= CreateIconIndirect(&cursorInfo
);
2370 ok(cursor
!= NULL
, "CreateIconIndirect returned %p\n", cursor
);
2376 SetLastError(0xdeadbeef);
2377 ret
= DestroyCursor(cursor
);
2378 ok(!ret
|| broken(ret
) /* succeeds on win9x */, "DestroyCursor on the active cursor succeeded\n");
2379 error
= GetLastError();
2380 ok(error
== 0xdeadbeef, "Last error: %u\n", error
);
2382 new_cursor
= GetCursor();
2383 if (ret
) /* win9x replaces cursor by another one on destroy */
2384 ok(new_cursor
!= cursor
, "GetCursor returned %p/%p\n", new_cursor
, cursor
);
2386 ok(new_cursor
== cursor
, "GetCursor returned %p/%p\n", new_cursor
, cursor
);
2388 SetLastError(0xdeadbeef);
2389 ret
= GetIconInfo( cursor
, &new_info
);
2390 ok( !ret
|| broken(ret
), /* nt4 */ "GetIconInfo succeeded\n" );
2391 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
||
2392 broken(GetLastError() == 0xdeadbeef), /* win9x */
2393 "wrong error %u\n", GetLastError() );
2395 if (ret
) /* nt4 delays destruction until cursor changes */
2397 DeleteObject( new_info
.hbmColor
);
2398 DeleteObject( new_info
.hbmMask
);
2400 SetLastError(0xdeadbeef);
2401 ret
= DestroyCursor( cursor
);
2402 ok( !ret
, "DestroyCursor succeeded\n" );
2403 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2404 "wrong error %u\n", GetLastError() );
2406 SetLastError(0xdeadbeef);
2407 cursor2
= SetCursor( cursor
);
2408 ok( cursor2
== cursor
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2409 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2410 "wrong error %u\n", GetLastError() );
2414 SetLastError(0xdeadbeef);
2415 cursor2
= CopyCursor( cursor
);
2416 ok(!cursor2
, "CopyCursor succeeded\n" );
2417 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
||
2418 broken(GetLastError() == 0xdeadbeef), /* win9x */
2419 "wrong error %u\n", GetLastError() );
2421 SetLastError(0xdeadbeef);
2422 ret
= DestroyCursor( cursor
);
2423 if (new_cursor
!= cursor
) /* win9x */
2424 ok( ret
, "DestroyCursor succeeded\n" );
2426 ok( !ret
, "DestroyCursor succeeded\n" );
2427 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2428 "wrong error %u\n", GetLastError() );
2430 SetLastError(0xdeadbeef);
2431 cursor2
= SetCursor( cursor
);
2432 ok(!cursor2
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2433 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2434 "wrong error %u\n", GetLastError() );
2437 cursor2
= GetCursor();
2438 ok(cursor2
== new_cursor
, "GetCursor returned %p/%p\n", cursor2
, new_cursor
);
2440 SetLastError(0xdeadbeef);
2441 cursor2
= SetCursor( 0 );
2442 if (new_cursor
!= cursor
) /* win9x */
2443 ok(cursor2
== new_cursor
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2445 ok(!cursor2
, "SetCursor returned %p/%p\n", cursor2
, cursor
);
2446 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2448 cursor2
= GetCursor();
2449 ok(!cursor2
, "GetCursor returned %p/%p\n", cursor2
, cursor
);
2451 SetLastError(0xdeadbeef);
2452 ret
= DestroyCursor(cursor
);
2453 if (new_cursor
!= cursor
) /* win9x */
2454 ok( ret
, "DestroyCursor succeeded\n" );
2456 ok( !ret
, "DestroyCursor succeeded\n" );
2457 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE
|| GetLastError() == 0xdeadbeef,
2458 "wrong error %u\n", GetLastError() );
2460 DeleteObject(cursorInfo
.hbmMask
);
2461 DeleteObject(cursorInfo
.hbmColor
);
2463 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2464 cursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2466 SetLastError(0xdeadbeef);
2467 ret
= DestroyCursor(cursor
);
2468 ok(ret
|| broken(!ret
) /* fails on win9x */, "DestroyCursor on the active cursor failed.\n");
2469 error
= GetLastError();
2470 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
2472 /* Try setting the cursor to a destroyed OEM cursor. */
2473 SetLastError(0xdeadbeef);
2475 error
= GetLastError();
2476 ok(error
== 0xdeadbeef, "Last error: 0x%08x\n", error
);
2478 /* Check if LoadCursor() returns the same handle with the same icon. */
2479 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2480 ok(cursor2
== cursor
, "cursor == %p, cursor2 == %p\n", cursor
, cursor2
);
2482 /* Check if LoadCursor() returns the same handle with a different icon. */
2483 cursor2
= LoadCursorA(NULL
, (LPCSTR
)IDC_WAIT
);
2484 ok(cursor2
!= cursor
, "cursor == %p, cursor2 == %p\n", cursor
, cursor2
);
2487 START_TEST(cursoricon
)
2489 pGetCursorInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" );
2490 pGetIconInfoExA
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExA" );
2491 pGetIconInfoExW
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetIconInfoExW" );
2492 pGetCursorFrameInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorFrameInfo" );
2493 test_argc
= winetest_get_mainargs(&test_argv
);
2497 /* Child process. */
2498 sscanf (test_argv
[2], "%x", (unsigned int *) &parent
);
2500 ok(parent
!= NULL
, "Parent not found.\n");
2508 test_CopyImage_Bitmap(1);
2509 test_CopyImage_Bitmap(4);
2510 test_CopyImage_Bitmap(8);
2511 test_CopyImage_Bitmap(16);
2512 test_CopyImage_Bitmap(24);
2513 test_CopyImage_Bitmap(32);
2514 test_initial_cursor();
2517 test_CreateIconFromResource();
2518 test_GetCursorFrameInfo();
2524 test_DestroyCursor();
2526 test_child_process();
2527 finish_child_process();