1998-11-15 14:25:18 +01:00
|
|
|
/*
|
|
|
|
* shell icon cache (SIC)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
2000-02-10 20:03:02 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
1999-05-22 13:33:23 +02:00
|
|
|
#include "winbase.h"
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
1999-05-22 13:33:23 +02:00
|
|
|
#include "winuser.h"
|
1999-01-01 19:57:33 +01:00
|
|
|
#include "wine/winuser16.h"
|
1999-02-17 14:51:06 +01:00
|
|
|
#include "wine/winbase16.h"
|
1998-11-15 14:25:18 +01:00
|
|
|
#include "neexe.h"
|
|
|
|
#include "cursoricon.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "heap.h"
|
1999-06-12 17:45:58 +02:00
|
|
|
#include "debugtools.h"
|
1999-04-22 12:11:04 +02:00
|
|
|
|
|
|
|
#include "shellapi.h"
|
2000-08-03 06:19:24 +02:00
|
|
|
#include "shlguid.h"
|
1998-11-15 14:25:18 +01:00
|
|
|
#include "pidl.h"
|
|
|
|
#include "shell32_main.h"
|
2000-04-28 22:18:15 +02:00
|
|
|
#include "wine/undocshell.h"
|
|
|
|
#include "shlwapi.h"
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(shell)
|
|
|
|
|
1999-04-25 14:36:53 +02:00
|
|
|
#include "pshpack1.h"
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
1999-04-11 13:50:41 +02:00
|
|
|
WORD idReserved; /* Reserved (must be 0) */
|
|
|
|
WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
|
|
|
|
WORD idCount; /* How many images */
|
1998-11-15 14:25:18 +01:00
|
|
|
icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
|
|
|
|
} icoICONDIR, *LPicoICONDIR;
|
|
|
|
|
1999-04-25 14:36:53 +02:00
|
|
|
#include "poppack.h"
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
#if 0
|
|
|
|
static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
|
|
|
|
{
|
1999-06-12 17:45:58 +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);
|
|
|
|
TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
|
1999-04-11 13:50:41 +02:00
|
|
|
entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
|
|
|
|
}
|
|
|
|
static void dumpIcoDir ( LPicoICONDIR entry )
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
|
1999-04-11 13:50:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
1998-11-15 14:25:18 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* SHELL_GetResourceTable
|
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
static DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr)
|
1998-11-15 14:25:18 +01:00
|
|
|
{ IMAGE_DOS_HEADER mz_header;
|
|
|
|
char magic[4];
|
|
|
|
int size;
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("0x%08x %p\n", hFile, retptr);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
*retptr = NULL;
|
1999-02-26 12:11:13 +01:00
|
|
|
_llseek( hFile, 0, SEEK_SET );
|
|
|
|
if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
|
1998-11-15 14:25:18 +01:00
|
|
|
{ if (mz_header.e_cblp == 1) /* .ICO file ? */
|
|
|
|
{ *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
|
1999-03-13 18:10:36 +01:00
|
|
|
return 1;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* failed */
|
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
_llseek( hFile, mz_header.e_lfanew, SEEK_SET );
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
|
1998-11-15 14:25:18 +01:00
|
|
|
return 0;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
_llseek( hFile, mz_header.e_lfanew, SEEK_SET);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
|
|
|
|
return IMAGE_NT_SIGNATURE;
|
|
|
|
|
|
|
|
if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
|
|
|
|
{ IMAGE_OS2_HEADER ne_header;
|
|
|
|
LPBYTE pTypeInfo = (LPBYTE)-1;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
|
1998-11-15 14:25:18 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
|
|
|
|
return 0;
|
|
|
|
|
2000-04-18 13:58:24 +02:00
|
|
|
size = ne_header.ne_restab - ne_header.ne_rsrctab;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
if( size > sizeof(NE_TYPEINFO) )
|
|
|
|
{ pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
|
|
|
|
if( pTypeInfo )
|
2000-04-18 13:58:24 +02:00
|
|
|
{ _llseek(hFile, mz_header.e_lfanew+ne_header.ne_rsrctab, SEEK_SET);
|
1999-02-26 12:11:13 +01:00
|
|
|
if( _lread( hFile, (char*)pTypeInfo, size) != size )
|
1998-11-15 14:25:18 +01:00
|
|
|
{ HeapFree( GetProcessHeap(), 0, pTypeInfo);
|
|
|
|
pTypeInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*retptr = pTypeInfo;
|
|
|
|
return IMAGE_OS2_SIGNATURE;
|
|
|
|
}
|
1999-03-13 18:10:36 +01:00
|
|
|
return 0; /* failed */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
/*************************************************************************
|
|
|
|
* SHELL_LoadResource
|
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
static BYTE * SHELL_LoadResource( HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
|
1998-11-15 14:25:18 +01:00
|
|
|
{ BYTE* ptr;
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("0x%08x %p 0x%08x\n", hFile, pNInfo, sizeShift);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
*uSize = (DWORD)pNInfo->length << sizeShift;
|
|
|
|
if( (ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
|
1999-02-26 12:11:13 +01:00
|
|
|
{ _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
|
|
|
|
_lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
|
1999-04-11 13:50:41 +02:00
|
|
|
return ptr;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* ICO_LoadIcon
|
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
static BYTE * ICO_LoadIcon( HFILE hFile, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
|
1998-11-15 14:25:18 +01:00
|
|
|
{ BYTE* ptr;
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("0x%08x %p\n", hFile, lpiIDE);
|
1999-04-11 13:50:41 +02:00
|
|
|
|
|
|
|
*uSize = lpiIDE->dwBytesInRes;
|
|
|
|
if( (ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize)) )
|
1999-02-26 12:11:13 +01:00
|
|
|
{ _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
|
|
|
|
_lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
|
1999-04-11 13:50:41 +02:00
|
|
|
return ptr;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* ICO_GetIconDirectory
|
|
|
|
*
|
1999-04-11 13:50:41 +02:00
|
|
|
* Reads .ico file and build phony ICONDIR struct
|
|
|
|
* see http://www.microsoft.com/win32dev/ui/icons.htm
|
1998-11-15 14:25:18 +01:00
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
#define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
|
|
|
|
#define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
|
|
|
|
|
|
|
|
static BYTE * ICO_GetIconDirectory( HFILE hFile, LPicoICONDIR* lplpiID, ULONG *uSize )
|
|
|
|
{ CURSORICONDIR lpcid; /* icon resource in resource-dir format */
|
|
|
|
LPicoICONDIR lpiID; /* icon resource in file format */
|
1998-11-15 14:25:18 +01:00
|
|
|
int i;
|
1999-03-13 18:10:36 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("0x%08x %p\n", hFile, lplpiID);
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
_llseek( hFile, 0, SEEK_SET );
|
1999-04-11 13:50:41 +02:00
|
|
|
if( _lread(hFile,(char*)&lpcid, HEADER_SIZE_FILE) != HEADER_SIZE_FILE )
|
1998-11-15 14:25:18 +01:00
|
|
|
return 0;
|
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
if( lpcid.idReserved || (lpcid.idType != 1) || (!lpcid.idCount) )
|
1998-11-15 14:25:18 +01:00
|
|
|
return 0;
|
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
i = lpcid.idCount * sizeof(icoICONDIRENTRY);
|
|
|
|
lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, HEADER_SIZE_FILE + i);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ CURSORICONDIR * lpID; /* icon resource in resource format */
|
|
|
|
*uSize = lpcid.idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
|
|
|
|
if( (lpID = (CURSORICONDIR*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
|
|
|
|
{
|
|
|
|
/* copy the header */
|
|
|
|
lpID->idReserved = lpiID->idReserved = 0;
|
|
|
|
lpID->idType = lpiID->idType = 1;
|
|
|
|
lpID->idCount = lpiID->idCount = lpcid.idCount;
|
|
|
|
|
|
|
|
/* copy the entrys */
|
1998-11-15 14:25:18 +01:00
|
|
|
for( i=0; i < lpiID->idCount; i++ )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpiID->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
|
|
|
|
lpID->idEntries[i].wResId = i;
|
1999-03-13 18:10:36 +01:00
|
|
|
}
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
*lplpiID = lpiID;
|
1999-04-11 13:50:41 +02:00
|
|
|
return (BYTE *)lpID;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fail */
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpiID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*
|
1999-11-23 23:31:18 +01:00
|
|
|
* returns
|
|
|
|
* failure:0; success: icon handle or nr of icons (nIconIndex-1)
|
1998-11-15 14:25:18 +01:00
|
|
|
*/
|
2000-04-28 22:18:15 +02:00
|
|
|
HICON WINAPI ICO_ExtractIconEx(LPCSTR lpszExeFileName, HICON * RetPtr, INT nIconIndex, UINT n, UINT cxDesired, UINT cyDesired )
|
1999-11-23 23:31:18 +01:00
|
|
|
{ HGLOBAL hRet = 0;
|
1998-11-15 14:25:18 +01:00
|
|
|
LPBYTE pData;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
DWORD sig;
|
1999-02-26 12:11:13 +01:00
|
|
|
HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
|
1998-11-15 14:25:18 +01:00
|
|
|
UINT16 iconDirCount = 0,iconCount = 0;
|
|
|
|
LPBYTE peimage;
|
1999-04-11 13:50:41 +02:00
|
|
|
HANDLE fmapping;
|
|
|
|
ULONG uSize;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(file %s,start %d,extract %d\n", lpszExeFileName, nIconIndex, n);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
2000-01-29 21:59:31 +01:00
|
|
|
if( hFile == HFILE_ERROR || (nIconIndex!=-1 && !n) )
|
1999-11-23 23:31:18 +01:00
|
|
|
return hRet;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
sig = SHELL_GetResourceTable(hFile,&pData);
|
|
|
|
|
|
|
|
/* ico file */
|
|
|
|
if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
|
1999-04-11 13:50:41 +02:00
|
|
|
{ BYTE *pCIDir = 0;
|
|
|
|
NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
|
|
|
|
NE_NAMEINFO *pIconStorage = NULL;
|
|
|
|
NE_NAMEINFO *pIconDir = NULL;
|
1998-11-15 14:25:18 +01:00
|
|
|
LPicoICONDIR lpiID = NULL;
|
1999-03-13 18:10:36 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
if( pData == (BYTE*)-1 )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ pCIDir = ICO_GetIconDirectory(hFile, &lpiID, &uSize); /* check for .ICO file */
|
|
|
|
if( pCIDir )
|
|
|
|
{ iconDirCount = 1; iconCount = lpiID->idCount;
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
|
|
|
|
{ if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
|
|
|
|
{ iconDirCount = pTInfo->count;
|
|
|
|
pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("\tfound directory - %i icon families\n", iconDirCount);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
if( pTInfo->type_id == NE_RSCTYPE_ICON )
|
|
|
|
{ iconCount = pTInfo->count;
|
|
|
|
pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("\ttotal icons - %i\n", iconCount);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
|
|
|
|
{ if( nIconIndex == (UINT16)-1 )
|
|
|
|
{ RetPtr[0] = iconDirCount;
|
|
|
|
}
|
|
|
|
else if( nIconIndex < iconDirCount )
|
|
|
|
{ UINT16 i, icon;
|
|
|
|
if( n > iconDirCount - nIconIndex )
|
|
|
|
n = iconDirCount - nIconIndex;
|
|
|
|
|
|
|
|
for( i = nIconIndex; i < nIconIndex + n; i++ )
|
|
|
|
{ /* .ICO files have only one icon directory */
|
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
if( lpiID == NULL ) /* *.ico */
|
|
|
|
pCIDir = SHELL_LoadResource( hFile, pIconDir + i, *(WORD*)pData, &uSize );
|
1999-05-22 13:33:23 +02:00
|
|
|
RetPtr[i-nIconIndex] = pLookupIconIdFromDirectoryEx( pCIDir, TRUE, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
|
1999-04-11 13:50:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pCIDir);
|
|
|
|
}
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ pCIDir = NULL;
|
1998-11-15 14:25:18 +01:00
|
|
|
if( lpiID )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ pCIDir = ICO_LoadIcon( hFile, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ for( i = 0; i < iconCount; i++ )
|
|
|
|
{ if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
|
1999-04-11 13:50:41 +02:00
|
|
|
{ pCIDir = SHELL_LoadResource( hFile, pIconStorage + i,*(WORD*)pData, &uSize );
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-11 13:50:41 +02:00
|
|
|
if( pCIDir )
|
|
|
|
{ RetPtr[icon-nIconIndex] = (HICON) pCreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ RetPtr[icon-nIconIndex] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( lpiID )
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpiID);
|
|
|
|
else
|
|
|
|
HeapFree( GetProcessHeap(), 0, pData);
|
|
|
|
}
|
|
|
|
/* end ico file */
|
|
|
|
|
|
|
|
/* exe/dll */
|
|
|
|
if( sig == IMAGE_NT_SIGNATURE)
|
|
|
|
{ LPBYTE idata,igdata;
|
|
|
|
PIMAGE_DOS_HEADER dheader;
|
|
|
|
PIMAGE_NT_HEADERS pe_header;
|
|
|
|
PIMAGE_SECTION_HEADER pe_sections;
|
|
|
|
PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
|
|
|
PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
|
|
|
PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
|
|
|
int i,j;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if ( !(fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
|
1998-11-15 14:25:18 +01:00
|
|
|
goto end_2; /* failure */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("failed to mmap filemap.\n");
|
1998-11-15 14:25:18 +01:00
|
|
|
goto end_2; /* failure */
|
|
|
|
}
|
|
|
|
|
|
|
|
dheader = (PIMAGE_DOS_HEADER)peimage;
|
|
|
|
pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, SHELL_GetResourceTable checked that */
|
|
|
|
pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
|
|
|
|
rootresdir = NULL;
|
|
|
|
|
|
|
|
for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
|
|
|
|
{ if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
|
|
|
|
continue;
|
|
|
|
/* FIXME: doesn't work when the resources are not in a seperate section */
|
|
|
|
if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
|
|
|
|
{ rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rootresdir)
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("haven't found section for resource directory.\n");
|
1999-11-23 23:31:18 +01:00
|
|
|
goto end_3; /* failure */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
/* search the group icon dir*/
|
1999-02-26 12:11:13 +01:00
|
|
|
if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE)))
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("No Icongroupresourcedirectory!\n");
|
1999-11-23 23:31:18 +01:00
|
|
|
goto end_3; /* failure */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
|
|
|
|
|
|
|
|
/* number of icons requested */
|
|
|
|
if( nIconIndex == -1 )
|
|
|
|
{ hRet = iconDirCount;
|
|
|
|
goto end_3; /* success */
|
|
|
|
}
|
1999-03-13 18:10:36 +01:00
|
|
|
|
2000-04-28 22:18:15 +02:00
|
|
|
/* (nIconIndex < 0): extract the icon by resource id */
|
|
|
|
if( nIconIndex < 0 )
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
int iId = abs(nIconIndex);
|
|
|
|
PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
|
|
|
|
|
|
|
|
while(n<iconDirCount && xprdeTmp)
|
|
|
|
{
|
|
|
|
if(xprdeTmp->u1.Id == iId)
|
|
|
|
{
|
|
|
|
nIconIndex = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
xprdeTmp++;
|
|
|
|
}
|
|
|
|
if (nIconIndex < 0)
|
|
|
|
{
|
|
|
|
WARN("resource id %d not found\n", iId);
|
|
|
|
goto end_3; /* failure */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check nIconIndex to be in range */
|
1998-11-15 14:25:18 +01:00
|
|
|
if (nIconIndex >= iconDirCount)
|
2000-04-28 22:18:15 +02:00
|
|
|
{
|
|
|
|
WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
1999-11-23 23:31:18 +01:00
|
|
|
goto end_3; /* failure */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); /* caller just wanted the number of entries */
|
|
|
|
|
|
|
|
if( n > iconDirCount - nIconIndex ) /* assure we don't get too much ... */
|
|
|
|
{ n = iconDirCount - nIconIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
xresent = xresent+nIconIndex; /* starting from specified index ... */
|
|
|
|
|
|
|
|
for (i=0;i<n;i++,xresent++)
|
|
|
|
{ PIMAGE_RESOURCE_DIRECTORY resdir;
|
|
|
|
|
|
|
|
/* go down this resource entry, name */
|
|
|
|
resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
|
|
|
|
|
|
|
/* default language (0) */
|
|
|
|
resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|
|
|
igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
|
|
|
|
|
|
|
/* lookup address in mapped image for virtual address */
|
|
|
|
igdata = NULL;
|
|
|
|
|
|
|
|
for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|
|
|
{ if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|
|
|
continue;
|
|
|
|
if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|
|
|
continue;
|
|
|
|
igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!igdata)
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("no matching real address for icongroup!\n");
|
1999-11-23 23:31:18 +01:00
|
|
|
goto end_3; /* failure */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
RetPtr[i] = (HICON)pLookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE)))
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("No Iconresourcedirectory!\n");
|
1999-11-23 23:31:18 +01:00
|
|
|
goto end_3; /* failure */
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0;i<n;i++)
|
|
|
|
{ PIMAGE_RESOURCE_DIRECTORY xresdir;
|
|
|
|
xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
|
|
|
xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|
|
|
idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
|
|
|
idata = NULL;
|
|
|
|
|
|
|
|
/* map virtual to address in image */
|
|
|
|
for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|
|
|
{ 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);
|
|
|
|
}
|
|
|
|
if (!idata)
|
1999-06-12 17:45:58 +02:00
|
|
|
{ WARN("no matching real address found for icondata!\n");
|
1998-11-15 14:25:18 +01:00
|
|
|
RetPtr[i]=0;
|
|
|
|
continue;
|
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
RetPtr[i] = (HICON) pCreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
hRet = RetPtr[0]; /* return first icon */
|
|
|
|
goto end_3; /* sucess */
|
|
|
|
}
|
|
|
|
goto end_1; /* unknown filetype */
|
|
|
|
|
|
|
|
/* cleaning up (try & catch would be nicer:-) ) */
|
|
|
|
end_3: UnmapViewOfFile(peimage); /* success */
|
|
|
|
end_2: CloseHandle(fmapping);
|
1999-02-26 12:11:13 +01:00
|
|
|
end_1: _lclose( hFile);
|
1998-11-15 14:25:18 +01:00
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************** THE ICON CACHE ********************************/
|
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
#define INVALID_INDEX -1
|
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
typedef struct
|
1999-04-11 13:50:41 +02:00
|
|
|
{ LPCSTR sSourceFile; /* file (not path!) containing the icon */
|
|
|
|
DWORD dwSourceIndex; /* index within the file, if it is a resoure ID it will be negated */
|
1998-11-15 14:25:18 +01:00
|
|
|
DWORD dwListIndex; /* index within the iconlist */
|
1999-04-11 13:50:41 +02:00
|
|
|
DWORD dwFlags; /* GIL_* flags */
|
|
|
|
DWORD dwAccessTime;
|
1998-11-15 14:25:18 +01:00
|
|
|
} SIC_ENTRY, * LPSIC_ENTRY;
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
static HDPA sic_hdpa = 0;
|
2000-04-08 23:06:06 +02:00
|
|
|
static CRITICAL_SECTION SHELL32_SicCS = CRITICAL_SECTION_INIT;
|
1999-08-15 16:26:30 +02:00
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
/*****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_CompareEntrys [called by comctl32.dll]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Callback for DPA_Search
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
INT CALLBACK SIC_CompareEntrys( LPVOID p1, LPVOID p2, LPARAM lparam)
|
1999-06-12 17:45:58 +02:00
|
|
|
{ TRACE("%p %p\n", p1, p2);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
if (((LPSIC_ENTRY)p1)->dwSourceIndex != ((LPSIC_ENTRY)p2)->dwSourceIndex) /* first the faster one*/
|
|
|
|
return 1;
|
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
if (strcasecmp(((LPSIC_ENTRY)p1)->sSourceFile,((LPSIC_ENTRY)p2)->sSourceFile))
|
1998-11-15 14:25:18 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_IconAppend [internal]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* appends a icon pair to the end of the cache
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static INT SIC_IconAppend (LPCSTR sSourceFile, INT dwSourceIndex, HICON hSmallIcon, HICON hBigIcon)
|
1998-11-15 14:25:18 +01:00
|
|
|
{ LPSIC_ENTRY lpsice;
|
1999-08-15 16:26:30 +02:00
|
|
|
INT ret, index, index1;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("%s %i %x %x\n", sSourceFile, dwSourceIndex, hSmallIcon ,hBigIcon);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));
|
|
|
|
|
2000-04-28 22:18:15 +02:00
|
|
|
lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFileNameA(sSourceFile));
|
1998-11-15 14:25:18 +01:00
|
|
|
lpsice->dwSourceIndex = dwSourceIndex;
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
EnterCriticalSection(&SHELL32_SicCS);
|
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
|
1998-12-14 18:37:38 +01:00
|
|
|
if ( INVALID_INDEX == index )
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
SHFree(lpsice);
|
|
|
|
ret = INVALID_INDEX;
|
1999-03-13 18:10:36 +01:00
|
|
|
}
|
1999-08-15 16:26:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
index = pImageList_AddIcon (ShellSmallIconList, hSmallIcon);
|
|
|
|
index1= pImageList_AddIcon (ShellBigIconList, hBigIcon);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
if (index!=index1)
|
|
|
|
{
|
|
|
|
FIXME("iconlists out of sync 0x%x 0x%x\n", index, index1);
|
|
|
|
}
|
|
|
|
lpsice->dwListIndex = index;
|
|
|
|
ret = lpsice->dwListIndex;
|
1998-12-14 18:37:38 +01:00
|
|
|
}
|
1999-08-15 16:26:30 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&SHELL32_SicCS);
|
|
|
|
return ret;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
1998-12-14 18:37:38 +01:00
|
|
|
/****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_LoadIcon [internal]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* gets small/big icon by number from a file
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static INT SIC_LoadIcon (LPCSTR sSourceFile, INT dwSourceIndex)
|
|
|
|
{ HICON hiconLarge=0;
|
|
|
|
HICON hiconSmall=0;
|
1998-12-14 18:37:38 +01:00
|
|
|
|
|
|
|
ICO_ExtractIconEx(sSourceFile, &hiconLarge, dwSourceIndex, 1, 32, 32 );
|
|
|
|
ICO_ExtractIconEx(sSourceFile, &hiconSmall, dwSourceIndex, 1, 16, 16 );
|
|
|
|
|
|
|
|
|
|
|
|
if ( !hiconLarge || !hiconSmall)
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
WARN("failure loading icon %i from %s (%x %x)\n", dwSourceIndex, sSourceFile, hiconLarge, hiconSmall);
|
1998-12-14 18:37:38 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return SIC_IconAppend (sSourceFile, dwSourceIndex, hiconSmall, hiconLarge);
|
|
|
|
}
|
1998-11-15 14:25:18 +01:00
|
|
|
/*****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_GetIconIndex [internal]
|
|
|
|
*
|
1999-04-11 13:50:41 +02:00
|
|
|
* Parameters
|
|
|
|
* sSourceFile [IN] filename of file containing the icon
|
|
|
|
* index [IN] index/resID (negated) in this file
|
|
|
|
*
|
1999-03-13 18:10:36 +01:00
|
|
|
* NOTES
|
|
|
|
* look in the cache for a proper icon. if not available the icon is taken
|
|
|
|
* from the file and cached
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
|
1998-12-14 18:37:38 +01:00
|
|
|
{ SIC_ENTRY sice;
|
1999-08-15 16:26:30 +02:00
|
|
|
INT ret, index = INVALID_INDEX;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("%s %i\n", sSourceFile, dwSourceIndex);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
2000-04-28 22:18:15 +02:00
|
|
|
sice.sSourceFile = PathFindFileNameA(sSourceFile);
|
1998-12-14 18:37:38 +01:00
|
|
|
sice.dwSourceIndex = dwSourceIndex;
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
EnterCriticalSection(&SHELL32_SicCS);
|
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
if (NULL != pDPA_GetPtr (sic_hdpa, 0))
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
index = pDPA_Search (sic_hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
|
1998-12-24 15:33:29 +01:00
|
|
|
}
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
if ( INVALID_INDEX == index )
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
ret = SIC_LoadIcon (sSourceFile, dwSourceIndex);
|
1998-12-14 18:37:38 +01:00
|
|
|
}
|
1999-08-15 16:26:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("-- found\n");
|
|
|
|
ret = ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&SHELL32_SicCS);
|
|
|
|
return ret;
|
1998-12-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
/****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_LoadIcon [internal]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* retrives the specified icon from the iconcache. if not found try's to load the icon
|
|
|
|
*/
|
1999-03-18 18:39:57 +01:00
|
|
|
static HICON WINE_UNUSED SIC_GetIcon (LPCSTR sSourceFile, INT dwSourceIndex, BOOL bSmallIcon )
|
1999-02-26 12:11:13 +01:00
|
|
|
{ INT index;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("%s %i\n", sSourceFile, dwSourceIndex);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
index = SIC_GetIconIndex(sSourceFile, dwSourceIndex);
|
1999-08-15 16:26:30 +02:00
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
if (INVALID_INDEX == index)
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
return INVALID_INDEX;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
1998-12-14 18:37:38 +01:00
|
|
|
if (bSmallIcon)
|
|
|
|
return pImageList_GetIcon(ShellSmallIconList, index, ILD_NORMAL);
|
|
|
|
return pImageList_GetIcon(ShellBigIconList, index, ILD_NORMAL);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
/*****************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SIC_Initialize [internal]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* hack to load the resources from the shell32.dll under a different dll name
|
|
|
|
* will be removed when the resource-compiler is ready
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL SIC_Initialize(void)
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
HICON hSm, hLg;
|
1999-02-26 12:11:13 +01:00
|
|
|
UINT index;
|
1999-04-11 13:50:41 +02:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("\n");
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
if (sic_hdpa) /* already initialized?*/
|
1998-11-15 14:25:18 +01:00
|
|
|
return TRUE;
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
sic_hdpa = pDPA_Create(16);
|
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
if (!sic_hdpa)
|
1999-08-15 16:26:30 +02:00
|
|
|
{
|
|
|
|
return(FALSE);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ShellSmallIconList = pImageList_Create(16,16,ILC_COLORDDB | ILC_MASK,0,0x20);
|
|
|
|
ShellBigIconList = pImageList_Create(32,32,ILC_COLORDDB | ILC_MASK,0,0x20);
|
|
|
|
|
1999-07-25 14:21:24 +02:00
|
|
|
pImageList_SetBkColor(ShellSmallIconList, GetSysColor(COLOR_WINDOW));
|
|
|
|
pImageList_SetBkColor(ShellBigIconList, GetSysColor(COLOR_WINDOW));
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
for (index=1; index<39; index++)
|
|
|
|
{
|
|
|
|
hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 16, 16,LR_SHARED);
|
|
|
|
hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 32, 32,LR_SHARED);
|
|
|
|
|
|
|
|
if(!hSm)
|
|
|
|
{
|
|
|
|
hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 16, 16,LR_SHARED);
|
|
|
|
hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 32, 32,LR_SHARED);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
1999-08-15 16:26:30 +02:00
|
|
|
SIC_IconAppend ("shell32.dll", index, hSm, hLg);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList);
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-03-28 14:35:24 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* SIC_Destroy
|
|
|
|
*
|
|
|
|
* frees the cache
|
|
|
|
*/
|
|
|
|
void SIC_Destroy(void)
|
|
|
|
{
|
|
|
|
LPSIC_ENTRY lpsice;
|
|
|
|
int i;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
EnterCriticalSection(&SHELL32_SicCS);
|
|
|
|
|
1999-07-10 13:50:54 +02:00
|
|
|
if (sic_hdpa && NULL != pDPA_GetPtr (sic_hdpa, 0))
|
|
|
|
{
|
|
|
|
for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
|
|
|
|
{
|
|
|
|
lpsice = pDPA_GetPtr(sic_hdpa, i);
|
1999-03-28 14:35:24 +02:00
|
|
|
SHFree(lpsice);
|
|
|
|
}
|
1999-07-10 13:50:54 +02:00
|
|
|
pDPA_Destroy(sic_hdpa);
|
1999-03-28 14:35:24 +02:00
|
|
|
}
|
1999-07-10 13:50:54 +02:00
|
|
|
|
|
|
|
sic_hdpa = NULL;
|
1999-08-15 16:26:30 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&SHELL32_SicCS);
|
2000-02-26 19:47:23 +01:00
|
|
|
DeleteCriticalSection(&SHELL32_SicCS);
|
1999-03-28 14:35:24 +02:00
|
|
|
}
|
1998-11-15 14:25:18 +01:00
|
|
|
/*************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* Shell_GetImageList [SHELL32.71]
|
1998-11-15 14:25:18 +01:00
|
|
|
*
|
|
|
|
* PARAMETERS
|
|
|
|
* imglist[1|2] [OUT] pointer which recive imagelist handles
|
|
|
|
*
|
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
BOOL WINAPI Shell_GetImageList(HIMAGELIST * lpBigList, HIMAGELIST * lpSmallList)
|
1999-06-12 17:45:58 +02:00
|
|
|
{ TRACE("(%p,%p)\n",lpBigList,lpSmallList);
|
1999-01-26 11:37:57 +01:00
|
|
|
if (lpBigList)
|
|
|
|
{ *lpBigList = ShellBigIconList;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
1999-01-26 11:37:57 +01:00
|
|
|
if (lpSmallList)
|
|
|
|
{ *lpSmallList = ShellSmallIconList;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-04-11 13:50:41 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* PidlToSicIndex [INTERNAL]
|
|
|
|
*
|
|
|
|
* PARAMETERS
|
|
|
|
* sh [IN] IShellFolder
|
|
|
|
* pidl [IN]
|
|
|
|
* bBigIcon [IN]
|
2000-02-26 19:47:23 +01:00
|
|
|
* uFlags [IN] GIL_*
|
1999-04-11 13:50:41 +02:00
|
|
|
* pIndex [OUT] index within the SIC
|
|
|
|
*
|
|
|
|
*/
|
2000-02-26 19:47:23 +01:00
|
|
|
BOOL PidlToSicIndex (
|
|
|
|
IShellFolder * sh,
|
|
|
|
LPITEMIDLIST pidl,
|
|
|
|
BOOL bBigIcon,
|
|
|
|
UINT uFlags,
|
|
|
|
UINT * pIndex)
|
1999-04-11 13:50:41 +02:00
|
|
|
{
|
2000-02-26 19:47:23 +01:00
|
|
|
IExtractIconA *ei;
|
1999-04-11 13:50:41 +02:00
|
|
|
char szIconFile[MAX_PATH]; /* file containing the icon */
|
|
|
|
INT iSourceIndex; /* index or resID(negated) in this file */
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
UINT dwFlags = 0;
|
|
|
|
|
2000-02-26 19:47:23 +01:00
|
|
|
TRACE("sf=%p pidl=%p %s\n", sh, pidl, bBigIcon?"Big":"Small");
|
1999-04-22 11:20:01 +02:00
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh, 0, 1, &pidl, &IID_IExtractIconA, 0, (void **)&ei)))
|
|
|
|
{
|
2000-02-26 19:47:23 +01:00
|
|
|
if (SUCCEEDED(IExtractIconA_GetIconLocation(ei, uFlags, szIconFile, MAX_PATH, &iSourceIndex, &dwFlags)))
|
|
|
|
{
|
|
|
|
*pIndex = SIC_GetIconIndex(szIconFile, iSourceIndex);
|
1999-04-22 11:20:01 +02:00
|
|
|
ret = TRUE;
|
1999-04-11 13:50:41 +02:00
|
|
|
}
|
|
|
|
IExtractIconA_Release(ei);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INVALID_INDEX == *pIndex) /* default icon when failed */
|
|
|
|
*pIndex = 1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* SHMapPIDLToSystemImageListIndex [SHELL32.77]
|
1998-11-15 14:25:18 +01:00
|
|
|
*
|
|
|
|
* PARAMETERS
|
1999-04-11 13:50:41 +02:00
|
|
|
* sh [IN] pointer to an instance of IShellFolder
|
|
|
|
* pidl [IN]
|
|
|
|
* pIndex [OUT][OPTIONAL] SIC index for big icon
|
1998-11-15 14:25:18 +01:00
|
|
|
*
|
|
|
|
*/
|
2000-04-28 22:18:15 +02:00
|
|
|
int WINAPI SHMapPIDLToSystemImageListIndex(
|
|
|
|
LPSHELLFOLDER sh,
|
|
|
|
LPCITEMIDLIST pidl,
|
|
|
|
UINT * pIndex)
|
1999-04-11 13:50:41 +02:00
|
|
|
{
|
|
|
|
UINT Index;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-08-15 16:26:30 +02:00
|
|
|
TRACE("(SF=%p,pidl=%p,%p)\n",sh,pidl,pIndex);
|
1998-12-14 18:37:38 +01:00
|
|
|
pdump(pidl);
|
1999-04-11 13:50:41 +02:00
|
|
|
|
|
|
|
if (pIndex)
|
2000-02-26 19:47:23 +01:00
|
|
|
PidlToSicIndex ( sh, pidl, 1, 0, pIndex);
|
|
|
|
PidlToSicIndex ( sh, pidl, 0, 0, &Index);
|
1999-04-11 13:50:41 +02:00
|
|
|
return Index;
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
|
1999-01-03 13:33:08 +01:00
|
|
|
/*************************************************************************
|
1999-03-13 18:10:36 +01:00
|
|
|
* Shell_GetCachedImageIndex [SHELL32.72]
|
1999-01-03 13:33:08 +01:00
|
|
|
*
|
|
|
|
*/
|
1999-04-11 13:50:41 +02:00
|
|
|
INT WINAPI Shell_GetCachedImageIndexA(LPCSTR szPath, INT nIndex, BOOL bSimulateDoc)
|
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath), nIndex, bSimulateDoc);
|
1999-01-03 13:33:08 +01:00
|
|
|
return SIC_GetIconIndex(szPath, nIndex);
|
|
|
|
}
|
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
INT WINAPI Shell_GetCachedImageIndexW(LPCWSTR szPath, INT nIndex, BOOL bSimulateDoc)
|
1999-02-26 12:11:13 +01:00
|
|
|
{ INT ret;
|
1999-04-11 13:50:41 +02:00
|
|
|
LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
|
1999-01-03 13:33:08 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath), nIndex, bSimulateDoc);
|
1999-01-03 13:33:08 +01:00
|
|
|
|
|
|
|
ret = SIC_GetIconIndex(sTemp, nIndex);
|
|
|
|
HeapFree(GetProcessHeap(),0,sTemp);
|
1999-04-11 13:50:41 +02:00
|
|
|
return ret;
|
1999-01-03 13:33:08 +01:00
|
|
|
}
|
|
|
|
|
1999-04-11 13:50:41 +02:00
|
|
|
INT WINAPI Shell_GetCachedImageIndexAW(LPCVOID szPath, INT nIndex, BOOL bSimulateDoc)
|
2000-08-14 16:35:01 +02:00
|
|
|
{ if( SHELL_OsIsUnicode())
|
1999-04-11 13:50:41 +02:00
|
|
|
return Shell_GetCachedImageIndexW(szPath, nIndex, bSimulateDoc);
|
|
|
|
return Shell_GetCachedImageIndexA(szPath, nIndex, bSimulateDoc);
|
1999-01-03 13:33:08 +01:00
|
|
|
}
|
|
|
|
|
1998-11-15 14:25:18 +01:00
|
|
|
/*************************************************************************
|
2000-03-24 21:46:04 +01:00
|
|
|
* ExtractIconEx [shell32.189]
|
1999-03-13 18:10:36 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HICON WINAPI ExtractIconExAW ( LPCVOID lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
2000-08-14 16:35:01 +02:00
|
|
|
{ if (SHELL_OsIsUnicode())
|
1999-02-26 12:11:13 +01:00
|
|
|
return ExtractIconExW ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
|
|
|
return ExtractIconExA ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
/*************************************************************************
|
2000-03-24 21:46:04 +01:00
|
|
|
* ExtractIconExA [shell32.190]
|
1999-03-13 18:10:36 +01:00
|
|
|
* RETURNS
|
|
|
|
* 0 no icon found
|
|
|
|
* 1 file is not valid
|
|
|
|
* HICON handle of a icon (phiconLarge/Small == NULL)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HICON WINAPI ExtractIconExA ( LPCSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
|
|
|
{ HICON ret=0;
|
1998-11-15 14:25:18 +01:00
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons );
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
if (nIconIndex==-1) /* Number of icons requested */
|
|
|
|
return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
|
|
if (phiconLarge)
|
|
|
|
{ ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
|
|
|
|
if ( nIcons==1)
|
|
|
|
{ ret = phiconLarge[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no pointers given and one icon expected, return the handle directly*/
|
|
|
|
if (!phiconLarge && ! phiconSmall && nIcons==1 )
|
|
|
|
phiconSmall = &ret;
|
|
|
|
|
|
|
|
if (phiconSmall)
|
|
|
|
{ ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
|
|
|
|
if ( nIcons==1 )
|
1999-01-17 17:32:32 +01:00
|
|
|
{ ret = phiconSmall[0];
|
1998-11-15 14:25:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/*************************************************************************
|
2000-03-24 21:46:04 +01:00
|
|
|
* ExtractIconExW [shell32.191]
|
1999-03-13 18:10:36 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HICON WINAPI ExtractIconExW ( LPCWSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
1998-11-15 14:25:18 +01:00
|
|
|
{ LPSTR sFile;
|
|
|
|
DWORD ret;
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons );
|
1998-11-15 14:25:18 +01:00
|
|
|
|
|
|
|
sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
|
1999-02-26 12:11:13 +01:00
|
|
|
ret = ExtractIconExA ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
1998-11-15 14:25:18 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,sFile);
|
|
|
|
return ret;
|
|
|
|
}
|