- Remove WIP comment -- the fix is correct
[reactos.git] / rostests / tests / Imagelistviewer / main.c
1 #include <windows.h>
2 #include <setupapi.h>
3 #include <tchar.h>
4 #include <stdlib.h>
5 #include "resource.h"
6
7 typedef BOOL (WINAPI * SH_GIL_PROC)(HIMAGELIST *phLarge, HIMAGELIST *phSmall);
8 typedef BOOL (WINAPI * FII_PROC)(BOOL fFullInit);
9
10 /*** Shell32 undoc'd functions ***/
11 /* Shell_GetImageLists @71 */
12 /* FileIconInit @660 */
13
14 BOOL
15 DisplayImageList(HWND hwnd,
16 UINT uID)
17 {
18 HWND hLV;
19 SP_CLASSIMAGELIST_DATA ImageListData;
20 LV_ITEM lvItem;
21 TCHAR Buf[6];
22 INT ImageListCount = -1;
23 INT i = 0;
24
25 hLV = GetDlgItem(hwnd, IDC_LSTVIEW);
26 (void)ListView_DeleteAllItems(hLV);
27
28 if (uID == IDC_SYSTEM)
29 {
30 HIMAGELIST hLarge, hSmall;
31 HMODULE hShell32;
32 SH_GIL_PROC Shell_GetImageLists;
33 FII_PROC FileIconInit;
34
35 hShell32 = LoadLibrary(_T("shell32.dll"));
36 if(hShell32 == NULL)
37 return FALSE;
38
39 Shell_GetImageLists = (SH_GIL_PROC)GetProcAddress(hShell32, (LPCSTR)71);
40 FileIconInit = (FII_PROC)GetProcAddress(hShell32, (LPCSTR)660);
41
42 if(Shell_GetImageLists == NULL || FileIconInit == NULL)
43 {
44 FreeLibrary(hShell32);
45 return FALSE;
46 }
47
48 FileIconInit(TRUE);
49
50 Shell_GetImageLists(&hLarge, &hSmall);
51
52 ImageListCount = ImageList_GetImageCount(hSmall);
53
54 (void)ListView_SetImageList(hLV,
55 hSmall,
56 LVSIL_SMALL);
57
58 FreeLibrary(hShell32);
59 }
60 else if (uID == IDC_DEVICE)
61 {
62 ImageListData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);
63 SetupDiGetClassImageList(&ImageListData);
64
65 ImageListCount = ImageList_GetImageCount(ImageListData.ImageList);
66
67 (void)ListView_SetImageList(hLV,
68 ImageListData.ImageList,
69 LVSIL_SMALL);
70 }
71 else
72 return FALSE;
73
74 lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
75
76 while (i <= ImageListCount)
77 {
78 lvItem.iItem = i;
79 lvItem.iSubItem = 0;
80 lvItem.pszText = _itot(i, Buf, 10);
81 lvItem.iImage = i;
82
83 (void)ListView_InsertItem(hLV, &lvItem);
84
85 i++;
86 }
87
88 return TRUE;
89 }
90
91
92 BOOL CALLBACK
93 DlgProc(HWND hwnd,
94 UINT message,
95 WPARAM wParam,
96 LPARAM lParam)
97 {
98 switch (message)
99 {
100 case WM_INITDIALOG:
101 DisplayImageList(hwnd, IDC_SYSTEM);
102 return TRUE;
103
104 case WM_CLOSE:
105 EndDialog(hwnd, 0);
106 return TRUE;
107
108 case WM_COMMAND:
109 {
110 switch(LOWORD(wParam))
111 {
112 case IDOK:
113 EndDialog(hwnd, 0);
114 return TRUE;
115
116 case IDC_SYSTEM:
117 DisplayImageList(hwnd, IDC_SYSTEM);
118 return TRUE;
119
120 case IDC_DEVICE:
121 DisplayImageList(hwnd, IDC_DEVICE);
122 return TRUE;
123 }
124 }
125 }
126
127 return FALSE;
128 }
129
130 int WINAPI
131 WinMain(HINSTANCE hThisInstance,
132 HINSTANCE hPrevInstance,
133 LPSTR lpszArgument,
134 int nCmdShow)
135 {
136 INITCOMMONCONTROLSEX icex;
137
138 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
139 icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
140 InitCommonControlsEx(&icex);
141
142 return DialogBox(hThisInstance,
143 MAKEINTRESOURCE(IDD_IMGLST),
144 NULL,
145 (DLGPROC)DlgProc);
146 }