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
23 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
25 /********************** THE ICON CACHE ********************************/
27 #define INVALID_INDEX -1
31 LPWSTR sSourceFile
; /* file (not path!) containing the icon */
32 DWORD dwSourceIndex
; /* index within the file, if it is a resoure ID it will be negated */
33 DWORD dwListIndex
; /* index within the iconlist */
34 DWORD dwFlags
; /* GIL_* flags */
36 } SIC_ENTRY
, * LPSIC_ENTRY
;
38 static HDPA sic_hdpa
= 0;
42 extern CRITICAL_SECTION SHELL32_SicCS
;
43 CRITICAL_SECTION_DEBUG critsect_debug
=
46 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
47 0, 0, { (DWORD_PTR
)(__FILE__
": SHELL32_SicCS") }
49 CRITICAL_SECTION SHELL32_SicCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
52 /*****************************************************************************
56 * Callback for DPA_Search
58 static INT CALLBACK
SIC_CompareEntries( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
59 { LPSIC_ENTRY e1
= (LPSIC_ENTRY
)p1
, e2
= (LPSIC_ENTRY
)p2
;
61 TRACE("%p %p %8lx\n", p1
, p2
, lparam
);
63 /* Icons in the cache are keyed by the name of the file they are
64 * loaded from, their resource index and the fact if they have a shortcut
65 * icon overlay or not.
67 if (e1
->dwSourceIndex
!= e2
->dwSourceIndex
|| /* first the faster one */
68 (e1
->dwFlags
& GIL_FORSHORTCUT
) != (e2
->dwFlags
& GIL_FORSHORTCUT
))
71 if (wcsicmp(e1
->sSourceFile
,e2
->sSourceFile
))
77 /* declare SIC_LoadOverlayIcon() */
78 static int SIC_LoadOverlayIcon(int icon_idx
);
80 /*****************************************************************************
81 * SIC_OverlayShortcutImage [internal]
84 * Creates a new icon as a copy of the passed-in icon, overlayed with a
86 * FIXME: This should go to the ImageList implementation!
88 static HICON
SIC_OverlayShortcutImage(HICON SourceIcon
, BOOL large
)
90 ICONINFO ShortcutIconInfo
, TargetIconInfo
;
91 HICON ShortcutIcon
= NULL
, TargetIcon
;
92 BITMAP TargetBitmapInfo
, ShortcutBitmapInfo
;
93 HDC ShortcutDC
= NULL
,
95 HBITMAP OldShortcutBitmap
= NULL
,
96 OldTargetBitmap
= NULL
;
98 static int s_imgListIdx
= -1;
99 ZeroMemory(&ShortcutIconInfo
, sizeof(ShortcutIconInfo
));
100 ZeroMemory(&TargetIconInfo
, sizeof(TargetIconInfo
));
102 /* Get information about the source icon and shortcut overlay.
103 * We will write over the source bitmaps to get the final ones */
104 if (! GetIconInfo(SourceIcon
, &TargetIconInfo
))
107 /* Is it possible with the ImageList implementation? */
108 if(!TargetIconInfo
.hbmColor
)
110 /* Maybe we'll support this at some point */
111 FIXME("1bpp icon wants its overlay!\n");
115 if(!GetObjectW(TargetIconInfo
.hbmColor
, sizeof(BITMAP
), &TargetBitmapInfo
))
120 /* search for the shortcut icon only once */
121 if (s_imgListIdx
== -1)
122 s_imgListIdx
= SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT
);
123 /* FIXME should use icon index 29 instead of the
124 resource id, but not all icons are present yet
125 so we can't use icon indices */
127 if (s_imgListIdx
!= -1)
130 ShortcutIcon
= ImageList_GetIcon(ShellBigIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
132 ShortcutIcon
= ImageList_GetIcon(ShellSmallIconList
, s_imgListIdx
, ILD_TRANSPARENT
);
136 if (!ShortcutIcon
|| !GetIconInfo(ShortcutIcon
, &ShortcutIconInfo
))
141 /* Is it possible with the ImageLists ? */
142 if(!ShortcutIconInfo
.hbmColor
)
144 /* Maybe we'll support this at some point */
145 FIXME("Should draw 1bpp overlay!\n");
149 if(!GetObjectW(ShortcutIconInfo
.hbmColor
, sizeof(BITMAP
), &ShortcutBitmapInfo
))
154 /* Setup the masks */
155 ShortcutDC
= CreateCompatibleDC(NULL
);
156 if (NULL
== ShortcutDC
) goto fail
;
157 OldShortcutBitmap
= (HBITMAP
)SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmMask
);
158 if (NULL
== OldShortcutBitmap
) goto fail
;
160 TargetDC
= CreateCompatibleDC(NULL
);
161 if (NULL
== TargetDC
) goto fail
;
162 OldTargetBitmap
= (HBITMAP
)SelectObject(TargetDC
, TargetIconInfo
.hbmMask
);
163 if (NULL
== OldTargetBitmap
) goto fail
;
165 /* Create the complete mask by ANDing the source and shortcut masks.
166 * NOTE: in an ImageList, all icons have the same dimensions */
167 if (!BitBlt(TargetDC
, 0, 0, ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
168 ShortcutDC
, 0, 0, SRCAND
))
174 * We must remove or add the alpha component to the shortcut overlay:
175 * If we don't, SRCCOPY will copy it to our resulting icon, resulting in a
176 * partially transparent icons where it shouldn't be, and to an invisible icon
177 * if the underlying icon don't have any alpha channel information. (16bpp only icon for instance).
178 * But if the underlying icon has alpha channel information, then we must mark the overlay information
180 * NOTE: This code sucks(tm) and should belong to the ImageList implementation.
181 * NOTE2: there are better ways to do this.
183 if(ShortcutBitmapInfo
.bmBitsPixel
== 32)
186 BYTE buffer
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
187 BITMAPINFO
* lpbmi
= (BITMAPINFO
*)buffer
;
192 /* Find if the source bitmap has an alpha channel */
193 if(TargetBitmapInfo
.bmBitsPixel
!= 32) add_alpha
= FALSE
;
196 ZeroMemory(buffer
, sizeof(buffer
));
197 lpbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
198 lpbmi
->bmiHeader
.biWidth
= TargetBitmapInfo
.bmWidth
;
199 lpbmi
->bmiHeader
.biHeight
= TargetBitmapInfo
.bmHeight
;
200 lpbmi
->bmiHeader
.biPlanes
= 1;
201 lpbmi
->bmiHeader
.biBitCount
= 32;
203 bits
= HeapAlloc(GetProcessHeap(), 0, TargetBitmapInfo
.bmHeight
* TargetBitmapInfo
.bmWidthBytes
);
207 if(!GetDIBits(TargetDC
, TargetIconInfo
.hbmColor
, 0, TargetBitmapInfo
.bmHeight
, bits
, lpbmi
, DIB_RGB_COLORS
))
209 ERR("GetBIBits failed!\n");
210 HeapFree(GetProcessHeap(), 0, bits
);
215 pixel
= (PULONG
)bits
;
217 for(i
=0; i
<TargetBitmapInfo
.bmHeight
; i
++)
219 for(j
=0; j
<TargetBitmapInfo
.bmWidth
; j
++)
221 add_alpha
= (*pixel
++ & 0xFF000000) != 0;
226 HeapFree(GetProcessHeap(), 0, bits
);
229 /* Allocate the bits */
230 bits
= HeapAlloc(GetProcessHeap(), 0, ShortcutBitmapInfo
.bmHeight
*ShortcutBitmapInfo
.bmWidthBytes
);
233 ZeroMemory(buffer
, sizeof(buffer
));
234 lpbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
235 lpbmi
->bmiHeader
.biWidth
= ShortcutBitmapInfo
.bmWidth
;
236 lpbmi
->bmiHeader
.biHeight
= ShortcutBitmapInfo
.bmHeight
;
237 lpbmi
->bmiHeader
.biPlanes
= 1;
238 lpbmi
->bmiHeader
.biBitCount
= 32;
240 if(!GetDIBits(TargetDC
, ShortcutIconInfo
.hbmColor
, 0, ShortcutBitmapInfo
.bmHeight
, bits
, lpbmi
, DIB_RGB_COLORS
))
242 ERR("GetBIBits failed!\n");
243 HeapFree(GetProcessHeap(), 0, bits
);
247 pixel
= (PULONG
)bits
;
248 /* Remove alpha channel component or make it totally opaque */
249 for(i
=0; i
<ShortcutBitmapInfo
.bmHeight
; i
++)
251 for(j
=0; j
<ShortcutBitmapInfo
.bmWidth
; j
++)
253 if(add_alpha
) *pixel
++ |= 0xFF000000;
254 else *pixel
++ &= 0x00FFFFFF;
258 /* GetDIBits return BI_BITFIELDS with masks set to 0, and SetDIBits fails when masks are 0. The irony... */
259 lpbmi
->bmiHeader
.biCompression
= BI_RGB
;
261 /* Set the bits again */
262 if(!SetDIBits(TargetDC
, ShortcutIconInfo
.hbmColor
, 0, ShortcutBitmapInfo
.bmHeight
, bits
, lpbmi
, DIB_RGB_COLORS
))
264 ERR("SetBIBits failed!, %lu\n", GetLastError());
265 HeapFree(GetProcessHeap(), 0, bits
);
268 HeapFree(GetProcessHeap(), 0, bits
);
271 /* Now do the copy. We overwrite the original icon data */
272 if (NULL
== SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmColor
) ||
273 NULL
== SelectObject(TargetDC
, TargetIconInfo
.hbmColor
))
275 if (!MaskBlt(TargetDC
, 0, 0, ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
276 ShortcutDC
, 0, 0, ShortcutIconInfo
.hbmMask
, 0, 0,
277 MAKEROP4(0xAA0000, SRCCOPY
)))
282 /* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set
284 SelectObject(TargetDC
, OldTargetBitmap
);
286 SelectObject(ShortcutDC
, OldShortcutBitmap
);
287 DeleteDC(ShortcutDC
);
289 /* Create the icon using the bitmaps prepared earlier */
290 TargetIcon
= CreateIconIndirect(&TargetIconInfo
);
292 /* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */
293 DeleteObject(TargetIconInfo
.hbmColor
);
294 DeleteObject(TargetIconInfo
.hbmMask
);
295 /* Delete what GetIconInfo gave us */
296 DeleteObject(ShortcutIconInfo
.hbmColor
);
297 DeleteObject(ShortcutIconInfo
.hbmMask
);
298 DestroyIcon(ShortcutIcon
);
303 /* Clean up scratch resources we created */
304 if (NULL
!= OldTargetBitmap
) SelectObject(TargetDC
, OldTargetBitmap
);
305 if (NULL
!= TargetDC
) DeleteDC(TargetDC
);
306 if (NULL
!= OldShortcutBitmap
) SelectObject(ShortcutDC
, OldShortcutBitmap
);
307 if (NULL
!= ShortcutDC
) DeleteDC(ShortcutDC
);
308 if (NULL
!= TargetIconInfo
.hbmColor
) DeleteObject(TargetIconInfo
.hbmColor
);
309 if (NULL
!= TargetIconInfo
.hbmMask
) DeleteObject(TargetIconInfo
.hbmMask
);
310 if (NULL
!= ShortcutIconInfo
.hbmColor
) DeleteObject(ShortcutIconInfo
.hbmColor
);
311 if (NULL
!= ShortcutIconInfo
.hbmMask
) DeleteObject(ShortcutIconInfo
.hbmColor
);
312 if (NULL
!= ShortcutIcon
) DestroyIcon(ShortcutIcon
);
317 /*****************************************************************************
318 * SIC_IconAppend [internal]
321 * appends an icon pair to the end of the cache
323 static INT
SIC_IconAppend (LPCWSTR sSourceFile
, INT dwSourceIndex
, HICON hSmallIcon
, HICON hBigIcon
, DWORD dwFlags
)
326 INT ret
, index
, index1
, indexDPA
;
327 WCHAR path
[MAX_PATH
];
328 TRACE("%s %i %p %p\n", debugstr_w(sSourceFile
), dwSourceIndex
, hSmallIcon
,hBigIcon
);
330 lpsice
= (LPSIC_ENTRY
) SHAlloc (sizeof (SIC_ENTRY
));
332 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
333 lpsice
->sSourceFile
= (LPWSTR
)HeapAlloc( GetProcessHeap(), 0, (wcslen(path
)+1)*sizeof(WCHAR
) );
334 wcscpy( lpsice
->sSourceFile
, path
);
336 lpsice
->dwSourceIndex
= dwSourceIndex
;
337 lpsice
->dwFlags
= dwFlags
;
339 EnterCriticalSection(&SHELL32_SicCS
);
341 indexDPA
= DPA_InsertPtr(sic_hdpa
, 0x7fff, lpsice
);
342 if ( -1 == indexDPA
)
348 index
= ImageList_AddIcon (ShellSmallIconList
, hSmallIcon
);
349 index1
= ImageList_AddIcon (ShellBigIconList
, hBigIcon
);
351 /* Something went wrong when allocating a new image in the list. Abort. */
352 if((index
== -1) || (index1
== -1))
354 WARN("Something went wrong when adding the icon to the list: small - 0x%x, big - 0x%x.\n",
356 if(index
!= -1) ImageList_Remove(ShellSmallIconList
, index
);
357 if(index1
!= -1) ImageList_Remove(ShellBigIconList
, index1
);
364 FIXME("iconlists out of sync 0x%x 0x%x\n", index
, index1
);
365 /* What to do ???? */
367 lpsice
->dwListIndex
= index
;
368 ret
= lpsice
->dwListIndex
;
371 if(ret
== INVALID_INDEX
)
373 if(indexDPA
!= -1) DPA_DeletePtr(sic_hdpa
, indexDPA
);
374 HeapFree(GetProcessHeap(), 0, lpsice
->sSourceFile
);
377 LeaveCriticalSection(&SHELL32_SicCS
);
380 /****************************************************************************
381 * SIC_LoadIcon [internal]
384 * gets small/big icon by number from a file
386 static INT
SIC_LoadIcon (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
391 static UINT (WINAPI
*PrivateExtractIconExW
)(LPCWSTR
,int,HICON
*,HICON
*,UINT
) = NULL
;
393 if (!PrivateExtractIconExW
)
395 HMODULE hUser32
= GetModuleHandleA("user32");
396 PrivateExtractIconExW
= (UINT(WINAPI
*)(LPCWSTR
,int,HICON
*,HICON
*,UINT
)) GetProcAddress(hUser32
, "PrivateExtractIconExW");
399 if (PrivateExtractIconExW
)
401 PrivateExtractIconExW(sSourceFile
, dwSourceIndex
, &hiconLarge
, &hiconSmall
, 1);
405 PrivateExtractIconsW(sSourceFile
, dwSourceIndex
, 32, 32, &hiconLarge
, NULL
, 1, 0);
406 PrivateExtractIconsW(sSourceFile
, dwSourceIndex
, 16, 16, &hiconSmall
, NULL
, 1, 0);
409 if ( !hiconLarge
|| !hiconSmall
)
411 WARN("failure loading icon %i from %s (%p %p)\n", dwSourceIndex
, debugstr_w(sSourceFile
), hiconLarge
, hiconSmall
);
412 if(hiconLarge
) DestroyIcon(hiconLarge
);
413 if(hiconSmall
) DestroyIcon(hiconSmall
);
414 return INVALID_INDEX
;
417 if (0 != (dwFlags
& GIL_FORSHORTCUT
))
419 HICON hiconLargeShortcut
= SIC_OverlayShortcutImage(hiconLarge
, TRUE
);
420 HICON hiconSmallShortcut
= SIC_OverlayShortcutImage(hiconSmall
, FALSE
);
421 if (NULL
!= hiconLargeShortcut
&& NULL
!= hiconSmallShortcut
)
423 DestroyIcon(hiconLarge
);
424 DestroyIcon(hiconSmall
);
425 hiconLarge
= hiconLargeShortcut
;
426 hiconSmall
= hiconSmallShortcut
;
430 WARN("Failed to create shortcut overlayed icons\n");
431 if (NULL
!= hiconLargeShortcut
) DestroyIcon(hiconLargeShortcut
);
432 if (NULL
!= hiconSmallShortcut
) DestroyIcon(hiconSmallShortcut
);
433 dwFlags
&= ~ GIL_FORSHORTCUT
;
437 ret
= SIC_IconAppend (sSourceFile
, dwSourceIndex
, hiconSmall
, hiconLarge
, dwFlags
);
438 DestroyIcon(hiconLarge
);
439 DestroyIcon(hiconSmall
);
442 /*****************************************************************************
443 * SIC_GetIconIndex [internal]
446 * sSourceFile [IN] filename of file containing the icon
447 * index [IN] index/resID (negated) in this file
450 * look in the cache for a proper icon. if not available the icon is taken
451 * from the file and cached
453 INT
SIC_GetIconIndex (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
456 INT ret
, index
= INVALID_INDEX
;
457 WCHAR path
[MAX_PATH
];
459 TRACE("%s %i\n", debugstr_w(sSourceFile
), dwSourceIndex
);
461 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
462 sice
.sSourceFile
= path
;
463 sice
.dwSourceIndex
= dwSourceIndex
;
464 sice
.dwFlags
= dwFlags
;
466 EnterCriticalSection(&SHELL32_SicCS
);
468 if (NULL
!= DPA_GetPtr (sic_hdpa
, 0))
470 /* search linear from position 0*/
471 index
= DPA_Search (sic_hdpa
, &sice
, 0, SIC_CompareEntries
, 0, 0);
474 if ( INVALID_INDEX
== index
)
476 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
, dwFlags
);
481 ret
= ((LPSIC_ENTRY
)DPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
484 LeaveCriticalSection(&SHELL32_SicCS
);
488 /*****************************************************************************
489 * SIC_Initialize [internal]
491 BOOL
SIC_Initialize(void)
493 HICON hSm
= NULL
, hLg
= NULL
;
494 INT cx_small
, cy_small
;
495 INT cx_large
, cy_large
;
501 TRACE("Entered SIC_Initialize\n");
505 TRACE("Icon cache already initialized\n");
509 sic_hdpa
= DPA_Create(16);
515 hDC
= CreateICW(L
"DISPLAY", NULL
, NULL
, NULL
);
518 ERR("Failed to create information context (error %d)\n", GetLastError());
522 bpp
= GetDeviceCaps(hDC
, BITSPIXEL
);
530 ilMask
= ILC_COLOR16
;
532 ilMask
= ILC_COLOR24
;
534 ilMask
= ILC_COLOR32
;
540 cx_small
= GetSystemMetrics(SM_CXSMICON
);
541 cy_small
= GetSystemMetrics(SM_CYSMICON
);
542 cx_large
= GetSystemMetrics(SM_CXICON
);
543 cy_large
= GetSystemMetrics(SM_CYICON
);
545 ShellSmallIconList
= ImageList_Create(cx_small
,
550 if (!ShellSmallIconList
)
552 ERR("Failed to create the small icon list.\n");
556 ShellBigIconList
= ImageList_Create(cx_large
,
561 if (!ShellBigIconList
)
563 ERR("Failed to create the big icon list.\n");
567 /* Load the document icon, which is used as the default if an icon isn't found. */
568 hSm
= (HICON
)LoadImageW(shell32_hInstance
,
569 MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT
),
573 LR_SHARED
| LR_DEFAULTCOLOR
);
576 ERR("Failed to load small IDI_SHELL_DOCUMENT icon!\n");
580 hLg
= (HICON
)LoadImageW(shell32_hInstance
,
581 MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT
),
585 LR_SHARED
| LR_DEFAULTCOLOR
);
588 ERR("Failed to load large IDI_SHELL_DOCUMENT icon!\n");
592 if(SIC_IconAppend(swShell32Name
, IDI_SHELL_DOCUMENT
-1, hSm
, hLg
, 0) == INVALID_INDEX
)
594 ERR("Failed to add IDI_SHELL_DOCUMENT icon to cache.\n");
597 if(SIC_IconAppend(swShell32Name
, -IDI_SHELL_DOCUMENT
, hSm
, hLg
, 0) == INVALID_INDEX
)
599 ERR("Failed to add IDI_SHELL_DOCUMENT icon to cache.\n");
603 /* Everything went fine */
607 /* The image list keeps a copy of the icons, we must destroy them */
608 if(hSm
) DestroyIcon(hSm
);
609 if(hLg
) DestroyIcon(hLg
);
611 /* Clean everything if something went wrong */
614 if(sic_hdpa
) DPA_Destroy(sic_hdpa
);
615 if(ShellSmallIconList
) ImageList_Destroy(ShellSmallIconList
);
616 if(ShellBigIconList
) ImageList_Destroy(ShellSmallIconList
);
618 ShellSmallIconList
= NULL
;
619 ShellBigIconList
= NULL
;
622 TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList
, ShellBigIconList
);
627 /*************************************************************************
632 static INT CALLBACK
sic_free( LPVOID ptr
, LPVOID lparam
)
634 HeapFree(GetProcessHeap(), 0, ((LPSIC_ENTRY
)ptr
)->sSourceFile
);
639 void SIC_Destroy(void)
643 EnterCriticalSection(&SHELL32_SicCS
);
645 if (sic_hdpa
) DPA_DestroyCallback(sic_hdpa
, sic_free
, NULL
);
648 ImageList_Destroy(ShellSmallIconList
);
649 ShellSmallIconList
= 0;
650 ImageList_Destroy(ShellBigIconList
);
651 ShellBigIconList
= 0;
653 LeaveCriticalSection(&SHELL32_SicCS
);
654 //DeleteCriticalSection(&SHELL32_SicCS); //static
657 /*****************************************************************************
658 * SIC_LoadOverlayIcon [internal]
660 * Load a shell overlay icon and return its icon cache index.
662 static int SIC_LoadOverlayIcon(int icon_idx
)
664 WCHAR buffer
[1024], wszIdx
[8];
669 static const WCHAR wszShellIcons
[] = {
670 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
671 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
672 'E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','I','c','o','n','s',0
674 static const WCHAR wszNumFmt
[] = {'%','d',0};
676 iconPath
= swShell32Name
; /* default: load icon from shell32.dll */
679 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszShellIcons
, 0, KEY_READ
, &hKeyShellIcons
) == ERROR_SUCCESS
)
681 DWORD count
= sizeof(buffer
);
683 swprintf(wszIdx
, wszNumFmt
, icon_idx
);
685 /* read icon path and index */
686 if (RegQueryValueExW(hKeyShellIcons
, wszIdx
, NULL
, NULL
, (LPBYTE
)buffer
, &count
) == ERROR_SUCCESS
)
688 LPWSTR p
= wcschr(buffer
, ',');
697 RegCloseKey(hKeyShellIcons
);
700 return SIC_LoadIcon(iconPath
, iconIdx
, 0);
703 /*************************************************************************
704 * Shell_GetImageLists [SHELL32.71]
707 * imglist[1|2] [OUT] pointer which receives imagelist handles
710 BOOL WINAPI
Shell_GetImageLists(HIMAGELIST
* lpBigList
, HIMAGELIST
* lpSmallList
)
711 { TRACE("(%p,%p)\n",lpBigList
,lpSmallList
);
713 { *lpBigList
= ShellBigIconList
;
716 { *lpSmallList
= ShellSmallIconList
;
721 /*************************************************************************
722 * PidlToSicIndex [INTERNAL]
725 * sh [IN] IShellFolder
729 * pIndex [OUT] index within the SIC
732 BOOL
PidlToSicIndex (
739 CComPtr
<IExtractIconW
> ei
;
740 WCHAR szIconFile
[MAX_PATH
]; /* file containing the icon */
741 INT iSourceIndex
; /* index or resID(negated) in this file */
744 int iShortcutDefaultIndex
= INVALID_INDEX
;
746 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
748 if (SUCCEEDED (sh
->GetUIObjectOf(0, 1, &pidl
, IID_NULL_PPV_ARG(IExtractIconW
, &ei
))))
750 if (SUCCEEDED(ei
->GetIconLocation(uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
752 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
, uFlags
);
757 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
759 if (0 == (uFlags
& GIL_FORSHORTCUT
))
765 if (INVALID_INDEX
== iShortcutDefaultIndex
)
767 iShortcutDefaultIndex
= SIC_LoadIcon(swShell32Name
, 0, GIL_FORSHORTCUT
);
769 *pIndex
= (INVALID_INDEX
!= iShortcutDefaultIndex
? iShortcutDefaultIndex
: 0);
777 /*************************************************************************
778 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
781 * sh [IN] pointer to an instance of IShellFolder
783 * pIndex [OUT][OPTIONAL] SIC index for big icon
786 int WINAPI
SHMapPIDLToSystemImageListIndex(
794 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
797 if (SHELL_IsShortcut(pidl
))
798 uGilFlags
|= GIL_FORSHORTCUT
;
801 if (!PidlToSicIndex ( sh
, pidl
, 1, uGilFlags
, pIndex
))
804 if (!PidlToSicIndex ( sh
, pidl
, 0, uGilFlags
, &Index
))
810 /*************************************************************************
811 * SHMapIDListToImageListIndexAsync [SHELL32.148]
813 EXTERN_C HRESULT WINAPI
SHMapIDListToImageListIndexAsync(IShellTaskScheduler
*pts
, IShellFolder
*psf
,
814 LPCITEMIDLIST pidl
, UINT flags
,
815 PFNASYNCICONTASKBALLBACK pfn
, void *pvData
, void *pvHint
,
816 int *piIndex
, int *piIndexSel
)
818 FIXME("(%p, %p, %p, 0x%08x, %p, %p, %p, %p, %p)\n",
819 pts
, psf
, pidl
, flags
, pfn
, pvData
, pvHint
, piIndex
, piIndexSel
);
823 /*************************************************************************
824 * Shell_GetCachedImageIndex [SHELL32.72]
827 INT WINAPI
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, UINT bSimulateDoc
)
832 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
834 len
= MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, NULL
, 0 );
835 szTemp
= (LPWSTR
)HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
836 MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, szTemp
, len
);
838 ret
= SIC_GetIconIndex( szTemp
, nIndex
, 0 );
840 HeapFree( GetProcessHeap(), 0, szTemp
);
845 INT WINAPI
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, UINT bSimulateDoc
)
847 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
849 return SIC_GetIconIndex(szPath
, nIndex
, 0);
852 EXTERN_C INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
853 { if( SHELL_OsIsUnicode())
854 return Shell_GetCachedImageIndexW((LPCWSTR
)szPath
, nIndex
, bSimulateDoc
);
855 return Shell_GetCachedImageIndexA((LPCSTR
)szPath
, nIndex
, bSimulateDoc
);
858 /*************************************************************************
859 * ExtractIconExW [SHELL32.@]
862 * -1 file is not valid
863 * or number of icons extracted
865 UINT WINAPI
ExtractIconExW(LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
867 /* get entry point of undocumented function PrivateExtractIconExW() in user32 */
868 #if defined(__CYGWIN__) || defined (__MINGW32__) || defined(_MSC_VER)
869 static UINT (WINAPI
*PrivateExtractIconExW
)(LPCWSTR
,int,HICON
*,HICON
*,UINT
) = NULL
;
871 if (!PrivateExtractIconExW
) {
872 HMODULE hUser32
= GetModuleHandleA("user32");
873 PrivateExtractIconExW
= (UINT(WINAPI
*)(LPCWSTR
,int,HICON
*,HICON
*,UINT
)) GetProcAddress(hUser32
, "PrivateExtractIconExW");
875 if (!PrivateExtractIconExW
)
880 TRACE("%s %i %p %p %i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
882 return PrivateExtractIconExW(lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
885 /*************************************************************************
886 * ExtractIconExA [SHELL32.@]
888 UINT WINAPI
ExtractIconExA(LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
891 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
892 LPWSTR lpwstrFile
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
894 TRACE("%s %i %p %p %i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
898 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
899 ret
= ExtractIconExW(lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
900 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
905 /*************************************************************************
906 * ExtractAssociatedIconA (SHELL32.@)
908 * Return icon for given file (either from file itself or from associated
909 * executable) and patch parameters if needed.
911 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
914 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, NULL
, 0);
915 /* Note that we need to allocate MAX_PATH, since we are supposed to fill
916 * the correct executable if there is no icon in lpIconPath directly.
917 * lpIconPath itself is supposed to be large enough, so make sure lpIconPathW
918 * is large enough too. Yes, I am puking too.
920 LPWSTR lpIconPathW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
922 TRACE("%p %s %p\n", hInst
, debugstr_a(lpIconPath
), lpiIcon
);
926 MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, lpIconPathW
, len
);
927 hIcon
= ExtractAssociatedIconW(hInst
, lpIconPathW
, lpiIcon
);
928 WideCharToMultiByte(CP_ACP
, 0, lpIconPathW
, -1, lpIconPath
, MAX_PATH
, NULL
, NULL
);
929 HeapFree(GetProcessHeap(), 0, lpIconPathW
);
934 /*************************************************************************
935 * ExtractAssociatedIconW (SHELL32.@)
937 * Return icon for given file (either from file itself or from associated
938 * executable) and patch parameters if needed.
940 HICON WINAPI
ExtractAssociatedIconW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIcon
)
945 TRACE("%p %s %p\n", hInst
, debugstr_w(lpIconPath
), lpiIcon
);
948 lpiIcon
= &wDummyIcon
;
950 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
952 if( hIcon
< (HICON
)2 )
953 { if( hIcon
== (HICON
)1 ) /* no icons found in given file */
954 { WCHAR tempPath
[MAX_PATH
];
955 HINSTANCE uRet
= FindExecutableW(lpIconPath
,NULL
,tempPath
);
957 if( uRet
> (HINSTANCE
)32 && tempPath
[0] )
958 { wcscpy(lpIconPath
,tempPath
);
959 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
960 if( hIcon
> (HICON
)2 )
965 if( hIcon
== (HICON
)1 )
966 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
968 *lpiIcon
= 6; /* generic icon - found nothing */
970 if (GetModuleFileNameW(hInst
, lpIconPath
, MAX_PATH
))
971 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(*lpiIcon
));
976 /*************************************************************************
977 * ExtractAssociatedIconExW (SHELL32.@)
979 * Return icon for given file (either from file itself or from associated
980 * executable) and patch parameters if needed.
982 EXTERN_C HICON WINAPI
ExtractAssociatedIconExW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
984 FIXME("%p %s %p %p): stub\n", hInst
, debugstr_w(lpIconPath
), lpiIconIdx
, lpiIconId
);
988 /*************************************************************************
989 * ExtractAssociatedIconExA (SHELL32.@)
991 * Return icon for given file (either from file itself or from associated
992 * executable) and patch parameters if needed.
994 EXTERN_C HICON WINAPI
ExtractAssociatedIconExA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
997 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, NULL
, 0 );
998 LPWSTR lpwstrFile
= (LPWSTR
)HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1000 TRACE("%p %s %p %p)\n", hInst
, lpIconPath
, lpiIconIdx
, lpiIconId
);
1002 MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, lpwstrFile
, len
);
1003 ret
= ExtractAssociatedIconExW(hInst
, lpwstrFile
, lpiIconIdx
, lpiIconId
);
1004 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
1009 /****************************************************************************
1010 * SHDefExtractIconW [SHELL32.@]
1012 HRESULT WINAPI
SHDefExtractIconW(LPCWSTR pszIconFile
, int iIndex
, UINT uFlags
,
1013 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
1017 WARN("%s %d 0x%08x %p %p %d, semi-stub\n", debugstr_w(pszIconFile
), iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
1019 ret
= PrivateExtractIconsW(pszIconFile
, iIndex
, nIconSize
, nIconSize
, hIcons
, NULL
, 2, LR_DEFAULTCOLOR
);
1020 /* FIXME: deal with uFlags parameter which contains GIL_ flags */
1021 if (ret
== 0xFFFFFFFF)
1025 *phiconLarge
= hIcons
[0];
1027 DestroyIcon(hIcons
[0]);
1029 *phiconSmall
= hIcons
[1];
1031 DestroyIcon(hIcons
[1]);
1037 /****************************************************************************
1038 * SHDefExtractIconA [SHELL32.@]
1040 HRESULT WINAPI
SHDefExtractIconA(LPCSTR pszIconFile
, int iIndex
, UINT uFlags
,
1041 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
1044 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, NULL
, 0);
1045 LPWSTR lpwstrFile
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1047 TRACE("%s %d 0x%08x %p %p %d\n", pszIconFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
1049 MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, lpwstrFile
, len
);
1050 ret
= SHDefExtractIconW(lpwstrFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
1051 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
1055 /****************************************************************************
1056 * SHGetIconOverlayIndexA [SHELL32.@]
1058 * Returns the index of the overlay icon in the system image list.
1060 EXTERN_C INT WINAPI
SHGetIconOverlayIndexA(LPCSTR pszIconPath
, INT iIconIndex
)
1062 FIXME("%s, %d\n", debugstr_a(pszIconPath
), iIconIndex
);
1067 /****************************************************************************
1068 * SHGetIconOverlayIndexW [SHELL32.@]
1070 * Returns the index of the overlay icon in the system image list.
1072 EXTERN_C INT WINAPI
SHGetIconOverlayIndexW(LPCWSTR pszIconPath
, INT iIconIndex
)
1074 FIXME("%s, %d\n", debugstr_w(pszIconPath
), iIconIndex
);