4 * taken and slightly changed from shell
5 * this should replace the icon extraction code in shell32 and shell16 once
6 * it needs a serious test for compliance with the native API
8 * Copyright 2000 Juergen Schmied
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /* Start of Hack section */
31 WINE_DEFAULT_DEBUG_CHANNEL(icon
);
37 BYTE bWidth
; /* Width, in pixels, of the image */
38 BYTE bHeight
; /* Height, in pixels, of the image */
39 BYTE bColorCount
; /* Number of colors in image (0 if >=8bpp) */
40 BYTE bReserved
; /* Reserved ( must be 0) */
41 WORD wPlanes
; /* Color Planes */
42 WORD wBitCount
; /* Bits per pixel */
43 DWORD dwBytesInRes
; /* How many bytes in this resource? */
44 DWORD dwImageOffset
; /* Where in the file is this image? */
45 } icoICONDIRENTRY
, *LPicoICONDIRENTRY
;
49 WORD idReserved
; /* Reserved (must be 0) */
50 WORD idType
; /* Resource Type (RES_ICON or RES_CURSOR) */
51 WORD idCount
; /* How many images */
52 icoICONDIRENTRY idEntries
[1]; /* An entry for each image (idCount of 'em) */
53 } icoICONDIR
, *LPicoICONDIR
;
57 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry
)
59 TRACE("width = 0x%08x height = 0x%08x\n", entry
->bWidth
, entry
->bHeight
);
60 TRACE("colors = 0x%08x planes = 0x%08x\n", entry
->bColorCount
, entry
->wPlanes
);
61 TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
62 entry
->wBitCount
, entry
->dwBytesInRes
, entry
->dwImageOffset
);
64 static void dumpIcoDir ( LPicoICONDIR entry
)
66 TRACE("type = 0x%08x count = 0x%08x\n", entry
->idType
, entry
->idCount
);
70 /**********************************************************************
73 * Find an entry by id in a resource directory
74 * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
76 static const IMAGE_RESOURCE_DIRECTORY
*find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY
*dir
,
77 WORD id
, const void *root
)
79 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*entry
;
82 entry
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(dir
+ 1);
83 min
= dir
->NumberOfNamedEntries
;
84 max
= min
+ dir
->NumberOfIdEntries
- 1;
87 pos
= (min
+ max
) / 2;
88 if (entry
[pos
].Id
== id
)
89 return (IMAGE_RESOURCE_DIRECTORY
*)((char *)root
+ entry
[pos
].OffsetToDirectory
);
90 if (entry
[pos
].Id
> id
) max
= pos
- 1;
96 /**********************************************************************
99 * Find a default entry in a resource directory
100 * Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
102 static const IMAGE_RESOURCE_DIRECTORY
*find_entry_default( const IMAGE_RESOURCE_DIRECTORY
*dir
,
105 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*entry
;
106 entry
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(dir
+ 1);
107 return (IMAGE_RESOURCE_DIRECTORY
*)((char *)root
+ entry
->OffsetToDirectory
);
110 /*************************************************************************
111 * USER32_GetResourceTable
113 static DWORD
USER32_GetResourceTable(LPBYTE peimage
,DWORD pesize
,LPBYTE
*retptr
)
115 IMAGE_DOS_HEADER
* mz_header
;
117 TRACE("%p %p\n", peimage
, retptr
);
121 mz_header
= (IMAGE_DOS_HEADER
*) peimage
;
123 if (mz_header
->e_magic
!= IMAGE_DOS_SIGNATURE
)
125 if (mz_header
->e_cblp
== 1) /* .ICO file ? */
127 *retptr
= (LPBYTE
)-1; /* ICONHEADER.idType, must be 1 */
131 return 0; /* failed */
133 if (mz_header
->e_lfanew
>= pesize
) {
134 return 0; /* failed, happens with PKZIP DOS Exes for instance. */
136 if (*((DWORD
*)(peimage
+ mz_header
->e_lfanew
)) == IMAGE_NT_SIGNATURE
)
137 return IMAGE_NT_SIGNATURE
;
139 if (*((WORD
*)(peimage
+ mz_header
->e_lfanew
)) == IMAGE_OS2_SIGNATURE
)
141 IMAGE_OS2_HEADER
* ne_header
;
143 ne_header
= (IMAGE_OS2_HEADER
*)(peimage
+ mz_header
->e_lfanew
);
145 if (ne_header
->ne_magic
!= IMAGE_OS2_SIGNATURE
)
148 if( (ne_header
->ne_restab
- ne_header
->ne_rsrctab
) <= sizeof(NE_TYPEINFO
) )
149 *retptr
= (LPBYTE
)-1;
151 *retptr
= peimage
+ mz_header
->e_lfanew
+ ne_header
->ne_rsrctab
;
153 return IMAGE_OS2_SIGNATURE
;
156 return 0; /* failed */
159 /*************************************************************************
160 * USER32_LoadResource
162 static BYTE
* USER32_LoadResource( LPBYTE peimage
, NE_NAMEINFO
* pNInfo
, WORD sizeShift
, ULONG
*uSize
)
164 TRACE("%p %p 0x%08x\n", peimage
, pNInfo
, sizeShift
);
166 *uSize
= (DWORD
)pNInfo
->length
<< sizeShift
;
167 return peimage
+ ((DWORD
)pNInfo
->offset
<< sizeShift
);
170 /*************************************************************************
173 static BYTE
* ICO_LoadIcon( LPBYTE peimage
, LPicoICONDIRENTRY lpiIDE
, ULONG
*uSize
)
175 TRACE("%p %p\n", peimage
, lpiIDE
);
177 *uSize
= lpiIDE
->dwBytesInRes
;
178 return peimage
+ lpiIDE
->dwImageOffset
;
181 /*************************************************************************
182 * ICO_GetIconDirectory
184 * Reads .ico file and build phony ICONDIR struct
185 * see http://www.microsoft.com/win32dev/ui/icons.htm
187 #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
188 #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
190 static BYTE
* ICO_GetIconDirectory( LPBYTE peimage
, LPicoICONDIR
* lplpiID
, ULONG
*uSize
)
192 CURSORICONDIR
* lpcid
; /* icon resource in resource-dir format */
193 CURSORICONDIR
* lpID
; /* icon resource in resource format */
196 TRACE("%p %p\n", peimage
, lplpiID
);
198 lpcid
= (CURSORICONDIR
*)peimage
;
200 if( lpcid
->idReserved
|| (lpcid
->idType
!= 1) || (!lpcid
->idCount
) )
203 /* allocate the phony ICONDIR structure */
204 *uSize
= lpcid
->idCount
* sizeof(CURSORICONDIRENTRY
) + HEADER_SIZE
;
205 if( (lpID
= (CURSORICONDIR
*)HeapAlloc(GetProcessHeap(),0, *uSize
) ))
207 /* copy the header */
208 lpID
->idReserved
= lpcid
->idReserved
;
209 lpID
->idType
= lpcid
->idType
;
210 lpID
->idCount
= lpcid
->idCount
;
212 /* copy the entries */
213 for( i
=0; i
< lpcid
->idCount
; i
++ )
215 memcpy((void*)&(lpID
->idEntries
[i
]),(void*)&(lpcid
->idEntries
[i
]), sizeof(CURSORICONDIRENTRY
) - 2);
216 lpID
->idEntries
[i
].wResId
= i
;
219 *lplpiID
= (LPicoICONDIR
)peimage
;
225 /*************************************************************************
226 * ICO_ExtractIconExW [internal]
229 * nIcons = 0: returns number of Icons in file
234 * success: number of icons in file (nIcons = 0) or nr of icons retrieved
236 static UINT
ICO_ExtractIconExW(
237 LPCWSTR lpszExeFileName
,
247 UINT cx1
, cx2
, cy1
, cy2
;
251 UINT16 iconDirCount
= 0; //,iconCount = 0;
256 WCHAR szExePath
[MAX_PATH
];
257 DWORD dwSearchReturn
;
259 TRACE("%s, %d, %d %p 0x%08x\n", debugstr_w(lpszExeFileName
), nIconIndex
, nIcons
, pIconId
, flags
);
261 dwSearchReturn
= SearchPathW(NULL
, lpszExeFileName
, NULL
, sizeof(szExePath
) / sizeof(szExePath
[0]), szExePath
, NULL
);
262 if ((dwSearchReturn
== 0) || (dwSearchReturn
> sizeof(szExePath
) / sizeof(szExePath
[0])))
264 WARN("File %s not found or path too long\n", debugstr_w(lpszExeFileName
));
268 hFile
= CreateFileW(szExePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
269 if (hFile
== INVALID_HANDLE_VALUE
) return ret
;
270 fsizel
= GetFileSize(hFile
,&fsizeh
);
273 fmapping
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
| SEC_COMMIT
, 0, 0, NULL
);
277 WARN("CreateFileMapping error %ld\n", GetLastError() );
281 if (!(peimage
= MapViewOfFile(fmapping
, FILE_MAP_READ
, 0, 0, 0)))
283 WARN("MapViewOfFile error %ld\n", GetLastError() );
284 CloseHandle(fmapping
);
287 CloseHandle(fmapping
);
289 cx1
= LOWORD(cxDesired
);
290 cx2
= HIWORD(cxDesired
) ? HIWORD(cxDesired
) : cx1
;
291 cy1
= LOWORD(cyDesired
);
292 cy2
= HIWORD(cyDesired
) ? HIWORD(cyDesired
) : cy1
;
294 if (pIconId
) /* Invalidate first icon identifier */
295 *pIconId
= 0xFFFFFFFF;
297 if (!pIconId
) /* if no icon identifier array present use the icon handle array as intermediate storage */
298 pIconId
= (UINT
*)RetPtr
;
300 sig
= USER32_GetResourceTable(peimage
, fsizel
, &pData
);
302 /* ico file or NE exe/dll*/
304 if (sig
==IMAGE_OS2_SIGNATURE
|| sig
==1) /* .ICO file */
307 NE_TYPEINFO
*pTInfo
= (NE_TYPEINFO
*)(pData
+ 2);
308 NE_NAMEINFO
*pIconStorage
= NULL
;
309 NE_NAMEINFO
*pIconDir
= NULL
;
310 LPicoICONDIR lpiID
= NULL
;
312 TRACE("-- OS2/icon Signature (0x%08lx)\n", sig
);
314 if (pData
== (BYTE
*)-1)
316 pCIDir
= ICO_GetIconDirectory(peimage
, &lpiID
, &uSize
); /* check for .ICO file */
319 iconDirCount
= 1; iconCount
= lpiID
->idCount
;
320 TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir
, uSize
, iconDirCount
, iconCount
);
323 else while (pTInfo
->type_id
&& !(pIconStorage
&& pIconDir
))
325 if (pTInfo
->type_id
== NE_RSCTYPE_GROUP_ICON
) /* find icon directory and icon repository */
327 iconDirCount
= pTInfo
->count
;
328 pIconDir
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
329 TRACE("\tfound directory - %i icon families\n", iconDirCount
);
331 if (pTInfo
->type_id
== NE_RSCTYPE_ICON
)
333 iconCount
= pTInfo
->count
;
334 pIconStorage
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
335 TRACE("\ttotal icons - %i\n", iconCount
);
337 pTInfo
= (NE_TYPEINFO
*)((char*)(pTInfo
+1)+pTInfo
->count
*sizeof(NE_NAMEINFO
));
340 if ((pIconStorage
&& pIconDir
) || lpiID
) /* load resources and create icons */
345 if (lpiID
&& pCIDir
) /* *.ico file, deallocate heap pointer*/
346 HeapFree(GetProcessHeap(), 0, pCIDir
);
348 else if (nIconIndex
< iconDirCount
)
351 if (nIcons
> iconDirCount
- nIconIndex
)
352 nIcons
= iconDirCount
- nIconIndex
;
354 for (i
= 0; i
< nIcons
; i
++)
356 /* .ICO files have only one icon directory */
357 if (lpiID
== NULL
) /* not *.ico */
358 pCIDir
= USER32_LoadResource(peimage
, pIconDir
+ i
+ nIconIndex
, *(WORD
*)pData
, &uSize
);
359 pIconId
[i
] = LookupIconIdFromDirectoryEx(pCIDir
, TRUE
, (i
& 1) ? cx2
: cx1
, (i
& 1) ? cy2
: cy1
, flags
);
361 if (lpiID
&& pCIDir
) /* *.ico file, deallocate heap pointer*/
362 HeapFree(GetProcessHeap(), 0, pCIDir
);
364 for (icon
= 0; icon
< nIcons
; icon
++)
368 pCIDir
= ICO_LoadIcon(peimage
, lpiID
->idEntries
+ (int)pIconId
[icon
], &uSize
);
370 for (i
= 0; i
< iconCount
; i
++)
371 if (pIconStorage
[i
].id
== ((int)pIconId
[icon
] | 0x8000) )
372 pCIDir
= USER32_LoadResource(peimage
, pIconStorage
+ i
, *(WORD
*)pData
, &uSize
);
375 RetPtr
[icon
] = (HICON
)CreateIconFromResourceEx(pCIDir
, uSize
, TRUE
, 0x00030000,
376 (icon
& 1) ? cx2
: cx1
, (icon
& 1) ? cy2
: cy1
, flags
);
380 ret
= icon
; /* return number of retrieved icons */
387 else if( sig
== IMAGE_NT_SIGNATURE
)
389 if( sig
== IMAGE_NT_SIGNATURE
)
392 PIMAGE_DOS_HEADER dheader
;
393 PIMAGE_NT_HEADERS pe_header
;
394 PIMAGE_SECTION_HEADER pe_sections
;
395 const IMAGE_RESOURCE_DIRECTORY
*rootresdir
,*iconresdir
,*icongroupresdir
;
396 const IMAGE_RESOURCE_DATA_ENTRY
*idataent
,*igdataent
;
397 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*xresent
;
400 dheader
= (PIMAGE_DOS_HEADER
)peimage
;
401 pe_header
= (PIMAGE_NT_HEADERS
)(peimage
+dheader
->e_lfanew
); /* it is a pe header, USER32_GetResourceTable checked that */
402 pe_sections
= (PIMAGE_SECTION_HEADER
)(((char*)pe_header
) + sizeof(DWORD
) + sizeof(IMAGE_FILE_HEADER
)
403 + pe_header
->FileHeader
.SizeOfOptionalHeader
);
406 /* search for the root resource directory */
407 for (i
=0;i
<pe_header
->FileHeader
.NumberOfSections
;i
++)
409 if (pe_sections
[i
].Characteristics
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
)
411 if (fsizel
< pe_sections
[i
].PointerToRawData
+pe_sections
[i
].SizeOfRawData
) {
412 FIXME("File %s too short (section is at %ld bytes, real size is %ld)\n",
413 debugstr_w(lpszExeFileName
),
414 pe_sections
[i
].PointerToRawData
+pe_sections
[i
].SizeOfRawData
,
419 /* FIXME: doesn't work when the resources are not in a separate section */
420 if (pe_sections
[i
].VirtualAddress
== pe_header
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
)
422 rootresdir
= (PIMAGE_RESOURCE_DIRECTORY
)(peimage
+pe_sections
[i
].PointerToRawData
);
429 WARN("haven't found section for resource directory.\n");
430 goto end
; /* failure */
433 /* search for the group icon directory */
434 if (!(icongroupresdir
= find_entry_by_id(rootresdir
, LOWORD(RT_GROUP_ICON
), rootresdir
)))
436 WARN("No Icongroupresourcedirectory!\n");
437 goto end
; /* failure */
439 iconDirCount
= icongroupresdir
->NumberOfNamedEntries
+ icongroupresdir
->NumberOfIdEntries
;
441 /* only number of icons requested */
445 goto end
; /* success */
450 /* search resource id */
452 int iId
= abs(nIconIndex
);
453 PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1);
455 while(n
<iconDirCount
&& xprdeTmp
)
457 if(xprdeTmp
->Id
== iId
)
467 WARN("resource id %d not found\n", iId
);
468 goto end
; /* failure */
473 /* check nIconIndex to be in range */
474 if (nIconIndex
>= iconDirCount
)
476 WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex
,iconDirCount
);
477 goto end
; /* failure */
481 /* assure we don't get too much */
482 if( nIcons
/ 2 > iconDirCount
- nIconIndex
)
483 nIcons
= 2 * (iconDirCount
- nIconIndex
);
485 /* starting from specified index */
486 xresent
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1) + nIconIndex
;
488 for (i
=0; i
< nIcons
; i
++)
490 const IMAGE_RESOURCE_DIRECTORY
*resdir
;
492 /* go down this resource entry, name */
493 resdir
= (PIMAGE_RESOURCE_DIRECTORY
)((DWORD
)rootresdir
+(xresent
->OffsetToDirectory
));
495 /* default language (0) */
496 resdir
= find_entry_default(resdir
,rootresdir
);
497 igdataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)resdir
;
499 /* lookup address in mapped image for virtual address */
502 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
504 if (igdataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
506 if (igdataent
->OffsetToData
+igdataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
509 if (igdataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
+igdataent
->Size
> fsizel
) {
510 FIXME("overflow in PE lookup (%s has len %ld, have offset %ld), short file?\n", debugstr_w(lpszExeFileName
), fsizel
,
511 igdataent
->OffsetToData
- pe_sections
[j
].VirtualAddress
+ pe_sections
[j
].PointerToRawData
+ igdataent
->Size
);
512 goto end
; /* failure */
514 igdata
= peimage
+(igdataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
519 FIXME("no matching real address for icongroup!\n");
520 goto end
; /* failure */
522 pIconId
[i
] = LookupIconIdFromDirectoryEx(igdata
, TRUE
, (i
& 1) ? cx2
: cx1
, (i
& 1) ? cy2
: cy1
, flags
);
523 if (i
& 1) xresent
++;
526 if (!(iconresdir
=find_entry_by_id(rootresdir
,LOWORD(RT_ICON
),rootresdir
)))
528 WARN("No Iconresourcedirectory!\n");
529 goto end
; /* failure */
532 for (i
=0; i
<nIcons
; i
++)
534 const IMAGE_RESOURCE_DIRECTORY
*xresdir
;
535 xresdir
= find_entry_by_id(iconresdir
, LOWORD(pIconId
[i
]), rootresdir
);
536 xresdir
= find_entry_default(xresdir
, rootresdir
);
537 idataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)xresdir
;
540 /* map virtual to address in image */
541 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
543 if (idataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
545 if (idataent
->OffsetToData
+idataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
547 idata
= peimage
+(idataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
551 WARN("no matching real address found for icondata!\n");
555 RetPtr
[i
] = (HICON
) CreateIconFromResourceEx(idata
,idataent
->Size
,TRUE
,0x00030000,
556 (i
& 1) ? cx2
: cx1
, (i
& 1) ? cy2
: cy1
, flags
);
558 ret
= i
; /* return number of retrieved icons */
559 } /* if(sig == IMAGE_NT_SIGNATURE) */
562 UnmapViewOfFile(peimage
); /* success */
566 /***********************************************************************
567 * PrivateExtractIconsW [USER32.@]
571 * If HIWORD(sizeX) && HIWORD(sizeY) 2 * ((nIcons + 1) MOD 2) icons are
572 * returned, with the LOWORD size icon first and the HIWORD size icon
574 * Also the Windows equivalent does extract icons in a strange way if
575 * nIndex is negative. Our implementation treats a negative nIndex as
576 * looking for that resource identifier for the first icon to retrieve.
579 * should also support 16 bit EXE + DLLs, cursor and animated cursor as
580 * well as bitmap files.
583 UINT WINAPI
PrivateExtractIconsW (
588 HICON
* phicon
, /* [out] pointer to array of nIcons HICON handles */
589 UINT
* pIconId
, /* [out] pointer to array of nIcons icon identifiers or NULL */
590 UINT nIcons
, /* [in] number of icons to retrieve */
591 UINT flags
) /* [in] LR_* flags used by LoadImage */
593 TRACE("%s %d %dx%d %p %p %d 0x%08x\n",
594 debugstr_w(lpwstrFile
), nIndex
, sizeX
, sizeY
, phicon
, pIconId
, nIcons
, flags
);
596 if ((nIcons
& 1) && HIWORD(sizeX
) && HIWORD(sizeY
))
598 WARN("Uneven number %d of icons requested for small and large icons!", nIcons
);
600 return ICO_ExtractIconExW(lpwstrFile
, phicon
, nIndex
, nIcons
, sizeX
, sizeY
, pIconId
, flags
);
603 /***********************************************************************
604 * PrivateExtractIconsA [USER32.@]
608 UINT WINAPI
PrivateExtractIconsA (
613 HICON
* phicon
, /* [out] pointer to array of nIcons HICON handles */
614 UINT
* piconid
, /* [out] pointer to array of nIcons icon identifiers or NULL */
615 UINT nIcons
, /* [in] number of icons to retrieve */
616 UINT flags
) /* [in] LR_* flags used by LoadImage */
619 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpstrFile
, -1, NULL
, 0);
620 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
622 MultiByteToWideChar(CP_ACP
, 0, lpstrFile
, -1, lpwstrFile
, len
);
623 ret
= PrivateExtractIconsW(lpwstrFile
, nIndex
, sizeX
, sizeY
, phicon
, piconid
, nIcons
, flags
);
625 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
629 /***********************************************************************
630 * PrivateExtractIconExW [USER32.@]
633 * if nIndex == -1 it returns the number of icons in any case !!!
635 UINT WINAPI
PrivateExtractIconExW (
642 DWORD cyicon
, cysmicon
, cxicon
, cxsmicon
;
645 TRACE("%s %d %p %p %d\n",
646 debugstr_w(lpwstrFile
),nIndex
,phIconLarge
, phIconSmall
, nIcons
);
649 /* get the number of icons */
650 return ICO_ExtractIconExW(lpwstrFile
, NULL
, 0, 0, 0, 0, NULL
, LR_DEFAULTCOLOR
);
652 if (nIcons
== 1 && phIconSmall
&& phIconLarge
)
655 cxicon
= GetSystemMetrics(SM_CXICON
);
656 cyicon
= GetSystemMetrics(SM_CYICON
);
657 cxsmicon
= GetSystemMetrics(SM_CXSMICON
);
658 cysmicon
= GetSystemMetrics(SM_CYSMICON
);
660 ret
= ICO_ExtractIconExW(lpwstrFile
, (HICON
*) &hIcon
, nIndex
, 2, cxicon
| (cxsmicon
<<16),
661 cyicon
| (cysmicon
<<16), NULL
, LR_DEFAULTCOLOR
);
662 *phIconLarge
= (1 <= ret
? hIcon
[0] : NULL
);
663 *phIconSmall
= (2 <= ret
? hIcon
[1] : NULL
);
669 /* extract n small icons */
670 cxsmicon
= GetSystemMetrics(SM_CXSMICON
);
671 cysmicon
= GetSystemMetrics(SM_CYSMICON
);
672 ret
= ICO_ExtractIconExW(lpwstrFile
, phIconSmall
, nIndex
, nIcons
, cxsmicon
,
673 cysmicon
, NULL
, LR_DEFAULTCOLOR
);
677 /* extract n large icons */
678 cxicon
= GetSystemMetrics(SM_CXICON
);
679 cyicon
= GetSystemMetrics(SM_CYICON
);
680 ret
= ICO_ExtractIconExW(lpwstrFile
, phIconLarge
, nIndex
, nIcons
, cxicon
,
681 cyicon
, NULL
, LR_DEFAULTCOLOR
);
686 /***********************************************************************
687 * PrivateExtractIconExA [USER32.@]
690 UINT WINAPI
PrivateExtractIconExA (
698 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpstrFile
, -1, NULL
, 0);
699 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
701 TRACE("%s %d %p %p %d\n", lpstrFile
, nIndex
, phIconLarge
, phIconSmall
, nIcons
);
703 MultiByteToWideChar(CP_ACP
, 0, lpstrFile
, -1, lpwstrFile
, len
);
704 ret
= PrivateExtractIconExW(lpwstrFile
, nIndex
, phIconLarge
, phIconSmall
, nIcons
);
705 HeapFree(GetProcessHeap(), 0, lpwstrFile
);