2000-06-13 00:00:11 +02:00
|
|
|
/*
|
|
|
|
* icon extracting
|
|
|
|
*
|
|
|
|
* taken and slightly changed from shell
|
|
|
|
* this should replace the icon extraction code in shell32 and shell16 once
|
2002-06-01 01:06:46 +02:00
|
|
|
* it needs a serious test for compliance with the native API
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Juergen Schmied
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-13 00:00:11 +02:00
|
|
|
*/
|
2001-10-14 18:18:52 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-13 00:00:11 +02:00
|
|
|
#include <string.h>
|
2000-10-23 01:45:50 +02:00
|
|
|
#include <stdlib.h> /* abs() */
|
2000-06-13 00:00:11 +02:00
|
|
|
#include <sys/types.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2000-06-13 00:00:11 +02:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2000-06-13 00:00:11 +02:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "winuser.h"
|
2000-12-01 22:32:55 +01:00
|
|
|
#include "wine/winbase16.h"
|
2000-06-13 00:00:11 +02:00
|
|
|
#include "cursoricon.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(icon);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
#include "pshpack1.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE bWidth; /* Width, in pixels, of the image */
|
|
|
|
BYTE bHeight; /* Height, in pixels, of the image */
|
|
|
|
BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
|
|
|
|
BYTE bReserved; /* Reserved ( must be 0) */
|
|
|
|
WORD wPlanes; /* Color Planes */
|
|
|
|
WORD wBitCount; /* Bits per pixel */
|
|
|
|
DWORD dwBytesInRes; /* How many bytes in this resource? */
|
|
|
|
DWORD dwImageOffset; /* Where in the file is this image? */
|
|
|
|
} icoICONDIRENTRY, *LPicoICONDIRENTRY;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD idReserved; /* Reserved (must be 0) */
|
|
|
|
WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
|
|
|
|
WORD idCount; /* How many images */
|
|
|
|
icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
|
|
|
|
} icoICONDIR, *LPicoICONDIR;
|
|
|
|
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-06-13 00:00:11 +02:00
|
|
|
TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
|
|
|
|
TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
|
2000-06-13 00:00:11 +02:00
|
|
|
entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
|
|
|
|
}
|
|
|
|
static void dumpIcoDir ( LPicoICONDIR entry )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-06-13 00:00:11 +02:00
|
|
|
TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
|
|
|
|
}
|
|
|
|
#endif
|
2000-10-23 03:35:46 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_entry_by_id
|
|
|
|
*
|
|
|
|
* Find an entry by id in a resource directory
|
|
|
|
* Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
|
|
|
|
*/
|
|
|
|
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
|
|
|
|
WORD id, const void *root )
|
|
|
|
{
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
|
|
|
int min, max, pos;
|
|
|
|
|
|
|
|
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
|
|
|
min = dir->NumberOfNamedEntries;
|
|
|
|
max = min + dir->NumberOfIdEntries - 1;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
pos = (min + max) / 2;
|
2000-12-19 04:38:53 +01:00
|
|
|
if (entry[pos].u1.s2.Id == id)
|
2004-11-30 22:38:57 +01:00
|
|
|
return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s3.OffsetToDirectory);
|
2000-12-19 04:38:53 +01:00
|
|
|
if (entry[pos].u1.s2.Id > id) max = pos - 1;
|
2000-10-23 03:35:46 +02:00
|
|
|
else min = pos + 1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_entry_default
|
|
|
|
*
|
|
|
|
* Find a default entry in a resource directory
|
|
|
|
* Copied from loader/pe_resource.c (FIXME: should use exported resource functions)
|
|
|
|
*/
|
|
|
|
static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
|
|
|
|
const void *root )
|
|
|
|
{
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
|
|
|
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
2004-11-30 22:38:57 +01:00
|
|
|
return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry->u2.s3.OffsetToDirectory);
|
2000-10-23 03:35:46 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 00:00:11 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* USER32_GetResourceTable
|
|
|
|
*/
|
2000-10-23 01:45:50 +02:00
|
|
|
static DWORD USER32_GetResourceTable(LPBYTE peimage,DWORD pesize,LPBYTE *retptr)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER * mz_header;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("%p %p\n", peimage, retptr);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
*retptr = NULL;
|
|
|
|
|
|
|
|
mz_header = (IMAGE_DOS_HEADER*) peimage;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-13 00:00:11 +02:00
|
|
|
if (mz_header->e_magic != IMAGE_DOS_SIGNATURE)
|
|
|
|
{
|
|
|
|
if (mz_header->e_cblp == 1) /* .ICO file ? */
|
|
|
|
{
|
|
|
|
*retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* failed */
|
|
|
|
}
|
2000-10-23 01:45:50 +02:00
|
|
|
if (mz_header->e_lfanew >= pesize) {
|
|
|
|
return 0; /* failed, happens with PKZIP DOS Exes for instance. */
|
|
|
|
}
|
2000-06-13 00:00:11 +02:00
|
|
|
if (*((DWORD*)(peimage + mz_header->e_lfanew)) == IMAGE_NT_SIGNATURE )
|
|
|
|
return IMAGE_NT_SIGNATURE;
|
|
|
|
|
|
|
|
if (*((WORD*)(peimage + mz_header->e_lfanew)) == IMAGE_OS2_SIGNATURE )
|
|
|
|
{
|
|
|
|
IMAGE_OS2_HEADER * ne_header;
|
|
|
|
|
|
|
|
ne_header = (IMAGE_OS2_HEADER*)(peimage + mz_header->e_lfanew);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-13 00:00:11 +02:00
|
|
|
if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( (ne_header->ne_restab - ne_header->ne_rsrctab) <= sizeof(NE_TYPEINFO) )
|
|
|
|
*retptr = (LPBYTE)-1;
|
|
|
|
else
|
|
|
|
*retptr = peimage + mz_header->e_lfanew + ne_header->ne_rsrctab;
|
|
|
|
|
|
|
|
return IMAGE_OS2_SIGNATURE;
|
|
|
|
}
|
|
|
|
return 0; /* failed */
|
|
|
|
}
|
|
|
|
/*************************************************************************
|
|
|
|
* USER32_LoadResource
|
|
|
|
*/
|
|
|
|
static BYTE * USER32_LoadResource( LPBYTE peimage, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
|
|
|
|
{
|
|
|
|
TRACE("%p %p 0x%08x\n", peimage, pNInfo, sizeShift);
|
|
|
|
|
|
|
|
*uSize = (DWORD)pNInfo->length << sizeShift;
|
|
|
|
return peimage + ((DWORD)pNInfo->offset << sizeShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* ICO_LoadIcon
|
|
|
|
*/
|
|
|
|
static BYTE * ICO_LoadIcon( LPBYTE peimage, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
|
|
|
|
{
|
|
|
|
TRACE("%p %p\n", peimage, lpiIDE);
|
|
|
|
|
|
|
|
*uSize = lpiIDE->dwBytesInRes;
|
|
|
|
return peimage + lpiIDE->dwImageOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* ICO_GetIconDirectory
|
|
|
|
*
|
|
|
|
* Reads .ico file and build phony ICONDIR struct
|
|
|
|
* see http://www.microsoft.com/win32dev/ui/icons.htm
|
|
|
|
*/
|
|
|
|
#define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
|
|
|
|
#define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG *uSize )
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
CURSORICONDIR * lpcid; /* icon resource in resource-dir format */
|
|
|
|
CURSORICONDIR * lpID; /* icon resource in resource format */
|
|
|
|
int i;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("%p %p\n", peimage, lplpiID);
|
|
|
|
|
2000-06-13 00:00:11 +02:00
|
|
|
lpcid = (CURSORICONDIR*)peimage;
|
|
|
|
|
|
|
|
if( lpcid->idReserved || (lpcid->idType != 1) || (!lpcid->idCount) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* allocate the phony ICONDIR structure */
|
|
|
|
*uSize = lpcid->idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
|
2005-03-24 22:01:35 +01:00
|
|
|
if( (lpID = HeapAlloc(GetProcessHeap(),0, *uSize) ))
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
/* copy the header */
|
|
|
|
lpID->idReserved = lpcid->idReserved;
|
|
|
|
lpID->idType = lpcid->idType;
|
|
|
|
lpID->idCount = lpcid->idCount;
|
|
|
|
|
2001-11-06 22:01:32 +01:00
|
|
|
/* copy the entries */
|
2000-06-13 00:00:11 +02:00
|
|
|
for( i=0; i < lpcid->idCount; i++ )
|
|
|
|
{
|
|
|
|
memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpcid->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
|
|
|
|
lpID->idEntries[i].wResId = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lplpiID = (LPicoICONDIR)peimage;
|
|
|
|
return (BYTE *)lpID;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* ICO_ExtractIconExW [internal]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* nIcons = 0: returns number of Icons in file
|
|
|
|
*
|
|
|
|
* returns
|
2002-12-10 20:09:45 +01:00
|
|
|
* invalid file: -1
|
|
|
|
* failure:0;
|
|
|
|
* success: number of icons in file (nIcons = 0) or nr of icons retrieved
|
2000-06-13 00:00:11 +02:00
|
|
|
*/
|
2002-12-03 22:35:27 +01:00
|
|
|
static UINT ICO_ExtractIconExW(
|
2000-06-13 00:00:11 +02:00
|
|
|
LPCWSTR lpszExeFileName,
|
|
|
|
HICON * RetPtr,
|
|
|
|
INT nIconIndex,
|
|
|
|
UINT nIcons,
|
|
|
|
UINT cxDesired,
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT cyDesired,
|
|
|
|
UINT *pIconId,
|
|
|
|
UINT flags)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-12 23:59:50 +01:00
|
|
|
UINT ret = 0;
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT cx1, cx2, cy1, cy2;
|
2000-06-13 00:00:11 +02:00
|
|
|
LPBYTE pData;
|
|
|
|
DWORD sig;
|
2002-07-31 19:20:00 +02:00
|
|
|
HANDLE hFile;
|
2000-06-13 00:00:11 +02:00
|
|
|
UINT16 iconDirCount = 0,iconCount = 0;
|
|
|
|
LPBYTE peimage;
|
|
|
|
HANDLE fmapping;
|
|
|
|
ULONG uSize;
|
2000-10-23 01:45:50 +02:00
|
|
|
DWORD fsizeh,fsizel;
|
2003-05-14 01:38:21 +02:00
|
|
|
WCHAR szExePath[MAX_PATH];
|
|
|
|
DWORD dwSearchReturn;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
TRACE("%s, %d, %d %p 0x%08x\n", debugstr_w(lpszExeFileName), nIconIndex, nIcons, pIconId, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2003-05-14 01:38:21 +02:00
|
|
|
dwSearchReturn = SearchPathW(NULL, lpszExeFileName, NULL, sizeof(szExePath) / sizeof(szExePath[0]), szExePath, NULL);
|
|
|
|
if ((dwSearchReturn == 0) || (dwSearchReturn > sizeof(szExePath) / sizeof(szExePath[0])))
|
|
|
|
{
|
|
|
|
WARN("File %s not found or path too long\n", debugstr_w(lpszExeFileName));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hFile = CreateFileW(szExePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
2002-12-03 22:35:27 +01:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return ret;
|
2000-10-23 01:45:50 +02:00
|
|
|
fsizel = GetFileSize(hFile,&fsizeh);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
/* Map the file */
|
2002-12-12 23:59:50 +01:00
|
|
|
fmapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
|
|
|
|
CloseHandle(hFile);
|
2000-06-13 00:00:11 +02:00
|
|
|
if (!fmapping)
|
|
|
|
{
|
|
|
|
WARN("CreateFileMapping error %ld\n", GetLastError() );
|
2002-12-12 23:59:50 +01:00
|
|
|
return 0xFFFFFFFF;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
if (!(peimage = MapViewOfFile(fmapping, FILE_MAP_READ, 0, 0, 0)))
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("MapViewOfFile error %ld\n", GetLastError() );
|
2002-12-12 23:59:50 +01:00
|
|
|
CloseHandle(fmapping);
|
|
|
|
return 0xFFFFFFFF;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-12 23:59:50 +01:00
|
|
|
CloseHandle(fmapping);
|
2002-12-10 20:09:45 +01:00
|
|
|
|
|
|
|
cx1 = LOWORD(cxDesired);
|
|
|
|
cx2 = HIWORD(cxDesired) ? HIWORD(cxDesired) : cx1;
|
|
|
|
cy1 = LOWORD(cyDesired);
|
|
|
|
cy2 = HIWORD(cyDesired) ? HIWORD(cyDesired) : cy1;
|
|
|
|
|
|
|
|
if (pIconId) /* Invalidate first icon identifier */
|
|
|
|
*pIconId = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
if (!pIconId) /* if no icon identifier array present use the icon handle array as intermediate storage */
|
|
|
|
pIconId = (UINT*)RetPtr;
|
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
sig = USER32_GetResourceTable(peimage, fsizel, &pData);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
/* ico file or NE exe/dll*/
|
|
|
|
if (sig==IMAGE_OS2_SIGNATURE || sig==1) /* .ICO file */
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
BYTE *pCIDir = 0;
|
|
|
|
NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
|
|
|
|
NE_NAMEINFO *pIconStorage = NULL;
|
|
|
|
NE_NAMEINFO *pIconDir = NULL;
|
|
|
|
LPicoICONDIR lpiID = NULL;
|
|
|
|
|
|
|
|
TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
|
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
if (pData == (BYTE*)-1)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize); /* check for .ICO file */
|
2002-12-12 23:59:50 +01:00
|
|
|
if (pCIDir)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
iconDirCount = 1; iconCount = lpiID->idCount;
|
|
|
|
TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
|
|
|
|
}
|
|
|
|
}
|
2002-12-12 23:59:50 +01:00
|
|
|
else while (pTInfo->type_id && !(pIconStorage && pIconDir))
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-12 23:59:50 +01:00
|
|
|
if (pTInfo->type_id == NE_RSCTYPE_GROUP_ICON) /* find icon directory and icon repository */
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
iconDirCount = pTInfo->count;
|
|
|
|
pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
|
|
|
TRACE("\tfound directory - %i icon families\n", iconDirCount);
|
|
|
|
}
|
2002-12-12 23:59:50 +01:00
|
|
|
if (pTInfo->type_id == NE_RSCTYPE_ICON)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
iconCount = pTInfo->count;
|
|
|
|
pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
|
|
|
TRACE("\ttotal icons - %i\n", iconCount);
|
|
|
|
}
|
|
|
|
pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
|
|
|
}
|
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
if ((pIconStorage && pIconDir) || lpiID) /* load resources and create icons */
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-12 23:59:50 +01:00
|
|
|
if (nIcons == 0)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-03 22:35:27 +01:00
|
|
|
ret = iconDirCount;
|
2002-12-12 23:59:50 +01:00
|
|
|
if (lpiID && pCIDir) /* *.ico file, deallocate heap pointer*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, pCIDir);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-12 23:59:50 +01:00
|
|
|
else if (nIconIndex < iconDirCount)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
UINT16 i, icon;
|
2002-12-12 23:59:50 +01:00
|
|
|
if (nIcons > iconDirCount - nIconIndex)
|
2000-06-13 00:00:11 +02:00
|
|
|
nIcons = iconDirCount - nIconIndex;
|
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
for (i = 0; i < nIcons; i++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
/* .ICO files have only one icon directory */
|
2002-12-12 23:59:50 +01:00
|
|
|
if (lpiID == NULL) /* not *.ico */
|
|
|
|
pCIDir = USER32_LoadResource(peimage, pIconDir + i + nIconIndex, *(WORD*)pData, &uSize);
|
2002-12-10 20:09:45 +01:00
|
|
|
pIconId[i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, (i & 1) ? cx2 : cx1, (i & 1) ? cy2 : cy1, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-12 23:59:50 +01:00
|
|
|
if (lpiID && pCIDir) /* *.ico file, deallocate heap pointer*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, pCIDir);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
for (icon = 0; icon < nIcons; icon++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
pCIDir = NULL;
|
2002-12-12 23:59:50 +01:00
|
|
|
if (lpiID)
|
2002-12-10 20:09:45 +01:00
|
|
|
pCIDir = ICO_LoadIcon(peimage, lpiID->idEntries + (int)pIconId[icon], &uSize);
|
2000-06-13 00:00:11 +02:00
|
|
|
else
|
2002-12-10 20:09:45 +01:00
|
|
|
for (i = 0; i < iconCount; i++)
|
|
|
|
if (pIconStorage[i].id == ((int)pIconId[icon] | 0x8000) )
|
|
|
|
pCIDir = USER32_LoadResource(peimage, pIconStorage + i, *(WORD*)pData, &uSize);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-12 23:59:50 +01:00
|
|
|
if (pCIDir)
|
2002-12-10 20:09:45 +01:00
|
|
|
RetPtr[icon] = (HICON)CreateIconFromResourceEx(pCIDir, uSize, TRUE, 0x00030000,
|
|
|
|
(icon & 1) ? cx2 : cx1, (icon & 1) ? cy2 : cy1, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
else
|
2002-12-10 20:09:45 +01:00
|
|
|
RetPtr[icon] = 0;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-10 20:09:45 +01:00
|
|
|
ret = icon; /* return number of retrieved icons */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2000-06-13 00:00:11 +02:00
|
|
|
/* end ico file */
|
|
|
|
|
|
|
|
/* exe/dll */
|
|
|
|
else if( sig == IMAGE_NT_SIGNATURE )
|
|
|
|
{
|
|
|
|
LPBYTE idata,igdata;
|
|
|
|
PIMAGE_DOS_HEADER dheader;
|
|
|
|
PIMAGE_NT_HEADERS pe_header;
|
|
|
|
PIMAGE_SECTION_HEADER pe_sections;
|
2000-10-19 22:29:53 +02:00
|
|
|
const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
|
|
|
|
const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
|
2002-12-12 23:59:50 +01:00
|
|
|
UINT i, j;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-13 00:00:11 +02:00
|
|
|
dheader = (PIMAGE_DOS_HEADER)peimage;
|
|
|
|
pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, USER32_GetResourceTable checked that */
|
2002-12-12 23:59:50 +01:00
|
|
|
pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER)
|
|
|
|
+ pe_header->FileHeader.SizeOfOptionalHeader);
|
2000-06-13 00:00:11 +02:00
|
|
|
rootresdir = NULL;
|
|
|
|
|
|
|
|
/* search for the root resource directory */
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
|
|
|
|
continue;
|
2000-10-23 01:45:50 +02:00
|
|
|
if (fsizel < pe_sections[i].PointerToRawData+pe_sections[i].SizeOfRawData) {
|
|
|
|
FIXME("File %s too short (section is at %ld bytes, real size is %ld)\n",
|
|
|
|
debugstr_w(lpszExeFileName),
|
|
|
|
pe_sections[i].PointerToRawData+pe_sections[i].SizeOfRawData,
|
|
|
|
fsizel
|
|
|
|
);
|
|
|
|
goto end;
|
|
|
|
}
|
2001-02-28 06:31:02 +01:00
|
|
|
/* FIXME: doesn't work when the resources are not in a separate section */
|
2002-06-01 01:06:46 +02:00
|
|
|
if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
rootresdir = (PIMAGE_RESOURCE_DIRECTORY)(peimage+pe_sections[i].PointerToRawData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!rootresdir)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("haven't found section for resource directory.\n");
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* search for the group icon directory */
|
2003-09-10 05:56:47 +02:00
|
|
|
if (!(icongroupresdir = find_entry_by_id(rootresdir, LOWORD(RT_GROUP_ICON), rootresdir)))
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("No Icongroupresourcedirectory!\n");
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
|
|
|
|
|
|
|
|
/* only number of icons requested */
|
|
|
|
if( nIcons == 0 )
|
|
|
|
{
|
2002-12-03 22:35:27 +01:00
|
|
|
ret = iconDirCount;
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* success */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( nIconIndex < 0 )
|
|
|
|
{
|
|
|
|
/* search resource id */
|
|
|
|
int n = 0;
|
|
|
|
int iId = abs(nIconIndex);
|
2004-11-30 22:38:57 +01:00
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY* xprdeTmp = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
while(n<iconDirCount && xprdeTmp)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-12-19 04:38:53 +01:00
|
|
|
if(xprdeTmp->u1.s2.Id == iId)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
nIconIndex = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
2002-06-01 01:06:46 +02:00
|
|
|
xprdeTmp++;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
if (nIconIndex < 0)
|
|
|
|
{
|
|
|
|
WARN("resource id %d not found\n", iId);
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check nIconIndex to be in range */
|
2002-06-01 01:06:46 +02:00
|
|
|
if (nIconIndex >= iconDirCount)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assure we don't get too much */
|
|
|
|
if( nIcons > iconDirCount - nIconIndex )
|
|
|
|
nIcons = iconDirCount - nIconIndex;
|
|
|
|
|
|
|
|
/* starting from specified index */
|
2004-11-30 22:38:57 +01:00
|
|
|
xresent = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(icongroupresdir+1) + nIconIndex;
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i=0; i < nIcons; i++,xresent++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-10 20:09:45 +01:00
|
|
|
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
/* go down this resource entry, name */
|
2000-12-20 00:31:52 +01:00
|
|
|
resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s3.OffsetToDirectory));
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
/* default language (0) */
|
2000-10-23 03:35:46 +02:00
|
|
|
resdir = find_entry_default(resdir,rootresdir);
|
2004-11-30 22:38:57 +01:00
|
|
|
igdataent = (const IMAGE_RESOURCE_DATA_ENTRY*)resdir;
|
2000-06-13 00:00:11 +02:00
|
|
|
|
|
|
|
/* lookup address in mapped image for virtual address */
|
|
|
|
igdata = NULL;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|
|
|
continue;
|
|
|
|
if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
2002-12-03 22:35:27 +01:00
|
|
|
continue;
|
2000-10-23 01:45:50 +02:00
|
|
|
|
|
|
|
if (igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData+igdataent->Size > fsizel) {
|
2002-12-03 22:35:27 +01:00
|
|
|
FIXME("overflow in PE lookup (%s has len %ld, have offset %ld), short file?\n", debugstr_w(lpszExeFileName), fsizel,
|
|
|
|
igdataent->OffsetToData - pe_sections[j].VirtualAddress + pe_sections[j].PointerToRawData + igdataent->Size);
|
|
|
|
goto end; /* failure */
|
2000-10-23 01:45:50 +02:00
|
|
|
}
|
2000-06-13 00:00:11 +02:00
|
|
|
igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!igdata)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2000-10-23 01:45:50 +02:00
|
|
|
FIXME("no matching real address for icongroup!\n");
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-10 20:09:45 +01:00
|
|
|
pIconId[i] = LookupIconIdFromDirectoryEx(igdata, TRUE, (i & 1) ? cx2 : cx1, (i & 1) ? cy2 : cy1, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
2003-09-10 05:56:47 +02:00
|
|
|
if (!(iconresdir=find_entry_by_id(rootresdir,LOWORD(RT_ICON),rootresdir)))
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("No Iconresourcedirectory!\n");
|
2000-10-19 22:29:53 +02:00
|
|
|
goto end; /* failure */
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i=0; i<nIcons; i++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-10 20:09:45 +01:00
|
|
|
const IMAGE_RESOURCE_DIRECTORY *xresdir;
|
|
|
|
xresdir = find_entry_by_id(iconresdir, LOWORD(pIconId[i]), rootresdir);
|
2004-07-12 21:53:36 +02:00
|
|
|
if( !xresdir )
|
|
|
|
{
|
|
|
|
WARN("icon entry %d not found\n", LOWORD(pIconId[i]));
|
|
|
|
RetPtr[i]=0;
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-10 20:09:45 +01:00
|
|
|
xresdir = find_entry_default(xresdir, rootresdir);
|
2004-11-30 22:38:57 +01:00
|
|
|
idataent = (const IMAGE_RESOURCE_DATA_ENTRY*)xresdir;
|
2000-06-13 00:00:11 +02:00
|
|
|
idata = NULL;
|
|
|
|
|
|
|
|
/* map virtual to address in image */
|
2002-06-01 01:06:46 +02:00
|
|
|
for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|
|
|
continue;
|
|
|
|
if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|
|
|
continue;
|
|
|
|
idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!idata)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
WARN("no matching real address found for icondata!\n");
|
|
|
|
RetPtr[i]=0;
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-10 20:09:45 +01:00
|
|
|
RetPtr[i] = (HICON) CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,
|
|
|
|
(i & 1) ? cx2 : cx1, (i & 1) ? cy2 : cy1, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2002-12-03 22:35:27 +01:00
|
|
|
ret = i; /* return number of retrieved icons */
|
2000-06-13 00:00:11 +02:00
|
|
|
} /* if(sig == IMAGE_NT_SIGNATURE) */
|
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
end:
|
|
|
|
UnmapViewOfFile(peimage); /* success */
|
|
|
|
return ret;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PrivateExtractIconsW [USER32.@]
|
|
|
|
*
|
|
|
|
* NOTES
|
2002-12-10 20:09:45 +01:00
|
|
|
* If HIWORD(sizeX) && HIWORD(sizeY) 2 * ((nIcons + 1) MOD 2) icons are
|
|
|
|
* returned, with the LOWORD size icon first and the HIWORD size icon
|
|
|
|
* second.
|
|
|
|
* Also the Windows equivalent does extract icons in a strange way if
|
|
|
|
* nIndex is negative. Our implementation treats a negative nIndex as
|
|
|
|
* looking for that resource identifier for the first icon to retrieve.
|
2000-06-13 00:00:11 +02:00
|
|
|
*
|
2002-12-03 22:35:27 +01:00
|
|
|
* FIXME:
|
2002-12-10 20:09:45 +01:00
|
|
|
* should also support 16 bit EXE + DLLs, cursor and animated cursor as
|
|
|
|
* well as bitmap files.
|
2000-06-13 00:00:11 +02:00
|
|
|
*/
|
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT WINAPI PrivateExtractIconsW (
|
2000-06-13 00:00:11 +02:00
|
|
|
LPCWSTR lpwstrFile,
|
|
|
|
int nIndex,
|
2002-12-03 22:35:27 +01:00
|
|
|
int sizeX,
|
|
|
|
int sizeY,
|
2002-12-10 20:09:45 +01:00
|
|
|
HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
|
|
|
|
UINT* pIconId, /* [out] pointer to array of nIcons icon identifiers or NULL */
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT nIcons, /* [in] number of icons to retrieve */
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT flags ) /* [in] LR_* flags used by LoadImage */
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-10 20:09:45 +01:00
|
|
|
TRACE("%s %d %dx%d %p %p %d 0x%08x\n",
|
|
|
|
debugstr_w(lpwstrFile), nIndex, sizeX, sizeY, phicon, pIconId, nIcons, flags);
|
2002-12-03 22:35:27 +01:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
if ((nIcons & 1) && HIWORD(sizeX) && HIWORD(sizeY))
|
|
|
|
{
|
2004-01-27 01:01:43 +01:00
|
|
|
WARN("Uneven number %d of icons requested for small and large icons!\n", nIcons);
|
2002-12-10 20:09:45 +01:00
|
|
|
}
|
|
|
|
return ICO_ExtractIconExW(lpwstrFile, phicon, nIndex, nIcons, sizeX, sizeY, pIconId, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PrivateExtractIconsA [USER32.@]
|
|
|
|
*/
|
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT WINAPI PrivateExtractIconsA (
|
2000-06-13 00:00:11 +02:00
|
|
|
LPCSTR lpstrFile,
|
2002-12-03 22:35:27 +01:00
|
|
|
int nIndex,
|
|
|
|
int sizeX,
|
|
|
|
int sizeY,
|
2002-12-10 20:09:45 +01:00
|
|
|
HICON * phicon, /* [out] pointer to array of nIcons HICON handles */
|
|
|
|
UINT* piconid, /* [out] pointer to array of nIcons icon identifiers or NULL */
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT nIcons, /* [in] number of icons to retrieve */
|
|
|
|
UINT flags ) /* [in] LR_* flags used by LoadImage */
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-03 22:35:27 +01:00
|
|
|
UINT ret;
|
|
|
|
INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
|
|
|
|
LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2002-01-01 01:24:30 +01:00
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
|
|
|
|
ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, piconid, nIcons, flags);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-03 22:35:27 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwstrFile);
|
|
|
|
return ret;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* PrivateExtractIconExW [USER32.@]
|
2000-06-13 00:00:11 +02:00
|
|
|
* NOTES
|
2002-12-10 20:09:45 +01:00
|
|
|
* if nIndex == -1 it returns the number of icons in any case !!!
|
2000-06-13 00:00:11 +02:00
|
|
|
*/
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT WINAPI PrivateExtractIconExW (
|
2000-06-13 00:00:11 +02:00
|
|
|
LPCWSTR lpwstrFile,
|
2002-12-10 20:09:45 +01:00
|
|
|
int nIndex,
|
2000-06-13 00:00:11 +02:00
|
|
|
HICON * phIconLarge,
|
|
|
|
HICON * phIconSmall,
|
|
|
|
UINT nIcons )
|
|
|
|
{
|
|
|
|
DWORD cyicon, cysmicon, cxicon, cxsmicon;
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT ret = 0;
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
TRACE("%s %d %p %p %d\n",
|
2000-06-13 00:00:11 +02:00
|
|
|
debugstr_w(lpwstrFile),nIndex,phIconLarge, phIconSmall, nIcons);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
if (nIndex == -1)
|
|
|
|
/* get the number of icons */
|
|
|
|
return ICO_ExtractIconExW(lpwstrFile, NULL, 0, 0, 0, 0, NULL, LR_DEFAULTCOLOR);
|
|
|
|
|
|
|
|
if (nIcons == 1 && phIconSmall && phIconLarge)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
|
|
|
HICON hIcon[2];
|
|
|
|
cxicon = GetSystemMetrics(SM_CXICON);
|
|
|
|
cyicon = GetSystemMetrics(SM_CYICON);
|
|
|
|
cxsmicon = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
cysmicon = GetSystemMetrics(SM_CYSMICON);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
ret = ICO_ExtractIconExW(lpwstrFile, (HICON*) &hIcon, nIndex, 2, cxicon | (cxsmicon<<16),
|
|
|
|
cyicon | (cysmicon<<16), NULL, LR_DEFAULTCOLOR);
|
2000-06-13 00:00:11 +02:00
|
|
|
*phIconLarge = hIcon[0];
|
|
|
|
*phIconSmall = hIcon[1];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
if (phIconSmall)
|
2000-06-13 00:00:11 +02:00
|
|
|
{
|
2002-12-10 20:09:45 +01:00
|
|
|
/* extract n small icons */
|
|
|
|
cxsmicon = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
cysmicon = GetSystemMetrics(SM_CYSMICON);
|
|
|
|
ret = ICO_ExtractIconExW(lpwstrFile, phIconSmall, nIndex, nIcons, cxsmicon,
|
|
|
|
cysmicon, NULL, LR_DEFAULTCOLOR);
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
2003-03-10 20:04:39 +01:00
|
|
|
if (phIconLarge)
|
2002-12-10 20:09:45 +01:00
|
|
|
{
|
|
|
|
/* extract n large icons */
|
|
|
|
cxicon = GetSystemMetrics(SM_CXICON);
|
|
|
|
cyicon = GetSystemMetrics(SM_CYICON);
|
2003-03-10 20:04:39 +01:00
|
|
|
ret = ICO_ExtractIconExW(lpwstrFile, phIconLarge, nIndex, nIcons, cxicon,
|
2002-12-10 20:09:45 +01:00
|
|
|
cyicon, NULL, LR_DEFAULTCOLOR);
|
|
|
|
}
|
|
|
|
return ret;
|
2000-06-13 00:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* PrivateExtractIconExA [USER32.@]
|
2000-06-13 00:00:11 +02:00
|
|
|
*/
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT WINAPI PrivateExtractIconExA (
|
2000-06-13 00:00:11 +02:00
|
|
|
LPCSTR lpstrFile,
|
2002-12-10 20:09:45 +01:00
|
|
|
int nIndex,
|
2000-06-13 00:00:11 +02:00
|
|
|
HICON * phIconLarge,
|
|
|
|
HICON * phIconSmall,
|
|
|
|
UINT nIcons )
|
|
|
|
{
|
2002-12-10 20:09:45 +01:00
|
|
|
UINT ret;
|
|
|
|
INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
|
|
|
|
LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
TRACE("%s %d %p %p %d\n", lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
|
2000-06-13 00:00:11 +02:00
|
|
|
|
2002-12-10 20:09:45 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
|
|
|
|
ret = PrivateExtractIconExW(lpwstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
|
2000-06-13 00:00:11 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwstrFile);
|
|
|
|
return ret;
|
|
|
|
}
|