1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#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 )
// #pragmas are used here to insure that the structure's
// packing in memory matches the packing of the EXE or DLL.
#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
{
BITMAPINFOHEADER icHeader; // DIB header
RGBQUAD icColors[1]; // Color table
BYTE icXOR[1]; // DIB bits for XOR mask
BYTE icAND[1]; // DIB bits for AND mask
} ICONIMAGE, *LPICONIMAGE;
int main(int argc, char* argv[])
{
HMODULE hExe = LoadLibrary("TestRes.exe");
EnumResourceTypes(hExe, (ENUMRESTYPEPROC)ResTypes, 0);
// Find the group resource which lists its images
/* Need to set "IconGrpName" this from ResTypee */
HRSRC hRsrc = FindResource( hExe, MAKEINTRESOURCE(1), RT_GROUP_ICON );
// Load and Lock to get a pointer to a GRPICONDIR
HGLOBAL hGlobal = LoadResource( hExe, hRsrc );
GRPICONDIR *lpIconGroup = new GRPICONDIR[ SizeofResource( hExe, hRsrc ) ];
RtlZeroMemory( lpIconGroup, SizeofResource( hExe, hRsrc ) );
lpIconGroup = (GRPICONDIR*)LockResource( hGlobal );
// We now have the header of the icon file now we need all the icons.
cout << "Icon Count: " << lpIconGroup->idCount << endl;
cout << "Type: " << lpIconGroup->idType << endl;
cout << "idReserved: " << lpIconGroup->idReserved << endl;
for ( unsigned i = 0; i < lpIconGroup->idCount; i++ )
{
cout << "\tEntry ID: " << lpIconGroup->idEntries[i].nID << endl;
cout << "\tEntry Height: " << (int)lpIconGroup->idEntries[i].bHeight << endl;
cout << "\tEntry Height: " << (int)lpIconGroup->idEntries[i].bWidth << endl;
cout << "\tEntry Size: " << lpIconGroup->idEntries[i].dwBytesInRes << endl << endl;
}
vector<ICONIMAGE*> vec_ICONIMAGE;
for ( int i = 0; i < lpIconGroup->idCount; i++ )
{
HRSRC hrSrc = FindResource( hExe, MAKEINTRESOURCE( lpIconGroup->idEntries[0].nID ), RT_ICON );
HGLOBAL hGlobEntry = LoadResource( hExe, hrSrc );
ICONIMAGE *lpIconImage = new ICONIMAGE[ SizeofResource( hExe, hrSrc ) ];
RtlZeroMemory( lpIconImage, SizeofResource( hExe, hrSrc ) );
lpIconImage = (ICONIMAGE*)LockResource( hGlobEntry );
vec_ICONIMAGE.push_back( lpIconImage );
}
system("PAUSE");
return 0;
}
|