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 INT_PTR CALLBACK 92 DlgProc(HWND hwnd, 93 UINT message, 94 WPARAM wParam, 95 LPARAM lParam) 96 { 97 switch (message) 98 { 99 case WM_INITDIALOG: 100 DisplayImageList(hwnd, IDC_SYSTEM); 101 return TRUE; 102 103 case WM_CLOSE: 104 EndDialog(hwnd, 0); 105 return TRUE; 106 107 case WM_COMMAND: 108 { 109 switch(LOWORD(wParam)) 110 { 111 case IDOK: 112 EndDialog(hwnd, 0); 113 return TRUE; 114 115 case IDC_SYSTEM: 116 DisplayImageList(hwnd, IDC_SYSTEM); 117 return TRUE; 118 119 case IDC_DEVICE: 120 DisplayImageList(hwnd, IDC_DEVICE); 121 return TRUE; 122 } 123 } 124 } 125 126 return FALSE; 127 } 128 129 int WINAPI 130 WinMain(HINSTANCE hThisInstance, 131 HINSTANCE hPrevInstance, 132 LPSTR lpszArgument, 133 int nCmdShow) 134 { 135 INITCOMMONCONTROLSEX icex; 136 137 icex.dwSize = sizeof(INITCOMMONCONTROLSEX); 138 icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; 139 InitCommonControlsEx(&icex); 140 141 return DialogBox(hThisInstance, 142 MAKEINTRESOURCE(IDD_IMGLST), 143 NULL, 144 DlgProc); 145 } 146