2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 WCHAR swShell32Name
[MAX_PATH
];
24 DWORD NumIconOverlayHandlers
= 0;
25 IShellIconOverlayIdentifier
** Handlers
= NULL
;
27 static HRESULT
getIconLocationForFolder(LPCITEMIDLIST pidl
, UINT uFlags
,
28 LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
31 WCHAR wszPath
[MAX_PATH
];
32 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
33 static const WCHAR shellClassInfo
[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
34 static const WCHAR iconFile
[] = { 'I', 'c', 'o', 'n', 'F', 'i', 'l', 'e', 0 };
35 static const WCHAR clsid
[] = { 'C', 'L', 'S', 'I', 'D', 0 };
36 static const WCHAR clsid2
[] = { 'C', 'L', 'S', 'I', 'D', '2', 0 };
37 static const WCHAR iconIndex
[] = { 'I', 'c', 'o', 'n', 'I', 'n', 'd', 'e', 'x', 0 };
39 if (SHELL32_GetCustomFolderAttribute(pidl
, shellClassInfo
, iconFile
,
42 WCHAR wszIconIndex
[10];
43 SHELL32_GetCustomFolderAttribute(pidl
, shellClassInfo
, iconIndex
,
45 *piIndex
= _wtoi(wszIconIndex
);
47 else if (SHELL32_GetCustomFolderAttribute(pidl
, shellClassInfo
, clsid
,
48 wszCLSIDValue
, CHARS_IN_GUID
) &&
49 HCR_GetIconW(wszCLSIDValue
, szIconFile
, NULL
, cchMax
, &icon_idx
))
53 else if (SHELL32_GetCustomFolderAttribute(pidl
, shellClassInfo
, clsid2
,
54 wszCLSIDValue
, CHARS_IN_GUID
) &&
55 HCR_GetIconW(wszCLSIDValue
, szIconFile
, NULL
, cchMax
, &icon_idx
))
61 static const WCHAR folder
[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 };
63 if (!HCR_GetIconW(folder
, szIconFile
, NULL
, cchMax
, &icon_idx
))
65 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
66 icon_idx
= -IDI_SHELL_FOLDER
;
69 if (uFlags
& GIL_OPENICON
)
70 *piIndex
= icon_idx
< 0 ? icon_idx
- 1 : icon_idx
+ 1;
78 void InitIconOverlays(void)
81 DWORD dwIndex
, dwResult
, dwSize
;
82 WCHAR szName
[MAX_PATH
];
85 IShellIconOverlayIdentifier
* Overlay
;
87 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers", 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
90 if (RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, &dwResult
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
96 Handlers
= (IShellIconOverlayIdentifier
**)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwResult
* sizeof(IShellIconOverlayIdentifier
*));
109 dwSize
= sizeof(szName
) / sizeof(WCHAR
);
110 dwResult
= RegEnumKeyExW(hKey
, dwIndex
, szName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
112 if (dwResult
== ERROR_NO_MORE_ITEMS
)
115 if (dwResult
== ERROR_SUCCESS
)
117 dwSize
= sizeof(szValue
) / sizeof(WCHAR
);
118 if (RegGetValueW(hKey
, szName
, NULL
, RRF_RT_REG_SZ
, NULL
, szValue
, &dwSize
) == ERROR_SUCCESS
)
121 CLSIDFromString(szValue
, &clsid
);
122 dwResult
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
, IID_IUnknown
, (LPVOID
*)&Overlay
);
123 if (dwResult
== S_OK
)
125 Handlers
[NumIconOverlayHandlers
] = Overlay
;
126 NumIconOverlayHandlers
++;
139 GetIconOverlay(LPCITEMIDLIST pidl
, WCHAR
* wTemp
, int* pIndex
)
147 WCHAR szPath
[MAX_PATH
];
149 if(!SHGetPathFromIDListW(pidl
, szPath
))
153 HighestPriority
= 101;
154 IconIndex
= NumIconOverlayHandlers
;
155 for(Index
= 0; Index
< NumIconOverlayHandlers
; Index
++)
157 hResult
= Handlers
[Index
]->IsMemberOf(szPath
, SFGAO_FILESYSTEM
);
160 hResult
= Handlers
[Index
]->GetPriority(&Priority
);
163 if (Priority
< HighestPriority
)
165 HighestPriority
= Priority
;
172 if (IconIndex
== NumIconOverlayHandlers
)
175 hResult
= Handlers
[IconIndex
]->GetOverlayInfo(wTemp
, MAX_PATH
, pIndex
, &Flags
);
183 /**************************************************************************
184 * IExtractIconW_Constructor
186 IExtractIconW
* IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
188 CComPtr
<IDefaultExtractIconInit
> initIcon
;
189 IExtractIconW
*extractIcon
;
193 CHAR sTemp
[MAX_PATH
];
194 WCHAR wTemp
[MAX_PATH
];
195 LPITEMIDLIST pSimplePidl
= ILFindLastID(pidl
);
198 hr
= SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit
,&initIcon
));
202 hr
= initIcon
->QueryInterface(IID_PPV_ARG(IExtractIconW
,&extractIcon
));
206 if (_ILIsDesktop(pSimplePidl
))
208 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_DESKTOP
);
210 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
212 /* my computer and other shell extensions */
213 static const WCHAR fmt
[] = { 'C', 'L', 'S', 'I', 'D', '\\',
214 '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-',
215 '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x',
216 '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0
221 riid
->Data1
, riid
->Data2
, riid
->Data3
,
222 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
223 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
225 const WCHAR
* iconname
= NULL
;
226 if (_ILIsBitBucket(pSimplePidl
))
228 static const WCHAR szFull
[] = {'F','u','l','l',0};
229 static const WCHAR szEmpty
[] = {'E','m','p','t','y',0};
230 IEnumIDList
*EnumIDList
= NULL
;
233 IShellFolder2
*psfRecycleBin
= NULL
;
234 IShellFolder
*psfDesktop
= NULL
;
235 hr
= SHGetDesktopFolder(&psfDesktop
);
238 hr
= psfDesktop
->BindToObject(pSimplePidl
, NULL
, IID_IShellFolder2
, (void**) &psfRecycleBin
);
240 hr
= psfRecycleBin
->EnumObjects(NULL
, SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
, &EnumIDList
);
243 LPITEMIDLIST pidl
= NULL
;
244 if (SUCCEEDED(hr
) && (hr
= EnumIDList
->Next(1, &pidl
, &itemcount
)) == S_OK
)
253 psfDesktop
->Release();
255 psfRecycleBin
->Release();
257 EnumIDList
->Release();
260 if (HCR_GetIconW(xriid
, wTemp
, iconname
, MAX_PATH
, &icon_idx
))
262 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
266 if (IsEqualGUID(*riid
, CLSID_MyComputer
))
267 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_MY_COMPUTER
);
268 else if (IsEqualGUID(*riid
, CLSID_MyDocuments
))
269 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_MY_DOCUMENTS
);
270 else if (IsEqualGUID(*riid
, CLSID_NetworkPlaces
))
271 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_MY_NETWORK_PLACES
);
273 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_FOLDER
);
277 else if (_ILIsDrive (pSimplePidl
))
279 static const WCHAR drive
[] = { 'D', 'r', 'i', 'v', 'e', 0 };
282 if (_ILGetDrive(pSimplePidl
, sTemp
, MAX_PATH
))
284 switch(GetDriveTypeA(sTemp
))
286 case DRIVE_REMOVABLE
:
287 icon_idx
= IDI_SHELL_FLOPPY
;
290 icon_idx
= IDI_SHELL_CDROM
;
293 icon_idx
= IDI_SHELL_NETDRIVE
;
296 icon_idx
= IDI_SHELL_RAMDISK
;
298 case DRIVE_NO_ROOT_DIR
:
299 icon_idx
= IDI_SHELL_CDROM
;
306 initIcon
->SetNormalIcon(swShell32Name
, -icon_idx
);
310 if (HCR_GetIconW(drive
, wTemp
, NULL
, MAX_PATH
, &icon_idx
))
311 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
313 initIcon
->SetNormalIcon(swShell32Name
, -IDI_SHELL_DRIVE
);
317 else if (_ILIsFolder (pSimplePidl
))
319 if (SUCCEEDED(getIconLocationForFolder(
320 pidl
, 0, wTemp
, MAX_PATH
,
324 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
326 if (SUCCEEDED(getIconLocationForFolder(
327 pidl
, GIL_DEFAULTICON
, wTemp
, MAX_PATH
,
331 initIcon
->SetDefaultIcon(wTemp
, icon_idx
);
333 if (SUCCEEDED(getIconLocationForFolder(
334 pidl
, GIL_FORSHORTCUT
, wTemp
, MAX_PATH
,
338 initIcon
->SetShortcutIcon(wTemp
, icon_idx
);
340 if (SUCCEEDED(getIconLocationForFolder(
341 pidl
, GIL_OPENICON
, wTemp
, MAX_PATH
,
345 initIcon
->SetOpenIcon(wTemp
, icon_idx
);
352 if (_ILIsCPanelStruct(pSimplePidl
))
354 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, wTemp
, MAX_PATH
, &icon_idx
)))
357 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
359 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
360 && HCR_GetIconA(sTemp
, sTemp
, NULL
, MAX_PATH
, &icon_idx
))
362 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
364 SHGetPathFromIDListW(pidl
, wTemp
);
369 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, wTemp
, MAX_PATH
);
374 else if (!lstrcmpiA(sTemp
, "lnkfile"))
376 /* extract icon from shell shortcut */
377 CComPtr
<IShellFolder
> dsf
;
378 CComPtr
<IShellLinkW
> psl
;
380 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
382 HRESULT hr
= dsf
->GetUIObjectOf(NULL
, 1, (LPCITEMIDLIST
*)&pidl
, IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
386 hr
= psl
->GetIconLocation(wTemp
, MAX_PATH
, &icon_idx
);
388 if (SUCCEEDED(hr
) && *sTemp
)
398 initIcon
->SetNormalIcon(swShell32Name
, 0);
400 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
406 /**************************************************************************
407 * IExtractIconA_Constructor
409 IExtractIconA
* IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
411 IExtractIconW
*extractIconW
;
412 IExtractIconA
*extractIconA
;
415 extractIconW
= IExtractIconW_Constructor(pidl
);
419 hr
= extractIconW
->QueryInterface(IID_PPV_ARG(IExtractIconA
, &extractIconA
));
420 extractIconW
->Release();