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