youpiyoyo
Messages postés
539
Date d'inscription
vendredi 6 juin 2003
Statut
Membre
Dernière intervention
14 juillet 2010
30 juil. 2004 à 10:44
#pragma pack( push )
#pragma pack( 2 )
typedef struct
{
BYTE bWidth; // Width of the image
BYTE bHeight; // Height of the image (times 2)
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
BYTE bReserved; // Reserved
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
DWORD dwBytesInRes; // how many bytes in this resource?
WORD nID; // the ID
} MEMICONDIRENTRY, *LPMEMICONDIRENTRY;
typedef struct
{
WORD idReserved; // Reserved
WORD idType; // resource type (1 for icons)
WORD idCount; // how many images?
MEMICONDIRENTRY idEntries[1]; // the entries for each image
} MEMICONDIR, *LPMEMICONDIR;
#pragma pack( pop )
#pragma pack( push )
#pragma pack( 2 )
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
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
DWORD dwBytesInRes; // how many bytes in this resource?
WORD nID; // the ID
} GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
#pragma pack( pop )
#pragma pack( push )
#pragma pack( 2 )
typedef struct
{
WORD idReserved; // Reserved (must be 0)
WORD idType; // Resource type (1 for icons)
WORD idCount; // How many images?
GRPICONDIRENTRY idEntries[1]; // The entries for each image
} GRPICONDIR, *LPGRPICONDIR;
#pragma pack( pop )
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?
} ICONDIRENTRY, *LPICONDIRENTRY;
typedef struct
{
WORD idReserved; // Reserved (must be 0)
WORD idType; // Resource Type (1 for icons)
WORD idCount; // How many images?
ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
} ICONDIR, *LPICONDIR;
typedef struct
{
UINT Width, Height, Colors; // Width, Height and bpp
LPBYTE lpBits; // ptr to DIB bits
DWORD dwNumBytes; // how many bytes?
LPBITMAPINFO lpbi; // ptr to header
LPBYTE lpXOR; // ptr to XOR image bits
LPBYTE lpAND; // ptr to AND image bits
} ICONIMAGE, *LPICONIMAGE;
typedef struct
{
BOOL bHasChanged; // Has image changed?
TCHAR szOriginalICOFileName[MAX_PATH]; // Original name
TCHAR szOriginalDLLFileName[MAX_PATH]; // Original name
UINT nNumImages; // How many images?
ICONIMAGE IconImages[1]; // Image entries
} ICONRESOURCE, *LPICONRESOURCE;
typedef struct
{
DWORD dwBytes;
DWORD dwOffset;
} RESOURCEPOSINFO, *LPRESOURCEPOSINFO;
// EXE/DLL icon information - filename, instance handle and ID
typedef struct
{
LPCTSTR szFileName;
HINSTANCE hInstance;
LPTSTR lpID;
} EXEDLLICONINFO, *LPEXEDLLICONINFO;
void PutIconToRes(LPCTSTR szFile)
{
LPICONDIR pIconDir;
DWORD uRead,nSize;
LPICONIMAGE pIconImage;
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
pIconDir = (LPICONDIR) malloc( sizeof( ICONDIR ) );
ReadFile( hFile, &(pIconDir->idReserved), sizeof( WORD ), &uRead, NULL );
ReadFile( hFile, &(pIconDir->idType), sizeof( WORD ), &uRead, NULL );
ReadFile( hFile, &(pIconDir->idCount), sizeof( WORD ), &uRead, NULL );
pIconDir = (LPICONDIR)realloc( pIconDir, ( sizeof( WORD ) * 3 ) + ( sizeof( ICONDIRENTRY ) * pIconDir->idCount ) );
ReadFile( hFile, pIconDir->idEntries, pIconDir->idCount * sizeof(ICONDIRENTRY),&uRead, NULL );
// Loop through and read in each image
for(int i=0;iidCount;i++)
{
pIconImage = (LPICONIMAGE)malloc( pIconDir->idEntries[i].dwBytesInRes );
SetFilePointer( hFile, pIconDir->idEntries[i].dwImageOffset,NULL, FILE_BEGIN );
// Read the image data
nSize=pIconDir->idEntries[i].dwBytesInRes;
ReadFile( hFile, pIconImage, pIconDir->idEntries[i].dwBytesInRes,&uRead, NULL );
}
/*char* CurDirz=0;
TCHAR tohBuffer[MAX_PATH];
CurDirz = tohBuffer;
GetModuleFileName(NULL,CurDirz, MAX_PATH);*/
//MessageBox(0,CurDirz,0,0);
HANDLE hUpdateRes = BeginUpdateResource("test resource.exe", FALSE);
if (hUpdateRes == NULL)
{
MessageBox(0,"Could not open file for writing.",0,0);
}
BOOL result = UpdateResource(hUpdateRes,RT_ICON,MAKEINTRESOURCE(104),MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH),
pIconImage,nSize);
if (result == FALSE)
{
MessageBox(0,"Could not add resource.",0,0);
}
if (!EndUpdateResource(hUpdateRes, FALSE))
{
MessageBox(0,"Could not write changes to file.",0,0);
}
//
free( pIconImage );
//
}
tu trouveras tout ici
youpi :)