4b6b792114b96dcc4cdcdb463951ca19e64d42ec
[reactos.git] / rostests / winetests / user32 / cursoricon.c
1 /*
2 * Unit test suite for cursors and icons.
3 *
4 * Copyright 2006 Michael Kaufmann
5 * Copyright 2007 Dmitry Timoshkov
6 * Copyright 2007-2008 Andrew Riedi
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "wine/test.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33
34 #include "pshpack1.h"
35
36 typedef struct
37 {
38 BYTE bWidth;
39 BYTE bHeight;
40 BYTE bColorCount;
41 BYTE bReserved;
42 WORD xHotspot;
43 WORD yHotspot;
44 DWORD dwDIBSize;
45 DWORD dwDIBOffset;
46 } CURSORICONFILEDIRENTRY;
47
48 typedef struct
49 {
50 WORD idReserved;
51 WORD idType;
52 WORD idCount;
53 CURSORICONFILEDIRENTRY idEntries[1];
54 } CURSORICONFILEDIR;
55
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 ) )
59
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')
68
69 #define ANI_FLAG_ICON 0x1
70 #define ANI_FLAG_SEQUENCE 0x2
71
72 typedef struct {
73 DWORD header_size;
74 DWORD num_frames;
75 DWORD num_steps;
76 DWORD width;
77 DWORD height;
78 DWORD bpp;
79 DWORD num_planes;
80 DWORD display_rate;
81 DWORD flags;
82 } ani_header;
83
84 typedef struct {
85 BYTE data[32*32*4];
86 } ani_data32x32x32;
87
88 typedef struct {
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 */
92 } ani_frame32x32x32;
93
94 typedef struct {
95 DWORD chunk_id; /* ANI_anih_ID */
96 DWORD chunk_size; /* actual size of data */
97 ani_header header; /* animated cursor header */
98 } riff_header_t;
99
100 typedef struct {
101 DWORD chunk_id; /* ANI_LIST_ID */
102 DWORD chunk_size; /* actual size of data */
103 DWORD chunk_type; /* ANI_fram_ID */
104 } riff_list_t;
105
106 typedef struct {
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;
111
112 typedef struct {
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 */
119 } riff_cursor1_t;
120
121 typedef struct {
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 */
128 } riff_cursor3_t;
129
130 typedef struct {
131 DWORD chunk_id; /* ANI_rate_ID */
132 DWORD chunk_size; /* actual size of data */
133 DWORD rate[3]; /* animated cursor rate data */
134 } riff_rate3_t;
135
136 typedef struct {
137 DWORD chunk_id; /* ANI_seq__ID */
138 DWORD chunk_size; /* actual size of data */
139 DWORD order[3]; /* animated cursor sequence data */
140 } riff_seq3_t;
141
142 typedef struct {
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;
152
153 #define EMPTY_ICON32 \
154 { \
155 ANI_icon_ID, \
156 sizeof(ani_frame32x32x32), \
157 { \
158 { \
159 0x0, /* reserved */ \
160 0, /* type: icon(1), cursor(2) */ \
161 1, /* count */ \
162 { \
163 { \
164 32, /* width */ \
165 32, /* height */ \
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 */ \
172 } \
173 } \
174 }, \
175 { \
176 sizeof(BITMAPINFOHEADER), /* structure for DIB-type data */ \
177 32, /* width */ \
178 32*2, /* actual height times two */ \
179 1, /* planes */ \
180 32, /* bpp */ \
181 BI_RGB, /* compression */ \
182 0, /* image size */ \
183 0, /* biXPelsPerMeter */ \
184 0, /* biYPelsPerMeter */ \
185 0, /* biClrUsed */ \
186 0 /* biClrImportant */ \
187 } \
188 /* DIB data: left uninitialized */ \
189 } \
190 }
191
192 riff_cursor1_t empty_anicursor = {
193 ANI_RIFF_ID,
194 sizeof(empty_anicursor) - sizeof(DWORD)*2,
195 ANI_ACON_ID,
196 {
197 ANI_anih_ID,
198 sizeof(ani_header),
199 {
200 sizeof(ani_header),
201 1, /* frames */
202 1, /* steps */
203 32, /* width */
204 32, /* height */
205 32, /* depth */
206 1, /* planes */
207 10, /* display rate in jiffies */
208 ANI_FLAG_ICON /* flags */
209 }
210 },
211 {
212 ANI_LIST_ID,
213 sizeof(riff_icon32x32x32_t)*(1 /*frames*/) + sizeof(DWORD),
214 ANI_fram_ID,
215 },
216 {
217 EMPTY_ICON32
218 }
219 };
220
221 riff_cursor3_t empty_anicursor3 = {
222 ANI_RIFF_ID,
223 sizeof(empty_anicursor3) - sizeof(DWORD)*2,
224 ANI_ACON_ID,
225 {
226 ANI_anih_ID,
227 sizeof(ani_header),
228 {
229 sizeof(ani_header),
230 3, /* frames */
231 3, /* steps */
232 32, /* width */
233 32, /* height */
234 32, /* depth */
235 1, /* planes */
236 0xbeef, /* display rate in jiffies */
237 ANI_FLAG_ICON /* flags */
238 }
239 },
240 {
241 ANI_LIST_ID,
242 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
243 ANI_fram_ID,
244 },
245 {
246 EMPTY_ICON32,
247 EMPTY_ICON32,
248 EMPTY_ICON32
249 }
250 };
251
252 riff_cursor3_seq_t empty_anicursor3_seq = {
253 ANI_RIFF_ID,
254 sizeof(empty_anicursor3_seq) - sizeof(DWORD)*2,
255 ANI_ACON_ID,
256 {
257 ANI_anih_ID,
258 sizeof(ani_header),
259 {
260 sizeof(ani_header),
261 3, /* frames */
262 3, /* steps */
263 32, /* width */
264 32, /* height */
265 32, /* depth */
266 1, /* planes */
267 0xbeef, /* display rate in jiffies */
268 ANI_FLAG_ICON|ANI_FLAG_SEQUENCE /* flags */
269 }
270 },
271 {
272 ANI_seq__ID,
273 sizeof(riff_seq3_t) - sizeof(DWORD)*2,
274 { 2, 0, 1} /* show frames in a uniquely identifiable order */
275 },
276 {
277 ANI_rate_ID,
278 sizeof(riff_rate3_t) - sizeof(DWORD)*2,
279 { 0xc0de, 0xcafe, 0xbabe}
280 },
281 {
282 ANI_LIST_ID,
283 sizeof(riff_icon32x32x32_t)*(3 /*frames*/) + sizeof(DWORD),
284 ANI_fram_ID,
285 },
286 {
287 EMPTY_ICON32,
288 EMPTY_ICON32,
289 EMPTY_ICON32
290 }
291 };
292
293 #include "poppack.h"
294
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;
300
301 #define PROC_INIT (WM_USER+1)
302
303 static BOOL (WINAPI *pGetCursorInfo)(CURSORINFO *);
304 static BOOL (WINAPI *pGetIconInfoExA)(HICON,ICONINFOEXA *);
305 static BOOL (WINAPI *pGetIconInfoExW)(HICON,ICONINFOEXW *);
306
307 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
308
309 static LRESULT CALLBACK callback_child(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
310 {
311 switch (msg)
312 {
313 /* Destroy the cursor. */
314 case WM_USER+1:
315 {
316 HCURSOR cursor = (HCURSOR)lParam;
317 ICONINFO info;
318 BOOL ret;
319 DWORD error;
320
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);
328
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);
336 return TRUE;
337 }
338 case WM_DESTROY:
339 PostQuitMessage(0);
340 return 0;
341 }
342
343 return DefWindowProcA(hwnd, msg, wParam, lParam);
344 }
345
346 static LRESULT CALLBACK callback_parent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
347 {
348 if (msg == PROC_INIT)
349 {
350 child = (HWND) wParam;
351 return TRUE;
352 }
353
354 return DefWindowProcA(hwnd, msg, wParam, lParam);
355 }
356
357 static void do_child(void)
358 {
359 WNDCLASSA class;
360 MSG msg;
361 BOOL ret;
362
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);
369 class.hIcon = NULL;
370 class.hCursor = NULL;
371 class.hbrBackground = NULL;
372 class.lpszMenuName = NULL;
373 class.lpszClassName = "cursor_child";
374
375 SetLastError(0xdeadbeef);
376 ret = RegisterClassA(&class);
377 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
378
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());
383
384 /* Let the parent know our HWND. */
385 PostMessageA(parent, PROC_INIT, (WPARAM) child, 0);
386
387 /* Receive messages. */
388 while ((ret = GetMessageA(&msg, 0, 0, 0)))
389 {
390 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
391 TranslateMessage(&msg);
392 DispatchMessageA(&msg);
393 }
394 }
395
396 static void do_parent(void)
397 {
398 char path_name[MAX_PATH];
399 PROCESS_INFORMATION info;
400 STARTUPINFOA startup;
401 WNDCLASSA class;
402 MSG msg;
403 BOOL ret;
404
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);
411 class.hIcon = NULL;
412 class.hCursor = NULL;
413 class.hbrBackground = NULL;
414 class.lpszMenuName = NULL;
415 class.lpszClassName = "cursor_parent";
416
417 SetLastError(0xdeadbeef);
418 ret = RegisterClassA(&class);
419 ok(ret, "Failed to register window class. Error: %u\n", GetLastError());
420
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());
425
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;
431
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;
435
436 /* Wait for child window handle. */
437 while ((child == 0) && (ret = GetMessageA(&msg, parent, 0, 0)))
438 {
439 ok(ret != -1, "GetMessage failed. Error: %u\n", GetLastError());
440 TranslateMessage(&msg);
441 DispatchMessageA(&msg);
442 }
443 }
444
445 static void finish_child_process(void)
446 {
447 SendMessageA(child, WM_CLOSE, 0, 0);
448 winetest_wait_child_process( child_process );
449 CloseHandle(child_process);
450 }
451
452 static void test_child_process(void)
453 {
454 static const BYTE bmp_bits[4096];
455 HCURSOR cursor;
456 ICONINFO cursorInfo;
457 UINT display_bpp;
458 HDC hdc;
459
460 /* Create and set a dummy cursor. */
461 hdc = GetDC(0);
462 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
463 ReleaseDC(0, hdc);
464
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);
470
471 cursor = CreateIconIndirect(&cursorInfo);
472 ok(cursor != NULL, "CreateIconIndirect returned %p.\n", cursor);
473
474 SetCursor(cursor);
475
476 /* Destroy the cursor. */
477 SendMessageA(child, WM_USER+1, 0, (LPARAM) cursor);
478 }
479
480 static BOOL color_match(COLORREF a, COLORREF b)
481 {
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.
484 * palettized. */
485 return (a & 0x00F8F8F8) == (b & 0x00F8F8F8);
486 }
487
488 static void test_CopyImage_Check(HBITMAP bitmap, UINT flags, INT copyWidth, INT copyHeight,
489 INT expectedWidth, INT expectedHeight, WORD expectedDepth, BOOL dibExpected)
490 {
491 HBITMAP copy;
492 BITMAP origBitmap;
493 BITMAP copyBitmap;
494 BOOL orig_is_dib;
495 BOOL copy_is_dib;
496
497 copy = CopyImage(bitmap, IMAGE_BITMAP, copyWidth, copyHeight, flags);
498 ok(copy != NULL, "CopyImage() failed\n");
499 if (copy != NULL)
500 {
501 GetObjectA(bitmap, sizeof(origBitmap), &origBitmap);
502 GetObjectA(copy, sizeof(copyBitmap), &copyBitmap);
503 orig_is_dib = (origBitmap.bmBits != NULL);
504 copy_is_dib = (copyBitmap.bmBits != NULL);
505
506 if (copy_is_dib && dibExpected
507 && copyBitmap.bmBitsPixel == 24
508 && (expectedDepth == 16 || expectedDepth == 32))
509 {
510 /* Windows 95 doesn't create DIBs with a depth of 16 or 32 bit */
511 if (GetVersion() & 0x80000000)
512 {
513 expectedDepth = 24;
514 }
515 }
516
517 if (copy_is_dib && !dibExpected && !(flags & LR_CREATEDIBSECTION))
518 {
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 */
523 dibExpected = TRUE;
524 expectedDepth = origBitmap.bmBitsPixel;
525 }
526
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);
536
537 DeleteObject(copy);
538 }
539 }
540
541 static void test_CopyImage_Bitmap(int depth)
542 {
543 HBITMAP ddb, dib;
544 HDC screenDC;
545 BITMAPINFO * info;
546 VOID * bits;
547 int screen_depth;
548 unsigned int i;
549
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;
558
559 for (i=0; i < 256; i++)
560 {
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;
565 }
566
567 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
568
569 /* Create a device-dependent bitmap (DDB) */
570 screenDC = GetDC(NULL);
571 screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
572 if (depth == 1 || depth == screen_depth)
573 {
574 ddb = CreateBitmap(2, 2, 1, depth, NULL);
575 }
576 else
577 {
578 ddb = NULL;
579 }
580 ReleaseDC(NULL, screenDC);
581
582 if (ddb != NULL)
583 {
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);
588
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);
593
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);
598
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);
604
605 DeleteObject(ddb);
606 }
607
608 if (depth != 1)
609 {
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);
614 }
615
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);
620
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);
625
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);
631
632 DeleteObject(dib);
633
634 if (depth == 1)
635 {
636 /* Special case: A monochrome DIB is converted to a monochrome DDB if
637 the colors in the color table are black and white.
638
639 Skip this test on Windows 95, it always creates a monochrome DDB
640 in this case */
641
642 if (!(GetVersion() & 0x80000000))
643 {
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;
651
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);
657 DeleteObject(dib);
658
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;
666
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);
672 DeleteObject(dib);
673
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;
681
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);
687 DeleteObject(dib);
688 }
689 }
690
691 HeapFree(GetProcessHeap(), 0, info);
692 }
693
694 static void test_initial_cursor(void)
695 {
696 HCURSOR cursor, cursor2;
697 DWORD error;
698
699 cursor = GetCursor();
700
701 /* Check what handle GetCursor() returns if a cursor is not set yet. */
702 SetLastError(0xdeadbeef);
703 cursor2 = LoadCursorA(NULL, (LPCSTR)IDC_WAIT);
704 todo_wine {
705 ok(cursor == cursor2, "cursor (%p) is not IDC_WAIT (%p).\n", cursor, cursor2);
706 }
707 error = GetLastError();
708 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
709 }
710
711 static void test_icon_info_dbg(HICON hIcon, UINT exp_cx, UINT exp_cy, UINT exp_mask_cy, UINT exp_bpp, int line)
712 {
713 ICONINFO info;
714 DWORD ret;
715 BITMAP bmMask, bmColor;
716
717 ret = GetIconInfo(hIcon, &info);
718 ok_(__FILE__, line)(ret, "GetIconInfo failed\n");
719
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");
724
725 ret = GetObjectA(info.hbmMask, sizeof(bmMask), &bmMask);
726 ok_(__FILE__, line)(ret == sizeof(bmMask), "GetObject(info.hbmMask) failed, ret %u\n", ret);
727
728 if (exp_bpp == 1)
729 ok_(__FILE__, line)(info.hbmColor == 0, "info.hbmColor should be NULL\n");
730
731 if (info.hbmColor)
732 {
733 HDC hdc;
734 UINT display_bpp;
735
736 hdc = GetDC(0);
737 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
738 ReleaseDC(0, hdc);
739
740 ret = GetObjectA(info.hbmColor, sizeof(bmColor), &bmColor);
741 ok_(__FILE__, line)(ret == sizeof(bmColor), "GetObject(info.hbmColor) failed, ret %u\n", ret);
742
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);
748
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);
752 }
753 else
754 {
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);
758 }
759 if (pGetIconInfoExA)
760 {
761 ICONINFOEXA infoex;
762
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());
769
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());
775
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());
782
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);
789 }
790 }
791
792 #define test_icon_info(a,b,c,d,e) test_icon_info_dbg((a),(b),(c),(d),(e),__LINE__)
793
794 static void test_CreateIcon(void)
795 {
796 static const BYTE bmp_bits[1024];
797 HICON hIcon;
798 HBITMAP hbmMask, hbmColor;
799 BITMAPINFO *bmpinfo;
800 ICONINFO info;
801 HDC hdc;
802 void *bits;
803 UINT display_bpp;
804 int i;
805
806 hdc = GetDC(0);
807 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
808
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);
812 */
813
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);
817 DestroyIcon(hIcon);
818
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);
822 DestroyIcon(hIcon);
823
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");
828
829 info.fIcon = TRUE;
830 info.xHotspot = 8;
831 info.yHotspot = 8;
832 info.hbmMask = 0;
833 info.hbmColor = 0;
834 SetLastError(0xdeadbeaf);
835 hIcon = CreateIconIndirect(&info);
836 ok(!hIcon, "CreateIconIndirect should fail\n");
837 ok(GetLastError() == 0xdeadbeaf, "wrong error %u\n", GetLastError());
838
839 info.fIcon = TRUE;
840 info.xHotspot = 8;
841 info.yHotspot = 8;
842 info.hbmMask = 0;
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());
848
849 info.fIcon = TRUE;
850 info.xHotspot = 8;
851 info.yHotspot = 8;
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);
857 DestroyIcon(hIcon);
858
859 DeleteObject(hbmMask);
860 DeleteObject(hbmColor);
861
862 hbmMask = CreateBitmap(16, 32, 1, 1, bmp_bits);
863 ok(hbmMask != 0, "CreateBitmap failed\n");
864
865 info.fIcon = TRUE;
866 info.xHotspot = 8;
867 info.yHotspot = 8;
868 info.hbmMask = hbmMask;
869 info.hbmColor = 0;
870 SetLastError(0xdeadbeaf);
871 hIcon = CreateIconIndirect(&info);
872 ok(hIcon != 0, "CreateIconIndirect failed\n");
873 test_icon_info(hIcon, 16, 16, 32, 1);
874 DestroyIcon(hIcon);
875 DeleteObject(hbmMask);
876
877 for (i = 0; i <= 4; i++)
878 {
879 hbmMask = CreateBitmap(1, i, 1, 1, bmp_bits);
880 ok(hbmMask != 0, "CreateBitmap failed\n");
881
882 info.fIcon = TRUE;
883 info.xHotspot = 0;
884 info.yHotspot = 0;
885 info.hbmMask = hbmMask;
886 info.hbmColor = 0;
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);
891 DestroyIcon(hIcon);
892 DeleteObject(hbmMask);
893 }
894
895 /* test creating an icon from a DIB section */
896
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");
906 if (bits)
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");
911 if (bits)
912 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
913
914 info.fIcon = TRUE;
915 info.xHotspot = 8;
916 info.yHotspot = 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);
923 DestroyIcon(hIcon);
924 DeleteObject(hbmColor);
925
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");
929 if (bits)
930 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
931
932 info.fIcon = TRUE;
933 info.xHotspot = 8;
934 info.yHotspot = 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);
941 DestroyIcon(hIcon);
942 DeleteObject(hbmColor);
943
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");
947 if (bits)
948 memset( bits, 0x55, 32 * 32 * bmpinfo->bmiHeader.biBitCount / 8 );
949
950 info.fIcon = TRUE;
951 info.xHotspot = 8;
952 info.yHotspot = 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);
959 DestroyIcon(hIcon);
960
961 DeleteObject(hbmMask);
962 DeleteObject(hbmColor);
963 HeapFree( GetProcessHeap(), 0, bmpinfo );
964
965 ReleaseDC(0, hdc);
966 }
967
968 /* Shamelessly ripped from dlls/oleaut32/tests/olepicture.c */
969 /* 1x1 pixel gif */
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,
973 0x01,0x00,0x3b
974 };
975
976 /* 1x1 pixel jpg */
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
996 };
997
998 /* 1x1 pixel png */
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
1007 };
1008
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
1017 };
1018
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
1024 };
1025
1026 /* 2x2 pixel gif */
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
1031 };
1032
1033 static const DWORD biSize_tests[] = {
1034 0,
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,
1045 0xdeadbeef,
1046 0xffffffff
1047 };
1048
1049 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1050
1051 static void test_LoadImageBitmap(const char * test_desc, HBITMAP hbm)
1052 {
1053 BITMAP bm;
1054 BITMAPINFO bmi;
1055 DWORD ret, pixel = 0;
1056 HDC hdc = GetDC(NULL);
1057
1058 ret = GetObjectA(hbm, sizeof(bm), &bm);
1059 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
1060
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);
1070
1071 ok(color_match(pixel, 0x00ffffff), "%s: Pixel is 0x%08x\n", test_desc, pixel);
1072 }
1073
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)
1076 {
1077 HANDLE handle;
1078 BOOL ret;
1079 DWORD error, bytes_written;
1080 char filename[64];
1081
1082 strcpy(filename, "test.");
1083 strcat(filename, ext);
1084
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);
1092
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();
1098 ok(error == 0 ||
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);
1103
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();
1109 ok(error == 0 ||
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);
1114
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();
1119 ok(error == 0 ||
1120 error == 0xdeadbeef, /* Win9x, WinMe */
1121 "Last error: %u\n", error);
1122
1123 if (expect_success) {
1124 ok(handle != NULL, "%s: IMAGE_BITMAP failed.\n", test_desc);
1125 if (handle != NULL) test_LoadImageBitmap(test_desc, handle);
1126 }
1127 else ok(handle == NULL, "%s: IMAGE_BITMAP succeeded incorrectly.\n", test_desc);
1128
1129 if (handle != NULL) DeleteObject(handle);
1130 DeleteFileA(filename);
1131 }
1132
1133 static void test_LoadImage(void)
1134 {
1135 HANDLE handle;
1136 BOOL ret;
1137 DWORD error, bytes_written;
1138 CURSORICONFILEDIR *icon_data;
1139 CURSORICONFILEDIRENTRY *icon_entry;
1140 BITMAPINFOHEADER *icon_header, *bitmap_header;
1141 ICONINFO icon_info;
1142 int i;
1143
1144 #define ICON_WIDTH 32
1145 #define ICON_HEIGHT 32
1146 #define ICON_AND_SIZE (ICON_WIDTH*ICON_HEIGHT/8)
1147 #define ICON_BPP 32
1148 #define ICON_SIZE \
1149 (sizeof(CURSORICONFILEDIR) + sizeof(BITMAPINFOHEADER) \
1150 + ICON_AND_SIZE + ICON_AND_SIZE*ICON_BPP)
1151
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;
1157
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);
1167
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. */
1175
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);
1183
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();
1189 ok(error == 0 ||
1190 broken(error == 0xdeadbeef) || /* Win9x */
1191 broken(error == ERROR_BAD_PATHNAME), /* Win98, WinMe */
1192 "Last error: %u\n", error);
1193
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);
1200
1201 if (ret)
1202 {
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 */,
1207 "No hbmColor!\n");
1208 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1209 }
1210
1211 if (pGetIconInfoExA)
1212 {
1213 ICONINFOEXA infoex;
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 );
1220 }
1221 else win_skip( "GetIconInfoEx not available\n" );
1222
1223 /* Clean up. */
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);
1229
1230 HeapFree(GetProcessHeap(), 0, icon_data);
1231 DeleteFileA("icon.ico");
1232
1233 /* Test a system icon */
1234 handle = LoadIconA( 0, (LPCSTR)IDI_HAND );
1235 ok(handle != NULL, "LoadImage() failed.\n");
1236 if (pGetIconInfoExA)
1237 {
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" );
1247 else
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) );
1258 }
1259 SetLastError(0xdeadbeef);
1260 DestroyIcon(handle);
1261
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);
1268
1269 /* Check failure for broken BMP images */
1270 bitmap_header = (BITMAPINFOHEADER *)(bmpimage + sizeof(BITMAPFILEHEADER));
1271
1272 bitmap_header->biHeight = 65536;
1273 test_LoadImageFile("BMP (too high)", bmpimage, sizeof(bmpimage), "bmp", 0);
1274 bitmap_header->biHeight = 1;
1275
1276 bitmap_header->biWidth = 65536;
1277 test_LoadImageFile("BMP (too wide)", bmpimage, sizeof(bmpimage), "bmp", 0);
1278 bitmap_header->biWidth = 1;
1279
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);
1283 }
1284 bitmap_header->biSize = sizeof(BITMAPINFOHEADER);
1285 }
1286
1287 #undef ARRAY_SIZE
1288
1289 static void test_CreateIconFromResource(void)
1290 {
1291 HANDLE handle;
1292 BOOL ret;
1293 DWORD error;
1294 BITMAPINFOHEADER *icon_header;
1295 INT16 *hotspot;
1296 ICONINFO icon_info;
1297
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)
1305
1306 /* Set icon data. */
1307 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1308
1309 /* Cursor resources have an extra hotspot, icon resources not. */
1310 hotspot[0] = 3;
1311 hotspot[1] = 3;
1312
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. */
1320
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");
1325
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);
1332
1333 if (ret)
1334 {
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 */,
1339 "No hbmColor!\n");
1340 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1341 }
1342
1343 if (pGetIconInfoExA)
1344 {
1345 ICONINFOEXA infoex;
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 );
1352 }
1353
1354 /* Clean up. */
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);
1360
1361 /* Test creating an icon. */
1362 SetLastError(0xdeadbeef);
1363 handle = CreateIconFromResource((PBYTE) icon_header, ICON_RES_SIZE, TRUE,
1364 0x00030000);
1365 ok(handle != NULL, "Create icon failed.\n");
1366
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);
1373
1374 if (ret)
1375 {
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");
1382 }
1383
1384 /* Clean up. */
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);
1390
1391 /* Rejection of NULL pointer crashes at least on WNT4WSSP6, W2KPROSP4, WXPPROSP3
1392 *
1393 * handle = CreateIconFromResource(NULL, ICON_RES_SIZE, TRUE, 0x00030000);
1394 * ok(handle == NULL, "Invalid pointer accepted (%p)\n", handle);
1395 */
1396 HeapFree(GetProcessHeap(), 0, hotspot);
1397
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");
1404
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);
1411
1412 if (ret)
1413 {
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 */,
1418 "No hbmColor!\n");
1419 ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
1420 }
1421
1422 /* Clean up. */
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);
1428 }
1429
1430 static int check_cursor_data( HDC hdc, HCURSOR hCursor, void *data, int length)
1431 {
1432 char *image = NULL;
1433 BITMAPINFO *info;
1434 ICONINFO iinfo;
1435 DWORD ret;
1436 int i;
1437
1438 ret = GetIconInfo( hCursor, &iinfo );
1439 ok(ret, "GetIconInfo() failed\n");
1440 if (!ret) return 0;
1441 ret = 0;
1442 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ));
1443 ok(info != NULL, "HeapAlloc() failed\n");
1444 if (!info) return 0;
1445
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++)
1463 {
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] );
1466 }
1467 cleanup:
1468 HeapFree( GetProcessHeap(), 0, image );
1469 HeapFree( GetProcessHeap(), 0, info );
1470 return ret;
1471 }
1472
1473 static HCURSOR (WINAPI *pGetCursorFrameInfo)(HCURSOR hCursor, DWORD unk1, DWORD istep, DWORD *rate, DWORD *steps);
1474 static void test_GetCursorFrameInfo(void)
1475 {
1476 DWORD frame_identifier[] = { 0x10Ad, 0xc001, 0x1c05 };
1477 HBITMAP bmp = NULL, bmpOld = NULL;
1478 DWORD rate, steps;
1479 BITMAPINFOHEADER *icon_header;
1480 BITMAPINFO bitmapInfo;
1481 HDC hdc = NULL;
1482 void *bits = 0;
1483 INT16 *hotspot;
1484 HANDLE h1, h2;
1485 BOOL ret;
1486 int i;
1487
1488 if (!pGetCursorFrameInfo)
1489 {
1490 win_skip( "GetCursorFrameInfo not supported, skipping tests.\n" );
1491 return;
1492 }
1493
1494 hdc = CreateCompatibleDC(0);
1495 ok(hdc != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1496 if (!hdc)
1497 return;
1498
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");
1509 if (!bmp || !bits)
1510 goto cleanup;
1511 bmpOld = SelectObject(hdc, bmp);
1512
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)
1520
1521 /* Set icon data. */
1522 hotspot = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, CRSR_RES_SIZE);
1523
1524 /* Cursor resources have an extra hotspot, icon resources not. */
1525 hotspot[0] = 3;
1526 hotspot[1] = 3;
1527
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. */
1535
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());
1540
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);
1547
1548 /* Clean up static cursor. */
1549 SetLastError(0xdeadbeef);
1550 ret = DestroyCursor(h1);
1551 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1552
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());
1561
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);
1571
1572 /* Clean up single-frame animated cursor. */
1573 SetLastError(0xdeadbeef);
1574 ret = DestroyCursor(h1);
1575 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1576
1577 /* Creating a multi-frame animated cursor. */
1578 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1579 {
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) );
1584 }
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());
1588
1589 /* Check number of steps in multi-frame animated cursor */
1590 i=0;
1591 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1592 i++;
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);
1596
1597 /* Check GetCursorFrameInfo behavior on a multi-frame animated cursor */
1598 for (i=0; i<empty_anicursor3.header.header.num_frames; i++)
1599 {
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);
1611 }
1612
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);
1623
1624 /* Clean up multi-frame animated cursor. */
1625 SetLastError(0xdeadbeef);
1626 ret = DestroyCursor(h1);
1627 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1628
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());
1634
1635 /* Check number of steps in multi-frame animated cursor (mismatch between steps and frames) */
1636 i=0;
1637 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1638 i++;
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);
1642
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);
1654
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);
1665
1666 /* Clean up multi-frame animated cursor. */
1667 SetLastError(0xdeadbeef);
1668 ret = DestroyCursor(h1);
1669 ok(ret, "DestroyCursor() failed (error = %d).\n", GetLastError());
1670
1671 /* Creating a multi-frame animated cursor with rate data. */
1672 for (i=0; i<empty_anicursor3_seq.header.header.num_frames; i++)
1673 {
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) );
1678 }
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());
1682
1683 /* Check number of steps in multi-frame animated cursor with rate data */
1684 i=0;
1685 while (DrawIconEx(hdc, 0, 0, h1, 32, 32, i, NULL, DI_NORMAL))
1686 i++;
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);
1690
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++)
1693 {
1694 int frame_id = empty_anicursor3_seq.seq.order[i];
1695
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);
1707 }
1708
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());
1713
1714 HeapFree(GetProcessHeap(), 0, hotspot);
1715 cleanup:
1716 if(bmpOld) SelectObject(hdc, bmpOld);
1717 if(bmp) DeleteObject(bmp);
1718 if(hdc) DeleteDC(hdc);
1719 }
1720
1721 static HICON create_test_icon(HDC hdc, int width, int height, int bpp,
1722 BOOL maskvalue, UINT32 *color, int colorSize)
1723 {
1724 ICONINFO iconInfo;
1725 BITMAPINFO bitmapInfo;
1726 void *buffer = NULL;
1727 UINT32 mask = maskvalue ? 0xFFFFFFFF : 0x00000000;
1728
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;
1737
1738 iconInfo.fIcon = TRUE;
1739 iconInfo.xHotspot = 0;
1740 iconInfo.yHotspot = 0;
1741
1742 iconInfo.hbmMask = CreateBitmap( width, height, 1, 1, &mask );
1743 if(!iconInfo.hbmMask) return NULL;
1744
1745 iconInfo.hbmColor = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
1746 if(!iconInfo.hbmColor || !buffer)
1747 {
1748 DeleteObject(iconInfo.hbmMask);
1749 return NULL;
1750 }
1751
1752 memcpy(buffer, color, colorSize);
1753
1754 return CreateIconIndirect(&iconInfo);
1755 }
1756
1757 static void check_alpha_draw(HDC hdc, BOOL drawiconex, BOOL alpha, int bpp, int line)
1758 {
1759 HICON hicon;
1760 UINT32 color[2];
1761 COLORREF modern_expected, legacy_expected, result;
1762
1763 color[0] = 0x00A0B0C0;
1764 color[1] = alpha ? 0xFF000000 : 0x00000000;
1765 modern_expected = alpha ? 0x00FFFFFF : 0x00C0B0A0;
1766 legacy_expected = 0x00C0B0A0;
1767
1768 hicon = create_test_icon(hdc, 2, 1, bpp, 0, color, sizeof(color));
1769 if (!hicon) return;
1770
1771 SetPixelV(hdc, 0, 0, 0x00FFFFFF);
1772
1773 if(drawiconex)
1774 DrawIconEx(hdc, 0, 0, hicon, 2, 1, 0, NULL, DI_NORMAL);
1775 else
1776 DrawIcon(hdc, 0, 0, hicon);
1777
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);
1785 }
1786
1787 static void check_DrawIcon(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, COLORREF background,
1788 COLORREF modern_expected, COLORREF legacy_expected, int line)
1789 {
1790 COLORREF result;
1791 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1792 if (!hicon) return;
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);
1798
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);
1804
1805 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON)-1, GetSystemMetrics(SM_CYICON)-1);
1806
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);
1812
1813 result = GetPixel(hdc, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
1814
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);
1819 }
1820
1821 static void test_DrawIcon(void)
1822 {
1823 BITMAPINFO bitmapInfo;
1824 HDC hdcDst = NULL;
1825 HBITMAP bmpDst = NULL;
1826 HBITMAP bmpOld = NULL;
1827 void *bits = 0;
1828
1829 hdcDst = CreateCompatibleDC(0);
1830 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1831 if (!hdcDst)
1832 return;
1833
1834 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1835 {
1836 skip("Windows will distort DrawIcon colors at 8-bpp and less due to palettizing.\n");
1837 goto cleanup;
1838 }
1839
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);
1848
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)
1852 goto cleanup;
1853 bmpOld = SelectObject(hdcDst, bmpDst);
1854
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__);
1858
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__);
1863
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__);
1868
1869 check_DrawIcon(hdcDst, FALSE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1870 check_DrawIcon(hdcDst, TRUE, 0x01FFFFFF, 32, 0x00000000, 0x00010101, 0x00FFFFFF, __LINE__);
1871
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
1875 and + xor blts. */
1876 check_alpha_draw(hdcDst, FALSE, FALSE, 32, __LINE__);
1877 check_alpha_draw(hdcDst, FALSE, TRUE, 32, __LINE__);
1878
1879 cleanup:
1880 if(bmpOld)
1881 SelectObject(hdcDst, bmpOld);
1882 if(bmpDst)
1883 DeleteObject(bmpDst);
1884 if(hdcDst)
1885 DeleteDC(hdcDst);
1886 }
1887
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)
1890 {
1891 COLORREF result;
1892 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
1893 if (!hicon) return;
1894 SetPixelV(hdc, 0, 0, background);
1895 DrawIconEx(hdc, 0, 0, hicon, 1, 1, 0, NULL, flags);
1896 result = GetPixel(hdc, 0, 0);
1897
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);
1903 }
1904
1905 static void test_DrawIconEx(void)
1906 {
1907 BITMAPINFO bitmapInfo;
1908 HDC hdcDst = NULL;
1909 HBITMAP bmpDst = NULL;
1910 HBITMAP bmpOld = NULL;
1911 void *bits = 0;
1912
1913 hdcDst = CreateCompatibleDC(0);
1914 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1915 if (!hdcDst)
1916 return;
1917
1918 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
1919 {
1920 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
1921 goto cleanup;
1922 }
1923
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)
1935 goto cleanup;
1936 bmpOld = SelectObject(hdcDst, bmpDst);
1937
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__);
1941
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__);
1944
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__);
1947
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__);
1952
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__);
1956
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__);
1961
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__);
1964
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
1968 and + xor blts. */
1969 check_alpha_draw(hdcDst, TRUE, FALSE, 32, __LINE__);
1970 check_alpha_draw(hdcDst, TRUE, TRUE, 32, __LINE__);
1971
1972 cleanup:
1973 if(bmpOld)
1974 SelectObject(hdcDst, bmpOld);
1975 if(bmpDst)
1976 DeleteObject(bmpDst);
1977 if(hdcDst)
1978 DeleteDC(hdcDst);
1979 }
1980
1981 static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
1982 {
1983 COLORREF result, background;
1984 BOOL passed[2];
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);
1990
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 ));
1993
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);
1998
1999 /* Check if manually specifying the icon size DOESN'T work */
2000
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 ));
2007
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);
2012
2013 if(!passed[0]&&!passed[1])
2014 ok (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);
2019 else if(!passed[1])
2020 ok (passed[1],
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);
2025 else
2026 ok (passed[0],
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);
2031 }
2032
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)
2035 {
2036 COLORREF result;
2037 HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
2038 if (!hicon) return;
2039 /* Set color of the pixel that will be checked afterwards */
2040 SetPixelV(hdc, 1, 1, background);
2041
2042 DrawStateA(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
2043
2044 /* Check the color of the pixel is correct */
2045 result = GetPixel(hdc, 1, 1);
2046
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);
2052 }
2053
2054 static void test_DrawState(void)
2055 {
2056 BITMAPINFO bitmapInfo;
2057 HDC hdcDst = NULL;
2058 HBITMAP bmpDst = NULL;
2059 HBITMAP bmpOld = NULL;
2060 void *bits = 0;
2061
2062 hdcDst = CreateCompatibleDC(0);
2063 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
2064 if (!hdcDst)
2065 return;
2066
2067 if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
2068 {
2069 skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palettizing.\n");
2070 goto cleanup;
2071 }
2072
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)
2084 goto cleanup;
2085 bmpOld = SelectObject(hdcDst, bmpDst);
2086
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 */
2092
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__);
2095
2096 cleanup:
2097 if(bmpOld)
2098 SelectObject(hdcDst, bmpOld);
2099 if(bmpDst)
2100 DeleteObject(bmpDst);
2101 if(hdcDst)
2102 DeleteDC(hdcDst);
2103 }
2104
2105 static DWORD parent_id;
2106
2107 static DWORD CALLBACK set_cursor_thread( void *arg )
2108 {
2109 HCURSOR ret;
2110
2111 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2112 if (parent_id)
2113 {
2114 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2115 ok( ret, "AttachThreadInput failed\n" );
2116 }
2117 if (arg) ret = SetCursor( (HCURSOR)arg );
2118 else ret = GetCursor();
2119 return (DWORD_PTR)ret;
2120 }
2121
2122 static void test_SetCursor(void)
2123 {
2124 static const BYTE bmp_bits[4096];
2125 ICONINFO cursorInfo;
2126 HCURSOR cursor, old_cursor, global_cursor = 0;
2127 DWORD error, id, result;
2128 UINT display_bpp;
2129 HDC hdc;
2130 HANDLE thread;
2131 CURSORINFO info;
2132
2133 if (pGetCursorInfo)
2134 {
2135 memset( &info, 0, sizeof(info) );
2136 info.cbSize = sizeof(info);
2137 if (!pGetCursorInfo( &info ))
2138 {
2139 win_skip( "GetCursorInfo not working\n" );
2140 pGetCursorInfo = NULL;
2141 }
2142 else global_cursor = info.hCursor;
2143 }
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 );
2149
2150 hdc = GetDC(0);
2151 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2152 ReleaseDC(0, hdc);
2153
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);
2159
2160 cursor = CreateIconIndirect(&cursorInfo);
2161 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2162 old_cursor = SetCursor( cursor );
2163
2164 if (pGetCursorInfo)
2165 {
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 );
2171 }
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 );
2176
2177 SetCursor( 0 );
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 );
2183
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() );
2189
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 );
2196
2197 if (pGetCursorInfo)
2198 {
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 );
2203 }
2204 SetCursor( old_cursor );
2205 DestroyCursor( cursor );
2206
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 );
2213
2214 if (pGetCursorInfo)
2215 {
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 );
2220 }
2221 }
2222
2223 static HANDLE event_start, event_next;
2224
2225 static DWORD CALLBACK show_cursor_thread( void *arg )
2226 {
2227 DWORD count = (DWORD_PTR)arg;
2228 int ret;
2229
2230 PeekMessageA( 0, 0, 0, 0, PM_NOREMOVE ); /* create a msg queue */
2231 if (parent_id)
2232 {
2233 BOOL ret = AttachThreadInput( GetCurrentThreadId(), parent_id, TRUE );
2234 ok( ret, "AttachThreadInput failed\n" );
2235 }
2236 if (!count) ret = ShowCursor( FALSE );
2237 else while (count--) ret = ShowCursor( TRUE );
2238 SetEvent( event_start );
2239 WaitForSingleObject( event_next, 2000 );
2240 return ret;
2241 }
2242
2243 static void test_ShowCursor(void)
2244 {
2245 int count;
2246 DWORD id, result;
2247 HANDLE thread;
2248 CURSORINFO info;
2249
2250 if (pGetCursorInfo)
2251 {
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" );
2256 }
2257
2258 event_start = CreateEventW( NULL, FALSE, FALSE, NULL );
2259 event_next = CreateEventW( NULL, FALSE, FALSE, NULL );
2260
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 );
2273
2274 if (pGetCursorInfo)
2275 {
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" );
2280 }
2281
2282 parent_id = 0;
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 );
2293
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 );
2304
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 );
2316
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 );
2327
2328 if (pGetCursorInfo)
2329 {
2330 info.cbSize = sizeof(info);
2331 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2332 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2333 }
2334
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 );
2339
2340 if (pGetCursorInfo)
2341 {
2342 info.cbSize = sizeof(info);
2343 ok( pGetCursorInfo( &info ), "GetCursorInfo failed\n" );
2344 ok( info.flags & CURSOR_SHOWING, "cursor not shown in info\n" );
2345 }
2346 }
2347
2348
2349 static void test_DestroyCursor(void)
2350 {
2351 static const BYTE bmp_bits[4096];
2352 ICONINFO cursorInfo, new_info;
2353 HCURSOR cursor, cursor2, new_cursor;
2354 BOOL ret;
2355 DWORD error;
2356 UINT display_bpp;
2357 HDC hdc;
2358
2359 hdc = GetDC(0);
2360 display_bpp = GetDeviceCaps(hdc, BITSPIXEL);
2361 ReleaseDC(0, hdc);
2362
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);
2368
2369 cursor = CreateIconIndirect(&cursorInfo);
2370 ok(cursor != NULL, "CreateIconIndirect returned %p\n", cursor);
2371 if(!cursor) {
2372 return;
2373 }
2374 SetCursor(cursor);
2375
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);
2381
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);
2385 else
2386 ok(new_cursor == cursor, "GetCursor returned %p/%p\n", new_cursor, cursor);
2387
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() );
2394
2395 if (ret) /* nt4 delays destruction until cursor changes */
2396 {
2397 DeleteObject( new_info.hbmColor );
2398 DeleteObject( new_info.hbmMask );
2399
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() );
2405
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() );
2411 }
2412 else
2413 {
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() );
2420
2421 SetLastError(0xdeadbeef);
2422 ret = DestroyCursor( cursor );
2423 if (new_cursor != cursor) /* win9x */
2424 ok( ret, "DestroyCursor succeeded\n" );
2425 else
2426 ok( !ret, "DestroyCursor succeeded\n" );
2427 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2428 "wrong error %u\n", GetLastError() );
2429
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() );
2435 }
2436
2437 cursor2 = GetCursor();
2438 ok(cursor2 == new_cursor, "GetCursor returned %p/%p\n", cursor2, new_cursor);
2439
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);
2444 else
2445 ok(!cursor2, "SetCursor returned %p/%p\n", cursor2, cursor);
2446 ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
2447
2448 cursor2 = GetCursor();
2449 ok(!cursor2, "GetCursor returned %p/%p\n", cursor2, cursor);
2450
2451 SetLastError(0xdeadbeef);
2452 ret = DestroyCursor(cursor);
2453 if (new_cursor != cursor) /* win9x */
2454 ok( ret, "DestroyCursor succeeded\n" );
2455 else
2456 ok( !ret, "DestroyCursor succeeded\n" );
2457 ok( GetLastError() == ERROR_INVALID_CURSOR_HANDLE || GetLastError() == 0xdeadbeef,
2458 "wrong error %u\n", GetLastError() );
2459
2460 DeleteObject(cursorInfo.hbmMask);
2461 DeleteObject(cursorInfo.hbmColor);
2462
2463 /* Try testing DestroyCursor() now using LoadCursor() cursors. */
2464 cursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
2465
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);
2471
2472 /* Try setting the cursor to a destroyed OEM cursor. */
2473 SetLastError(0xdeadbeef);
2474 SetCursor(cursor);
2475 error = GetLastError();
2476 ok(error == 0xdeadbeef, "Last error: 0x%08x\n", error);
2477
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);
2481
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);
2485 }
2486
2487 START_TEST(cursoricon)
2488 {
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);
2494
2495 if (test_argc >= 3)
2496 {
2497 /* Child process. */
2498 sscanf (test_argv[2], "%x", (unsigned int *) &parent);
2499
2500 ok(parent != NULL, "Parent not found.\n");
2501 if (parent == NULL)
2502 ExitProcess(1);
2503
2504 do_child();
2505 return;
2506 }
2507
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();
2515 test_CreateIcon();
2516 test_LoadImage();
2517 test_CreateIconFromResource();
2518 test_GetCursorFrameInfo();
2519 test_DrawIcon();
2520 test_DrawIconEx();
2521 test_DrawState();
2522 test_SetCursor();
2523 test_ShowCursor();
2524 test_DestroyCursor();
2525 do_parent();
2526 test_child_process();
2527 finish_child_process();
2528 }