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
;
63 static INIT_ONCE sic_init_once
= INIT_ONCE_STATIC_INIT
;
64 static HIMAGELIST ShellSmallIconList
;
65 static HIMAGELIST ShellBigIconList
;
67 static CRITICAL_SECTION SHELL32_SicCS
;
68 static CRITICAL_SECTION_DEBUG critsect_debug
=
71 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
72 0, 0, { (DWORD_PTR
)(__FILE__
": SHELL32_SicCS") }
74 static CRITICAL_SECTION SHELL32_SicCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
76 /*****************************************************************************
80 * Callback for DPA_Search
82 static INT CALLBACK
SIC_CompareEntries( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
84 LPSIC_ENTRY e1
= p1
, e2
= p2
;
86 TRACE("%p %p %8lx\n", p1
, p2
, lparam
);
88 /* Icons in the cache are keyed by the name of the file they are
89 * loaded from, their resource index and the fact if they have a shortcut
90 * icon overlay or not.
92 if (e1
->dwSourceIndex
!= e2
->dwSourceIndex
|| /* first the faster one */
93 (e1
->dwFlags
& GIL_FORSHORTCUT
) != (e2
->dwFlags
& GIL_FORSHORTCUT
))
96 if (strcmpiW(e1
->sSourceFile
,e2
->sSourceFile
))
102 /* declare SIC_LoadOverlayIcon() */
103 static int SIC_LoadOverlayIcon(int icon_idx
);
105 /*****************************************************************************
106 * SIC_OverlayShortcutImage [internal]
109 * Creates a new icon as a copy of the passed-in icon, overlayed with a
112 static HICON
SIC_OverlayShortcutImage(HICON SourceIcon
, BOOL large
)
113 { ICONINFO SourceIconInfo
, ShortcutIconInfo
, TargetIconInfo
;
114 HICON ShortcutIcon
, TargetIcon
;
115 BITMAP SourceBitmapInfo
, ShortcutBitmapInfo
;
120 HBITMAP OldSourceBitmap
= NULL
,
121 OldShortcutBitmap
= NULL
,
122 OldTargetBitmap
= NULL
;
124 static int s_imgListIdx
= -1;
126 /* Get information about the source icon and shortcut overlay */
127 if (! GetIconInfo(SourceIcon
, &SourceIconInfo
)
128 || 0 == GetObjectW(SourceIconInfo
.hbmColor
, sizeof(BITMAP
), &SourceBitmapInfo
))
133 /* search for the shortcut icon only once */
134 if (s_imgListIdx
== -1)
135 s_imgListIdx
= SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT
);
136 /* FIXME should use icon index 29 instead of the
137 resource id, but not all icons are present yet
138 so we can't use icon indices */
140 if (s_imgListIdx
!= -1)
143 ShortcutIcon
= ImageList_GetIcon(ShellBigIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
145 ShortcutIcon
= ImageList_GetIcon(ShellSmallIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
149 if (NULL
== ShortcutIcon
150 || ! GetIconInfo(ShortcutIcon
, &ShortcutIconInfo
)
151 || 0 == GetObjectW(ShortcutIconInfo
.hbmColor
, sizeof(BITMAP
), &ShortcutBitmapInfo
))
156 TargetIconInfo
= SourceIconInfo
;
157 TargetIconInfo
.hbmMask
= NULL
;
158 TargetIconInfo
.hbmColor
= NULL
;
160 /* Setup the source, shortcut and target masks */
161 SourceDC
= CreateCompatibleDC(NULL
);
162 if (NULL
== SourceDC
) goto fail
;
163 OldSourceBitmap
= SelectObject(SourceDC
, SourceIconInfo
.hbmMask
);
164 if (NULL
== OldSourceBitmap
) goto fail
;
166 ShortcutDC
= CreateCompatibleDC(NULL
);
167 if (NULL
== ShortcutDC
) goto fail
;
168 OldShortcutBitmap
= SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmMask
);
169 if (NULL
== OldShortcutBitmap
) goto fail
;
171 TargetDC
= CreateCompatibleDC(NULL
);
172 if (NULL
== TargetDC
) goto fail
;
173 TargetIconInfo
.hbmMask
= CreateCompatibleBitmap(TargetDC
, SourceBitmapInfo
.bmWidth
,
174 SourceBitmapInfo
.bmHeight
);
175 if (NULL
== TargetIconInfo
.hbmMask
) goto fail
;
176 ScreenDC
= GetDC(NULL
);
177 if (NULL
== ScreenDC
) goto fail
;
178 TargetIconInfo
.hbmColor
= CreateCompatibleBitmap(ScreenDC
, SourceBitmapInfo
.bmWidth
,
179 SourceBitmapInfo
.bmHeight
);
180 ReleaseDC(NULL
, ScreenDC
);
181 if (NULL
== TargetIconInfo
.hbmColor
) goto fail
;
182 OldTargetBitmap
= SelectObject(TargetDC
, TargetIconInfo
.hbmMask
);
183 if (NULL
== OldTargetBitmap
) goto fail
;
185 /* Create the target mask by ANDing the source and shortcut masks */
186 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
187 SourceDC
, 0, 0, SRCCOPY
) ||
188 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
189 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
190 ShortcutDC
, 0, 0, SRCAND
))
195 /* Setup the source and target xor bitmap */
196 if (NULL
== SelectObject(SourceDC
, SourceIconInfo
.hbmColor
) ||
197 NULL
== SelectObject(TargetDC
, TargetIconInfo
.hbmColor
))
202 /* Copy the source xor bitmap to the target and clear out part of it by using
204 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
205 SourceDC
, 0, 0, SRCCOPY
) ||
206 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
207 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
208 ShortcutDC
, 0, 0, SRCAND
))
213 if (NULL
== SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmColor
)) goto fail
;
215 /* Now put in the shortcut xor mask */
216 if (! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
217 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
218 ShortcutDC
, 0, 0, SRCINVERT
))
223 /* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set
225 SelectObject(TargetDC
, OldTargetBitmap
);
226 DeleteObject(TargetDC
);
227 SelectObject(ShortcutDC
, OldShortcutBitmap
);
228 DeleteObject(ShortcutDC
);
229 SelectObject(SourceDC
, OldSourceBitmap
);
230 DeleteObject(SourceDC
);
232 /* Create the icon using the bitmaps prepared earlier */
233 TargetIcon
= CreateIconIndirect(&TargetIconInfo
);
235 /* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */
236 DeleteObject(TargetIconInfo
.hbmColor
);
237 DeleteObject(TargetIconInfo
.hbmMask
);
242 /* Clean up scratch resources we created */
243 if (NULL
!= OldTargetBitmap
) SelectObject(TargetDC
, OldTargetBitmap
);
244 if (NULL
!= TargetIconInfo
.hbmColor
) DeleteObject(TargetIconInfo
.hbmColor
);
245 if (NULL
!= TargetIconInfo
.hbmMask
) DeleteObject(TargetIconInfo
.hbmMask
);
246 if (NULL
!= TargetDC
) DeleteObject(TargetDC
);
247 if (NULL
!= OldShortcutBitmap
) SelectObject(ShortcutDC
, OldShortcutBitmap
);
248 if (NULL
!= ShortcutDC
) DeleteObject(ShortcutDC
);
249 if (NULL
!= OldSourceBitmap
) SelectObject(SourceDC
, OldSourceBitmap
);
250 if (NULL
!= SourceDC
) DeleteObject(SourceDC
);
255 /*****************************************************************************
256 * SIC_IconAppend [internal]
259 * appends an icon pair to the end of the cache
261 static INT
SIC_IconAppend (LPCWSTR sSourceFile
, INT dwSourceIndex
, HICON hSmallIcon
, HICON hBigIcon
, DWORD dwFlags
)
262 { LPSIC_ENTRY lpsice
;
263 INT ret
, index
, index1
;
264 WCHAR path
[MAX_PATH
];
265 TRACE("%s %i %p %p\n", debugstr_w(sSourceFile
), dwSourceIndex
, hSmallIcon
,hBigIcon
);
267 lpsice
= SHAlloc(sizeof(SIC_ENTRY
));
269 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
270 lpsice
->sSourceFile
= HeapAlloc( GetProcessHeap(), 0, (strlenW(path
)+1)*sizeof(WCHAR
) );
271 strcpyW( lpsice
->sSourceFile
, path
);
273 lpsice
->dwSourceIndex
= dwSourceIndex
;
274 lpsice
->dwFlags
= dwFlags
;
276 EnterCriticalSection(&SHELL32_SicCS
);
278 index
= DPA_InsertPtr(sic_hdpa
, 0x7fff, lpsice
);
279 if ( INVALID_INDEX
== index
)
281 HeapFree(GetProcessHeap(), 0, lpsice
->sSourceFile
);
287 index
= ImageList_AddIcon (ShellSmallIconList
, hSmallIcon
);
288 index1
= ImageList_AddIcon (ShellBigIconList
, hBigIcon
);
292 FIXME("iconlists out of sync 0x%x 0x%x\n", index
, index1
);
294 lpsice
->dwListIndex
= index
;
295 ret
= lpsice
->dwListIndex
;
298 LeaveCriticalSection(&SHELL32_SicCS
);
301 /****************************************************************************
302 * SIC_LoadIcon [internal]
305 * gets small/big icon by number from a file
307 static INT
SIC_LoadIcon (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
308 { HICON hiconLarge
=0;
310 HICON hiconLargeShortcut
;
311 HICON hiconSmallShortcut
;
313 PrivateExtractIconsW( sSourceFile
, dwSourceIndex
, 32, 32, &hiconLarge
, 0, 1, 0 );
314 PrivateExtractIconsW( sSourceFile
, dwSourceIndex
, 16, 16, &hiconSmall
, 0, 1, 0 );
316 if ( !hiconLarge
|| !hiconSmall
)
318 WARN("failure loading icon %i from %s (%p %p)\n", dwSourceIndex
, debugstr_w(sSourceFile
), hiconLarge
, hiconSmall
);
322 if (0 != (dwFlags
& GIL_FORSHORTCUT
))
324 hiconLargeShortcut
= SIC_OverlayShortcutImage(hiconLarge
, TRUE
);
325 hiconSmallShortcut
= SIC_OverlayShortcutImage(hiconSmall
, FALSE
);
326 if (NULL
!= hiconLargeShortcut
&& NULL
!= hiconSmallShortcut
)
328 hiconLarge
= hiconLargeShortcut
;
329 hiconSmall
= hiconSmallShortcut
;
333 WARN("Failed to create shortcut overlayed icons\n");
334 if (NULL
!= hiconLargeShortcut
) DestroyIcon(hiconLargeShortcut
);
335 if (NULL
!= hiconSmallShortcut
) DestroyIcon(hiconSmallShortcut
);
336 dwFlags
&= ~ GIL_FORSHORTCUT
;
340 return SIC_IconAppend (sSourceFile
, dwSourceIndex
, hiconSmall
, hiconLarge
, dwFlags
);
342 /*****************************************************************************
343 * SIC_Initialize [internal]
345 static BOOL WINAPI
SIC_Initialize( INIT_ONCE
*once
, void *param
, void **context
)
348 int cx_small
, cy_small
;
349 int cx_large
, cy_large
;
351 cx_small
= GetSystemMetrics(SM_CXSMICON
);
352 cy_small
= GetSystemMetrics(SM_CYSMICON
);
353 cx_large
= GetSystemMetrics(SM_CXICON
);
354 cy_large
= GetSystemMetrics(SM_CYICON
);
358 sic_hdpa
= DPA_Create(16);
365 ShellSmallIconList
= ImageList_Create(cx_small
,cy_small
,ILC_COLOR32
|ILC_MASK
,0,0x20);
366 ShellBigIconList
= ImageList_Create(cx_large
,cy_large
,ILC_COLOR32
|ILC_MASK
,0,0x20);
368 ImageList_SetBkColor(ShellSmallIconList
, CLR_NONE
);
369 ImageList_SetBkColor(ShellBigIconList
, CLR_NONE
);
371 /* Load the document icon, which is used as the default if an icon isn't found. */
372 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT
),
373 IMAGE_ICON
, cx_small
, cy_small
, LR_SHARED
);
374 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT
),
375 IMAGE_ICON
, cx_large
, cy_large
, LR_SHARED
);
379 FIXME("Failed to load IDI_SHELL_DOCUMENT icon!\n");
383 SIC_IconAppend (swShell32Name
, IDI_SHELL_DOCUMENT
-1, hSm
, hLg
, 0);
384 SIC_IconAppend (swShell32Name
, -IDI_SHELL_DOCUMENT
, hSm
, hLg
, 0);
386 TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList
, ShellBigIconList
);
390 /*************************************************************************
395 static INT CALLBACK
sic_free( LPVOID ptr
, LPVOID lparam
)
397 HeapFree(GetProcessHeap(), 0, ((LPSIC_ENTRY
)ptr
)->sSourceFile
);
402 void SIC_Destroy(void)
406 EnterCriticalSection(&SHELL32_SicCS
);
408 if (sic_hdpa
) DPA_DestroyCallback(sic_hdpa
, sic_free
, NULL
);
410 if (ShellSmallIconList
)
411 ImageList_Destroy(ShellSmallIconList
);
412 if (ShellBigIconList
)
413 ImageList_Destroy(ShellBigIconList
);
415 LeaveCriticalSection(&SHELL32_SicCS
);
416 DeleteCriticalSection(&SHELL32_SicCS
);
419 /*****************************************************************************
420 * SIC_GetIconIndex [internal]
423 * sSourceFile [IN] filename of file containing the icon
424 * index [IN] index/resID (negated) in this file
427 * look in the cache for a proper icon. if not available the icon is taken
428 * from the file and cached
430 INT
SIC_GetIconIndex (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
433 INT ret
, index
= INVALID_INDEX
;
434 WCHAR path
[MAX_PATH
];
436 TRACE("%s %i\n", debugstr_w(sSourceFile
), dwSourceIndex
);
438 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
439 sice
.sSourceFile
= path
;
440 sice
.dwSourceIndex
= dwSourceIndex
;
441 sice
.dwFlags
= dwFlags
;
443 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
445 EnterCriticalSection(&SHELL32_SicCS
);
447 if (NULL
!= DPA_GetPtr (sic_hdpa
, 0))
449 /* search linear from position 0*/
450 index
= DPA_Search (sic_hdpa
, &sice
, 0, SIC_CompareEntries
, 0, 0);
453 if ( INVALID_INDEX
== index
)
455 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
, dwFlags
);
460 ret
= ((LPSIC_ENTRY
)DPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
463 LeaveCriticalSection(&SHELL32_SicCS
);
467 /*****************************************************************************
468 * SIC_LoadOverlayIcon [internal]
470 * Load a shell overlay icon and return its icon cache index.
472 static int SIC_LoadOverlayIcon(int icon_idx
)
474 WCHAR buffer
[1024], wszIdx
[8];
479 static const WCHAR wszShellIcons
[] = {
480 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
481 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
482 'E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','I','c','o','n','s',0
484 static const WCHAR wszNumFmt
[] = {'%','d',0};
486 iconPath
= swShell32Name
; /* default: load icon from shell32.dll */
489 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszShellIcons
, 0, KEY_READ
, &hKeyShellIcons
) == ERROR_SUCCESS
)
491 DWORD count
= sizeof(buffer
);
493 sprintfW(wszIdx
, wszNumFmt
, icon_idx
);
495 /* read icon path and index */
496 if (RegQueryValueExW(hKeyShellIcons
, wszIdx
, NULL
, NULL
, (LPBYTE
)buffer
, &count
) == ERROR_SUCCESS
)
498 LPWSTR p
= strchrW(buffer
, ',');
502 ERR("Icon index in %s/%s corrupted, no comma.\n", debugstr_w(wszShellIcons
),debugstr_w(wszIdx
));
503 RegCloseKey(hKeyShellIcons
);
511 RegCloseKey(hKeyShellIcons
);
514 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
516 return SIC_LoadIcon(iconPath
, iconIdx
, 0);
519 /*************************************************************************
520 * Shell_GetImageLists [SHELL32.71]
523 * imglist[1|2] [OUT] pointer which receives imagelist handles
526 BOOL WINAPI
Shell_GetImageLists(HIMAGELIST
* lpBigList
, HIMAGELIST
* lpSmallList
)
528 TRACE("(%p,%p)\n",lpBigList
,lpSmallList
);
529 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
530 if (lpBigList
) *lpBigList
= ShellBigIconList
;
531 if (lpSmallList
) *lpSmallList
= ShellSmallIconList
;
534 /*************************************************************************
535 * PidlToSicIndex [INTERNAL]
538 * sh [IN] IShellFolder
542 * pIndex [OUT] index within the SIC
545 BOOL
PidlToSicIndex (
553 WCHAR szIconFile
[MAX_PATH
]; /* file containing the icon */
554 INT iSourceIndex
; /* index or resID(negated) in this file */
557 int iShortcutDefaultIndex
= INVALID_INDEX
;
559 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
561 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
563 if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh
, 0, 1, &pidl
, &IID_IExtractIconW
, 0, (void **)&ei
)))
565 if (SUCCEEDED(IExtractIconW_GetIconLocation(ei
, uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
567 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
, uFlags
);
570 IExtractIconW_Release(ei
);
573 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
575 if (0 == (uFlags
& GIL_FORSHORTCUT
))
581 if (INVALID_INDEX
== iShortcutDefaultIndex
)
583 iShortcutDefaultIndex
= SIC_LoadIcon(swShell32Name
, 0, GIL_FORSHORTCUT
);
585 *pIndex
= (INVALID_INDEX
!= iShortcutDefaultIndex
? iShortcutDefaultIndex
: 0);
593 /*************************************************************************
594 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
597 * sh [IN] pointer to an instance of IShellFolder
599 * pIndex [OUT][OPTIONAL] SIC index for big icon
602 int WINAPI
SHMapPIDLToSystemImageListIndex(
610 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
613 if (SHELL_IsShortcut(pidl
))
614 uGilFlags
|= GIL_FORSHORTCUT
;
617 if (!PidlToSicIndex ( sh
, pidl
, 1, uGilFlags
, pIndex
))
620 if (!PidlToSicIndex ( sh
, pidl
, 0, uGilFlags
, &Index
))
626 /*************************************************************************
627 * SHMapIDListToImageListIndexAsync [SHELL32.148]
629 HRESULT WINAPI
SHMapIDListToImageListIndexAsync(IUnknown
*pts
, IShellFolder
*psf
,
630 LPCITEMIDLIST pidl
, UINT flags
,
631 void *pfn
, void *pvData
, void *pvHint
,
632 int *piIndex
, int *piIndexSel
)
634 FIXME("(%p, %p, %p, 0x%08x, %p, %p, %p, %p, %p)\n",
635 pts
, psf
, pidl
, flags
, pfn
, pvData
, pvHint
, piIndex
, piIndexSel
);
639 /*************************************************************************
640 * Shell_GetCachedImageIndex [SHELL32.72]
643 static INT
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
648 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
650 len
= MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, NULL
, 0 );
651 szTemp
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
652 MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, szTemp
, len
);
654 ret
= SIC_GetIconIndex( szTemp
, nIndex
, 0 );
656 HeapFree( GetProcessHeap(), 0, szTemp
);
661 static INT
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
663 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
665 return SIC_GetIconIndex(szPath
, nIndex
, 0);
668 INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
669 { if( SHELL_OsIsUnicode())
670 return Shell_GetCachedImageIndexW(szPath
, nIndex
, bSimulateDoc
);
671 return Shell_GetCachedImageIndexA(szPath
, nIndex
, bSimulateDoc
);
674 /*************************************************************************
675 * ExtractIconExW [SHELL32.@]
678 * -1 file is not valid
679 * or number of icons extracted
681 UINT WINAPI
ExtractIconExW(LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
683 TRACE("%s %i %p %p %i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
685 return PrivateExtractIconExW(lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
688 /*************************************************************************
689 * ExtractIconExA [SHELL32.@]
691 UINT WINAPI
ExtractIconExA(LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
694 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
695 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
697 TRACE("%s %i %p %p %i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
701 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
702 ret
= ExtractIconExW(lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
703 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
708 /*************************************************************************
709 * ExtractAssociatedIconA (SHELL32.@)
711 * Return icon for given file (either from file itself or from associated
712 * executable) and patch parameters if needed.
714 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
717 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, NULL
, 0);
718 /* Note that we need to allocate MAX_PATH, since we are supposed to fill
719 * the correct executable if there is no icon in lpIconPath directly.
720 * lpIconPath itself is supposed to be large enough, so make sure lpIconPathW
721 * is large enough too. Yes, I am puking too.
723 LPWSTR lpIconPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
725 TRACE("%p %s %p\n", hInst
, debugstr_a(lpIconPath
), lpiIcon
);
729 MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, lpIconPathW
, len
);
730 hIcon
= ExtractAssociatedIconW(hInst
, lpIconPathW
, lpiIcon
);
731 WideCharToMultiByte(CP_ACP
, 0, lpIconPathW
, -1, lpIconPath
, MAX_PATH
, NULL
, NULL
);
732 HeapFree(GetProcessHeap(), 0, lpIconPathW
);
737 /*************************************************************************
738 * ExtractAssociatedIconW (SHELL32.@)
740 * Return icon for given file (either from file itself or from associated
741 * executable) and patch parameters if needed.
743 HICON WINAPI
ExtractAssociatedIconW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIcon
)
748 TRACE("%p %s %p\n", hInst
, debugstr_w(lpIconPath
), lpiIcon
);
751 lpiIcon
= &wDummyIcon
;
753 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
755 if( hIcon
< (HICON
)2 )
756 { if( hIcon
== (HICON
)1 ) /* no icons found in given file */
757 { WCHAR tempPath
[MAX_PATH
];
758 HINSTANCE uRet
= FindExecutableW(lpIconPath
,NULL
,tempPath
);
760 if( uRet
> (HINSTANCE
)32 && tempPath
[0] )
761 { lstrcpyW(lpIconPath
,tempPath
);
762 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
763 if( hIcon
> (HICON
)2 )
768 if( hIcon
== (HICON
)1 )
769 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
771 *lpiIcon
= 6; /* generic icon - found nothing */
773 if (GetModuleFileNameW(hInst
, lpIconPath
, MAX_PATH
))
774 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(*lpiIcon
));
779 /*************************************************************************
780 * ExtractAssociatedIconExW (SHELL32.@)
782 * Return icon for given file (either from file itself or from associated
783 * executable) and patch parameters if needed.
785 HICON WINAPI
ExtractAssociatedIconExW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
787 FIXME("%p %s %p %p): stub\n", hInst
, debugstr_w(lpIconPath
), lpiIconIdx
, lpiIconId
);
791 /*************************************************************************
792 * ExtractAssociatedIconExA (SHELL32.@)
794 * Return icon for given file (either from file itself or from associated
795 * executable) and patch parameters if needed.
797 HICON WINAPI
ExtractAssociatedIconExA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
800 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, NULL
, 0 );
801 LPWSTR lpwstrFile
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
803 TRACE("%p %s %p %p)\n", hInst
, lpIconPath
, lpiIconIdx
, lpiIconId
);
805 MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, lpwstrFile
, len
);
806 ret
= ExtractAssociatedIconExW(hInst
, lpwstrFile
, lpiIconIdx
, lpiIconId
);
807 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
812 /****************************************************************************
813 * SHDefExtractIconW [SHELL32.@]
815 HRESULT WINAPI
SHDefExtractIconW(LPCWSTR pszIconFile
, int iIndex
, UINT uFlags
,
816 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
820 WARN("%s %d 0x%08x %p %p %d, semi-stub\n", debugstr_w(pszIconFile
), iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
822 ret
= PrivateExtractIconsW(pszIconFile
, iIndex
, nIconSize
, nIconSize
, hIcons
, NULL
, 2, LR_DEFAULTCOLOR
);
823 /* FIXME: deal with uFlags parameter which contains GIL_ flags */
824 if (ret
== 0xFFFFFFFF)
828 *phiconLarge
= hIcons
[0];
830 DestroyIcon(hIcons
[0]);
832 *phiconSmall
= hIcons
[1];
834 DestroyIcon(hIcons
[1]);
840 /****************************************************************************
841 * SHDefExtractIconA [SHELL32.@]
843 HRESULT WINAPI
SHDefExtractIconA(LPCSTR pszIconFile
, int iIndex
, UINT uFlags
,
844 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
847 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, NULL
, 0);
848 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
850 TRACE("%s %d 0x%08x %p %p %d\n", pszIconFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
852 MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, lpwstrFile
, len
);
853 ret
= SHDefExtractIconW(lpwstrFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
854 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
859 /****************************************************************************
860 * SHGetIconOverlayIndexA [SHELL32.@]
862 * Returns the index of the overlay icon in the system image list.
864 INT WINAPI
SHGetIconOverlayIndexA(LPCSTR pszIconPath
, INT iIconIndex
)
866 FIXME("%s, %d\n", debugstr_a(pszIconPath
), iIconIndex
);
871 /****************************************************************************
872 * SHGetIconOverlayIndexW [SHELL32.@]
874 * Returns the index of the overlay icon in the system image list.
876 INT WINAPI
SHGetIconOverlayIndexW(LPCWSTR pszIconPath
, INT iIconIndex
)
878 FIXME("%s, %d\n", debugstr_w(pszIconPath
), iIconIndex
);
883 /****************************************************************************
884 * SHGetStockIconInfo [SHELL32.@]
886 * Receive information for builtin icons
889 * id [I] selected icon-id to get information for
890 * flags [I] selects the information to receive
891 * sii [IO] SHSTOCKICONINFO structure to fill
895 * Failure: A HRESULT failure code
898 HRESULT WINAPI
SHGetStockIconInfo(SHSTOCKICONID id
, UINT flags
, SHSTOCKICONINFO
*sii
)
900 static const WCHAR shell32dll
[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
902 FIXME("(%d, 0x%x, %p) semi-stub\n", id
, flags
, sii
);
903 if ((id
< 0) || (id
>= SIID_MAX_ICONS
) || !sii
|| (sii
->cbSize
!= sizeof(SHSTOCKICONINFO
))) {
907 GetSystemDirectoryW(sii
->szPath
, MAX_PATH
);
909 /* no icons defined: use default */
910 sii
->iIcon
= -IDI_SHELL_DOCUMENT
;
911 lstrcatW(sii
->szPath
, shell32dll
);
914 FIXME("flags 0x%x not implemented\n", flags
);
917 sii
->iSysImageIndex
= -1;
919 TRACE("%3d: returning %s (%d)\n", id
, debugstr_w(sii
->szPath
), sii
->iIcon
);