1 
2 #include "precomp.h"
3 
4 START_TEST(LoadImage)
5 {
6     char path[MAX_PATH];
7     PROCESS_INFORMATION pi;
8     STARTUPINFO si;
9     HANDLE handle;
10 
11     char **test_argv;
12     int argc = winetest_get_mainargs( &test_argv );
13 
14     /* Now check its behaviour regarding Shared icons/cursors */
15     handle = LoadImageW( GetModuleHandle(NULL), L"TESTCURSOR", IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE );
16     ok(handle != 0, "\n");
17 
18     if (argc >= 3)
19     {
20         HANDLE arg;
21         HICON hCopy;
22         HBITMAP hbmp;
23         HDC hdc, hdcScreen;
24         ICONINFO ii;
25 
26         sscanf (test_argv[2], "%Iu", (ULONG_PTR*) &arg);
27 
28         ok(handle != arg, "Got same handles\n");
29 
30         /* Try copying it */
31         hCopy = CopyIcon(arg);
32         ok(hCopy != NULL, "\n");
33         ok(DestroyIcon(hCopy), "\n");
34 
35         hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, 0);
36         ok(hCopy != NULL, "\n");
37         ok(DestroyIcon(hCopy), "\n");
38         /* Unlike the original, this one is not shared */
39         ok(!DestroyIcon(hCopy), "\n");
40 
41         hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE);
42         ok(hCopy != NULL, "\n");
43         ok(DestroyIcon(hCopy), "\n");
44         /* Unlike the original, this one is not shared */
45         ok(!DestroyIcon(hCopy), "\n");
46 
47         hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE | LR_SHARED);
48         ok(hCopy != NULL, "\n");
49         ok(DestroyIcon(hCopy), "\n");
50         /* This one is shared */
51         ok(DestroyIcon(hCopy), "\n");
52 
53         hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_SHARED);
54         ok(hCopy != NULL, "\n");
55         ok(DestroyIcon(hCopy), "DestroyIcon should succeed.\n");
56         /* This one is shared */
57         ok(DestroyIcon(hCopy) == 0, "DestroyIcon should fail.\n");
58 
59         /* Try various usual functions */
60         hdcScreen = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
61         ok(hdcScreen != NULL, "\n");
62         hdc = CreateCompatibleDC(hdcScreen);
63         ok(hdc != NULL, "\n");
64         hbmp = CreateCompatibleBitmap(hdcScreen, 64, 64);
65         ok(hbmp != NULL, "\n");
66         hbmp = SelectObject(hdc, hbmp);
67         ok(hbmp != NULL, "\n");
68 
69         ok(DrawIcon(hdc, 0, 0, arg), "\n");
70         hbmp = SelectObject(hdc, hbmp);
71         DeleteObject(hbmp);
72         DeleteDC(hdc);
73         DeleteDC(hdcScreen);
74 
75         ok(GetIconInfo(arg, &ii), "\n");
76         ok(ii.hbmMask != NULL, "\n");
77         DeleteObject(ii.hbmMask);
78         if(ii.hbmColor) DeleteObject(ii.hbmColor);
79 
80         return;
81     }
82 
83     /* Start child process */
84     sprintf( path, "%s LoadImage %Iu", test_argv[0], (ULONG_PTR)handle );
85     memset( &si, 0, sizeof(si) );
86     si.cb = sizeof(si);
87     CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
88     WaitForSingleObject (pi.hProcess, INFINITE);
89 }
90