2 * shell icon cache (SIC)
4 * Copyright 1998, 1999 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #include <sys/types.h>
38 #include "wine/debug.h"
43 #include "shell32_main.h"
44 #include "undocshell.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
49 /********************** THE ICON CACHE ********************************/
51 #define INVALID_INDEX -1
55 LPWSTR sSourceFile
; /* file (not path!) containing the icon */
56 DWORD dwSourceIndex
; /* index within the file, if it is a resource ID it will be negated */
57 DWORD dwListIndex
; /* index within the iconlist */
58 DWORD dwFlags
; /* GIL_* flags */
60 } SIC_ENTRY
, * LPSIC_ENTRY
;
62 static HDPA sic_hdpa
= 0;
64 static CRITICAL_SECTION SHELL32_SicCS
;
65 static CRITICAL_SECTION_DEBUG critsect_debug
=
68 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
69 0, 0, { (DWORD_PTR
)(__FILE__
": SHELL32_SicCS") }
71 static CRITICAL_SECTION SHELL32_SicCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
73 /*****************************************************************************
77 * Callback for DPA_Search
79 static INT CALLBACK
SIC_CompareEntries( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
81 LPSIC_ENTRY e1
= p1
, e2
= p2
;
83 TRACE("%p %p %8lx\n", p1
, p2
, lparam
);
85 /* Icons in the cache are keyed by the name of the file they are
86 * loaded from, their resource index and the fact if they have a shortcut
87 * icon overlay or not.
89 if (e1
->dwSourceIndex
!= e2
->dwSourceIndex
|| /* first the faster one */
90 (e1
->dwFlags
& GIL_FORSHORTCUT
) != (e2
->dwFlags
& GIL_FORSHORTCUT
))
93 if (strcmpiW(e1
->sSourceFile
,e2
->sSourceFile
))
99 /* declare SIC_LoadOverlayIcon() */
100 static int SIC_LoadOverlayIcon(int icon_idx
);
102 /*****************************************************************************
103 * SIC_OverlayShortcutImage [internal]
106 * Creates a new icon as a copy of the passed-in icon, overlayed with a
109 static HICON
SIC_OverlayShortcutImage(HICON SourceIcon
, BOOL large
)
110 { ICONINFO SourceIconInfo
, ShortcutIconInfo
, TargetIconInfo
;
111 HICON ShortcutIcon
, TargetIcon
;
112 BITMAP SourceBitmapInfo
, ShortcutBitmapInfo
;
117 HBITMAP OldSourceBitmap
= NULL
,
118 OldShortcutBitmap
= NULL
,
119 OldTargetBitmap
= NULL
;
121 static int s_imgListIdx
= -1;
123 /* Get information about the source icon and shortcut overlay */
124 if (! GetIconInfo(SourceIcon
, &SourceIconInfo
)
125 || 0 == GetObjectW(SourceIconInfo
.hbmColor
, sizeof(BITMAP
), &SourceBitmapInfo
))
130 /* search for the shortcut icon only once */
131 if (s_imgListIdx
== -1)
132 s_imgListIdx
= SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT
);
133 /* FIXME should use icon index 29 instead of the
134 resource id, but not all icons are present yet
135 so we can't use icon indices */
137 if (s_imgListIdx
!= -1)
140 ShortcutIcon
= ImageList_GetIcon(ShellBigIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
142 ShortcutIcon
= ImageList_GetIcon(ShellSmallIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
146 if (NULL
== ShortcutIcon
147 || ! GetIconInfo(ShortcutIcon
, &ShortcutIconInfo
)
148 || 0 == GetObjectW(ShortcutIconInfo
.hbmColor
, sizeof(BITMAP
), &ShortcutBitmapInfo
))
153 TargetIconInfo
= SourceIconInfo
;
154 TargetIconInfo
.hbmMask
= NULL
;
155 TargetIconInfo
.hbmColor
= NULL
;
157 /* Setup the source, shortcut and target masks */
158 SourceDC
= CreateCompatibleDC(NULL
);
159 if (NULL
== SourceDC
) goto fail
;
160 OldSourceBitmap
= SelectObject(SourceDC
, SourceIconInfo
.hbmMask
);
161 if (NULL
== OldSourceBitmap
) goto fail
;
163 ShortcutDC
= CreateCompatibleDC(NULL
);
164 if (NULL
== ShortcutDC
) goto fail
;
165 OldShortcutBitmap
= SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmMask
);
166 if (NULL
== OldShortcutBitmap
) goto fail
;
168 TargetDC
= CreateCompatibleDC(NULL
);
169 if (NULL
== TargetDC
) goto fail
;
170 TargetIconInfo
.hbmMask
= CreateCompatibleBitmap(TargetDC
, SourceBitmapInfo
.bmWidth
,
171 SourceBitmapInfo
.bmHeight
);
172 if (NULL
== TargetIconInfo
.hbmMask
) goto fail
;
173 ScreenDC
= GetDC(NULL
);
174 if (NULL
== ScreenDC
) goto fail
;
175 TargetIconInfo
.hbmColor
= CreateCompatibleBitmap(ScreenDC
, SourceBitmapInfo
.bmWidth
,
176 SourceBitmapInfo
.bmHeight
);
177 ReleaseDC(NULL
, ScreenDC
);
178 if (NULL
== TargetIconInfo
.hbmColor
) goto fail
;
179 OldTargetBitmap
= SelectObject(TargetDC
, TargetIconInfo
.hbmMask
);
180 if (NULL
== OldTargetBitmap
) goto fail
;
182 /* Create the target mask by ANDing the source and shortcut masks */
183 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
184 SourceDC
, 0, 0, SRCCOPY
) ||
185 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
186 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
187 ShortcutDC
, 0, 0, SRCAND
))
192 /* Setup the source and target xor bitmap */
193 if (NULL
== SelectObject(SourceDC
, SourceIconInfo
.hbmColor
) ||
194 NULL
== SelectObject(TargetDC
, TargetIconInfo
.hbmColor
))
199 /* Copy the source xor bitmap to the target and clear out part of it by using
201 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
202 SourceDC
, 0, 0, SRCCOPY
) ||
203 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
204 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
205 ShortcutDC
, 0, 0, SRCAND
))
210 if (NULL
== SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmColor
)) goto fail
;
212 /* Now put in the shortcut xor mask */
213 if (! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
214 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
215 ShortcutDC
, 0, 0, SRCINVERT
))
220 /* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set
222 SelectObject(TargetDC
, OldTargetBitmap
);
223 DeleteObject(TargetDC
);
224 SelectObject(ShortcutDC
, OldShortcutBitmap
);
225 DeleteObject(ShortcutDC
);
226 SelectObject(SourceDC
, OldSourceBitmap
);
227 DeleteObject(SourceDC
);
229 /* Create the icon using the bitmaps prepared earlier */
230 TargetIcon
= CreateIconIndirect(&TargetIconInfo
);
232 /* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */
233 DeleteObject(TargetIconInfo
.hbmColor
);
234 DeleteObject(TargetIconInfo
.hbmMask
);
239 /* Clean up scratch resources we created */
240 if (NULL
!= OldTargetBitmap
) SelectObject(TargetDC
, OldTargetBitmap
);
241 if (NULL
!= TargetIconInfo
.hbmColor
) DeleteObject(TargetIconInfo
.hbmColor
);
242 if (NULL
!= TargetIconInfo
.hbmMask
) DeleteObject(TargetIconInfo
.hbmMask
);
243 if (NULL
!= TargetDC
) DeleteObject(TargetDC
);
244 if (NULL
!= OldShortcutBitmap
) SelectObject(ShortcutDC
, OldShortcutBitmap
);
245 if (NULL
!= ShortcutDC
) DeleteObject(ShortcutDC
);
246 if (NULL
!= OldSourceBitmap
) SelectObject(SourceDC
, OldSourceBitmap
);
247 if (NULL
!= SourceDC
) DeleteObject(SourceDC
);
252 /*****************************************************************************
253 * SIC_IconAppend [internal]
256 * appends an icon pair to the end of the cache
258 static INT
SIC_IconAppend (LPCWSTR sSourceFile
, INT dwSourceIndex
, HICON hSmallIcon
, HICON hBigIcon
, DWORD dwFlags
)
259 { LPSIC_ENTRY lpsice
;
260 INT ret
, index
, index1
;
261 WCHAR path
[MAX_PATH
];
262 TRACE("%s %i %p %p\n", debugstr_w(sSourceFile
), dwSourceIndex
, hSmallIcon
,hBigIcon
);
264 lpsice
= SHAlloc(sizeof(SIC_ENTRY
));
266 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
267 lpsice
->sSourceFile
= HeapAlloc( GetProcessHeap(), 0, (strlenW(path
)+1)*sizeof(WCHAR
) );
268 strcpyW( lpsice
->sSourceFile
, path
);
270 lpsice
->dwSourceIndex
= dwSourceIndex
;
271 lpsice
->dwFlags
= dwFlags
;
273 EnterCriticalSection(&SHELL32_SicCS
);
275 index
= DPA_InsertPtr(sic_hdpa
, 0x7fff, lpsice
);
276 if ( INVALID_INDEX
== index
)
278 HeapFree(GetProcessHeap(), 0, lpsice
->sSourceFile
);
284 index
= ImageList_AddIcon (ShellSmallIconList
, hSmallIcon
);
285 index1
= ImageList_AddIcon (ShellBigIconList
, hBigIcon
);
289 FIXME("iconlists out of sync 0x%x 0x%x\n", index
, index1
);
291 lpsice
->dwListIndex
= index
;
292 ret
= lpsice
->dwListIndex
;
295 LeaveCriticalSection(&SHELL32_SicCS
);
298 /****************************************************************************
299 * SIC_LoadIcon [internal]
302 * gets small/big icon by number from a file
304 static INT
SIC_LoadIcon (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
305 { HICON hiconLarge
=0;
307 HICON hiconLargeShortcut
;
308 HICON hiconSmallShortcut
;
310 PrivateExtractIconsW( sSourceFile
, dwSourceIndex
, 32, 32, &hiconLarge
, 0, 1, 0 );
311 PrivateExtractIconsW( sSourceFile
, dwSourceIndex
, 16, 16, &hiconSmall
, 0, 1, 0 );
313 if ( !hiconLarge
|| !hiconSmall
)
315 WARN("failure loading icon %i from %s (%p %p)\n", dwSourceIndex
, debugstr_w(sSourceFile
), hiconLarge
, hiconSmall
);
319 if (0 != (dwFlags
& GIL_FORSHORTCUT
))
321 hiconLargeShortcut
= SIC_OverlayShortcutImage(hiconLarge
, TRUE
);
322 hiconSmallShortcut
= SIC_OverlayShortcutImage(hiconSmall
, FALSE
);
323 if (NULL
!= hiconLargeShortcut
&& NULL
!= hiconSmallShortcut
)
325 hiconLarge
= hiconLargeShortcut
;
326 hiconSmall
= hiconSmallShortcut
;
330 WARN("Failed to create shortcut overlayed icons\n");
331 if (NULL
!= hiconLargeShortcut
) DestroyIcon(hiconLargeShortcut
);
332 if (NULL
!= hiconSmallShortcut
) DestroyIcon(hiconSmallShortcut
);
333 dwFlags
&= ~ GIL_FORSHORTCUT
;
337 return SIC_IconAppend (sSourceFile
, dwSourceIndex
, hiconSmall
, hiconLarge
, dwFlags
);
339 /*****************************************************************************
340 * SIC_GetIconIndex [internal]
343 * sSourceFile [IN] filename of file containing the icon
344 * index [IN] index/resID (negated) in this file
347 * look in the cache for a proper icon. if not available the icon is taken
348 * from the file and cached
350 INT
SIC_GetIconIndex (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
353 INT ret
, index
= INVALID_INDEX
;
354 WCHAR path
[MAX_PATH
];
356 TRACE("%s %i\n", debugstr_w(sSourceFile
), dwSourceIndex
);
358 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
359 sice
.sSourceFile
= path
;
360 sice
.dwSourceIndex
= dwSourceIndex
;
361 sice
.dwFlags
= dwFlags
;
363 EnterCriticalSection(&SHELL32_SicCS
);
365 if (NULL
!= DPA_GetPtr (sic_hdpa
, 0))
367 /* search linear from position 0*/
368 index
= DPA_Search (sic_hdpa
, &sice
, 0, SIC_CompareEntries
, 0, 0);
371 if ( INVALID_INDEX
== index
)
373 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
, dwFlags
);
378 ret
= ((LPSIC_ENTRY
)DPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
381 LeaveCriticalSection(&SHELL32_SicCS
);
384 /*****************************************************************************
385 * SIC_Initialize [internal]
387 BOOL
SIC_Initialize(void)
390 int cx_small
, cy_small
;
391 int cx_large
, cy_large
;
393 cx_small
= GetSystemMetrics(SM_CXSMICON
);
394 cy_small
= GetSystemMetrics(SM_CYSMICON
);
395 cx_large
= GetSystemMetrics(SM_CXICON
);
396 cy_large
= GetSystemMetrics(SM_CYICON
);
400 if (sic_hdpa
) /* already initialized?*/
403 sic_hdpa
= DPA_Create(16);
410 ShellSmallIconList
= ImageList_Create(cx_small
,cy_small
,ILC_COLOR32
|ILC_MASK
,0,0x20);
411 ShellBigIconList
= ImageList_Create(cx_large
,cy_large
,ILC_COLOR32
|ILC_MASK
,0,0x20);
413 ImageList_SetBkColor(ShellSmallIconList
, CLR_NONE
);
414 ImageList_SetBkColor(ShellBigIconList
, CLR_NONE
);
416 /* Load the document icon, which is used as the default if an icon isn't found. */
417 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT
),
418 IMAGE_ICON
, cx_small
, cy_small
, LR_SHARED
);
419 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT
),
420 IMAGE_ICON
, cx_large
, cy_large
, LR_SHARED
);
424 FIXME("Failed to load IDI_SHELL_DOCUMENT icon!\n");
428 SIC_IconAppend (swShell32Name
, IDI_SHELL_DOCUMENT
-1, hSm
, hLg
, 0);
429 SIC_IconAppend (swShell32Name
, -IDI_SHELL_DOCUMENT
, hSm
, hLg
, 0);
431 TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList
, ShellBigIconList
);
435 /*************************************************************************
440 static INT CALLBACK
sic_free( LPVOID ptr
, LPVOID lparam
)
442 HeapFree(GetProcessHeap(), 0, ((LPSIC_ENTRY
)ptr
)->sSourceFile
);
447 void SIC_Destroy(void)
451 EnterCriticalSection(&SHELL32_SicCS
);
453 if (sic_hdpa
) DPA_DestroyCallback(sic_hdpa
, sic_free
, NULL
);
456 ImageList_Destroy(ShellSmallIconList
);
457 ShellSmallIconList
= 0;
458 ImageList_Destroy(ShellBigIconList
);
459 ShellBigIconList
= 0;
461 LeaveCriticalSection(&SHELL32_SicCS
);
462 DeleteCriticalSection(&SHELL32_SicCS
);
465 /*****************************************************************************
466 * SIC_LoadOverlayIcon [internal]
468 * Load a shell overlay icon and return its icon cache index.
470 static int SIC_LoadOverlayIcon(int icon_idx
)
472 WCHAR buffer
[1024], wszIdx
[8];
477 static const WCHAR wszShellIcons
[] = {
478 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
479 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
480 'E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','I','c','o','n','s',0
482 static const WCHAR wszNumFmt
[] = {'%','d',0};
484 iconPath
= swShell32Name
; /* default: load icon from shell32.dll */
487 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszShellIcons
, 0, KEY_READ
, &hKeyShellIcons
) == ERROR_SUCCESS
)
489 DWORD count
= sizeof(buffer
);
491 sprintfW(wszIdx
, wszNumFmt
, icon_idx
);
493 /* read icon path and index */
494 if (RegQueryValueExW(hKeyShellIcons
, wszIdx
, NULL
, NULL
, (LPBYTE
)buffer
, &count
) == ERROR_SUCCESS
)
496 LPWSTR p
= strchrW(buffer
, ',');
500 ERR("Icon index in %s/%s corrupted, no comma.\n", debugstr_w(wszShellIcons
),debugstr_w(wszIdx
));
501 RegCloseKey(hKeyShellIcons
);
509 RegCloseKey(hKeyShellIcons
);
512 return SIC_LoadIcon(iconPath
, iconIdx
, 0);
515 /*************************************************************************
516 * Shell_GetImageList [SHELL32.71]
519 * imglist[1|2] [OUT] pointer which receives imagelist handles
522 BOOL WINAPI
Shell_GetImageList(HIMAGELIST
* lpBigList
, HIMAGELIST
* lpSmallList
)
523 { TRACE("(%p,%p)\n",lpBigList
,lpSmallList
);
525 { *lpBigList
= ShellBigIconList
;
528 { *lpSmallList
= ShellSmallIconList
;
533 /*************************************************************************
534 * PidlToSicIndex [INTERNAL]
537 * sh [IN] IShellFolder
541 * pIndex [OUT] index within the SIC
544 BOOL
PidlToSicIndex (
552 WCHAR szIconFile
[MAX_PATH
]; /* file containing the icon */
553 INT iSourceIndex
; /* index or resID(negated) in this file */
556 int iShortcutDefaultIndex
= INVALID_INDEX
;
558 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
560 if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh
, 0, 1, &pidl
, &IID_IExtractIconW
, 0, (void **)&ei
)))
562 if (SUCCEEDED(IExtractIconW_GetIconLocation(ei
, uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
564 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
, uFlags
);
567 IExtractIconW_Release(ei
);
570 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
572 if (0 == (uFlags
& GIL_FORSHORTCUT
))
578 if (INVALID_INDEX
== iShortcutDefaultIndex
)
580 iShortcutDefaultIndex
= SIC_LoadIcon(swShell32Name
, 0, GIL_FORSHORTCUT
);
582 *pIndex
= (INVALID_INDEX
!= iShortcutDefaultIndex
? iShortcutDefaultIndex
: 0);
590 /*************************************************************************
591 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
594 * sh [IN] pointer to an instance of IShellFolder
596 * pIndex [OUT][OPTIONAL] SIC index for big icon
599 int WINAPI
SHMapPIDLToSystemImageListIndex(
607 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
610 if (SHELL_IsShortcut(pidl
))
611 uGilFlags
|= GIL_FORSHORTCUT
;
614 if (!PidlToSicIndex ( sh
, pidl
, 1, uGilFlags
, pIndex
))
617 if (!PidlToSicIndex ( sh
, pidl
, 0, uGilFlags
, &Index
))
623 /*************************************************************************
624 * SHMapIDListToImageListIndexAsync [SHELL32.148]
626 HRESULT WINAPI
SHMapIDListToImageListIndexAsync(IUnknown
*pts
, IShellFolder
*psf
,
627 LPCITEMIDLIST pidl
, UINT flags
,
628 void *pfn
, void *pvData
, void *pvHint
,
629 int *piIndex
, int *piIndexSel
)
631 FIXME("(%p, %p, %p, 0x%08x, %p, %p, %p, %p, %p)\n",
632 pts
, psf
, pidl
, flags
, pfn
, pvData
, pvHint
, piIndex
, piIndexSel
);
636 /*************************************************************************
637 * Shell_GetCachedImageIndex [SHELL32.72]
640 static INT
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
645 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
647 len
= MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, NULL
, 0 );
648 szTemp
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
649 MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, szTemp
, len
);
651 ret
= SIC_GetIconIndex( szTemp
, nIndex
, 0 );
653 HeapFree( GetProcessHeap(), 0, szTemp
);
658 static INT
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
660 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
662 return SIC_GetIconIndex(szPath
, nIndex
, 0);
665 INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
666 { if( SHELL_OsIsUnicode())
667 return Shell_GetCachedImageIndexW(szPath
, nIndex
, bSimulateDoc
);
668 return Shell_GetCachedImageIndexA(szPath
, nIndex
, bSimulateDoc
);
671 /*************************************************************************
672 * ExtractIconExW [SHELL32.@]
675 * -1 file is not valid
676 * or number of icons extracted
678 UINT WINAPI
ExtractIconExW(LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
680 TRACE("%s %i %p %p %i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
682 return PrivateExtractIconExW(lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
685 /*************************************************************************
686 * ExtractIconExA [SHELL32.@]
688 UINT WINAPI
ExtractIconExA(LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
691 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
692 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
694 TRACE("%s %i %p %p %i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
698 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
699 ret
= ExtractIconExW(lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
700 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
705 /*************************************************************************
706 * ExtractAssociatedIconA (SHELL32.@)
708 * Return icon for given file (either from file itself or from associated
709 * executable) and patch parameters if needed.
711 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
714 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, NULL
, 0);
715 /* Note that we need to allocate MAX_PATH, since we are supposed to fill
716 * the correct executable if there is no icon in lpIconPath directly.
717 * lpIconPath itself is supposed to be large enough, so make sure lpIconPathW
718 * is large enough too. Yes, I am puking too.
720 LPWSTR lpIconPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
722 TRACE("%p %s %p\n", hInst
, debugstr_a(lpIconPath
), lpiIcon
);
726 MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, lpIconPathW
, len
);
727 hIcon
= ExtractAssociatedIconW(hInst
, lpIconPathW
, lpiIcon
);
728 WideCharToMultiByte(CP_ACP
, 0, lpIconPathW
, -1, lpIconPath
, MAX_PATH
, NULL
, NULL
);
729 HeapFree(GetProcessHeap(), 0, lpIconPathW
);
734 /*************************************************************************
735 * ExtractAssociatedIconW (SHELL32.@)
737 * Return icon for given file (either from file itself or from associated
738 * executable) and patch parameters if needed.
740 HICON WINAPI
ExtractAssociatedIconW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIcon
)
745 TRACE("%p %s %p\n", hInst
, debugstr_w(lpIconPath
), lpiIcon
);
748 lpiIcon
= &wDummyIcon
;
750 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
752 if( hIcon
< (HICON
)2 )
753 { if( hIcon
== (HICON
)1 ) /* no icons found in given file */
754 { WCHAR tempPath
[MAX_PATH
];
755 HINSTANCE uRet
= FindExecutableW(lpIconPath
,NULL
,tempPath
);
757 if( uRet
> (HINSTANCE
)32 && tempPath
[0] )
758 { lstrcpyW(lpIconPath
,tempPath
);
759 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
760 if( hIcon
> (HICON
)2 )
765 if( hIcon
== (HICON
)1 )
766 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
768 *lpiIcon
= 6; /* generic icon - found nothing */
770 if (GetModuleFileNameW(hInst
, lpIconPath
, MAX_PATH
))
771 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(*lpiIcon
));
776 /*************************************************************************
777 * ExtractAssociatedIconExW (SHELL32.@)
779 * Return icon for given file (either from file itself or from associated
780 * executable) and patch parameters if needed.
782 HICON WINAPI
ExtractAssociatedIconExW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
784 FIXME("%p %s %p %p): stub\n", hInst
, debugstr_w(lpIconPath
), lpiIconIdx
, lpiIconId
);
788 /*************************************************************************
789 * ExtractAssociatedIconExA (SHELL32.@)
791 * Return icon for given file (either from file itself or from associated
792 * executable) and patch parameters if needed.
794 HICON WINAPI
ExtractAssociatedIconExA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
797 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, NULL
, 0 );
798 LPWSTR lpwstrFile
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
800 TRACE("%p %s %p %p)\n", hInst
, lpIconPath
, lpiIconIdx
, lpiIconId
);
802 MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, lpwstrFile
, len
);
803 ret
= ExtractAssociatedIconExW(hInst
, lpwstrFile
, lpiIconIdx
, lpiIconId
);
804 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
809 /****************************************************************************
810 * SHDefExtractIconW [SHELL32.@]
812 HRESULT WINAPI
SHDefExtractIconW(LPCWSTR pszIconFile
, int iIndex
, UINT uFlags
,
813 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
817 WARN("%s %d 0x%08x %p %p %d, semi-stub\n", debugstr_w(pszIconFile
), iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
819 ret
= PrivateExtractIconsW(pszIconFile
, iIndex
, nIconSize
, nIconSize
, hIcons
, NULL
, 2, LR_DEFAULTCOLOR
);
820 /* FIXME: deal with uFlags parameter which contains GIL_ flags */
821 if (ret
== 0xFFFFFFFF)
825 *phiconLarge
= hIcons
[0];
827 DestroyIcon(hIcons
[0]);
829 *phiconSmall
= hIcons
[1];
831 DestroyIcon(hIcons
[1]);
837 /****************************************************************************
838 * SHDefExtractIconA [SHELL32.@]
840 HRESULT WINAPI
SHDefExtractIconA(LPCSTR pszIconFile
, int iIndex
, UINT uFlags
,
841 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
844 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, NULL
, 0);
845 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
847 TRACE("%s %d 0x%08x %p %p %d\n", pszIconFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
849 MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, lpwstrFile
, len
);
850 ret
= SHDefExtractIconW(lpwstrFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
851 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
856 /****************************************************************************
857 * SHGetIconOverlayIndexA [SHELL32.@]
859 * Returns the index of the overlay icon in the system image list.
861 INT WINAPI
SHGetIconOverlayIndexA(LPCSTR pszIconPath
, INT iIconIndex
)
863 FIXME("%s, %d\n", debugstr_a(pszIconPath
), iIconIndex
);
868 /****************************************************************************
869 * SHGetIconOverlayIndexW [SHELL32.@]
871 * Returns the index of the overlay icon in the system image list.
873 INT WINAPI
SHGetIconOverlayIndexW(LPCWSTR pszIconPath
, INT iIconIndex
)
875 FIXME("%s, %d\n", debugstr_w(pszIconPath
), iIconIndex
);