WetCode

Resource and Icons

Dec 3rd, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1. // Resources.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <Windows.h>
  7.  
  8. using namespace std;
  9.  
  10. BOOL ResTypes(HMODULE hModule, LPTSTR lpType, LONG lParam);
  11. BOOL ResNames(HMODULE hModule, LPCTSTR lpType, LPTSTR lpName, LONG lParam);
  12.  
  13. #pragma pack( push )
  14. #pragma pack( 2 )
  15. typedef struct
  16. {
  17.    BYTE   bWidth;               // Width, in pixels, of the image
  18.    BYTE   bHeight;              // Height, in pixels, of the image
  19.    BYTE   bColorCount;          // Number of colors in image (0 if >=8bpp)
  20.    BYTE   bReserved;            // Reserved
  21.    WORD   wPlanes;              // Color Planes
  22.    WORD   wBitCount;            // Bits per pixel
  23.    DWORD   dwBytesInRes;         // how many bytes in this resource?
  24.    WORD   nID;                  // the ID
  25. } GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
  26. #pragma pack( pop )
  27.  
  28. typedef struct
  29. {
  30.     BYTE        bWidth;          // Width, in pixels, of the image
  31.     BYTE        bHeight;         // Height, in pixels, of the image
  32.     BYTE        bColorCount;     // Number of colors in image (0 if >=8bpp)
  33.     BYTE        bReserved;       // Reserved ( must be 0)
  34.     WORD        wPlanes;         // Color Planes
  35.     WORD        wBitCount;       // Bits per pixel
  36.     DWORD       dwBytesInRes;    // How many bytes in this resource?
  37.     DWORD       dwImageOffset;   // Where in the file is this image?
  38. } ICONDIRENTRY, *LPICONDIRENTRY;
  39.  
  40. // #pragmas are used here to insure that the structure's
  41. // packing in memory matches the packing of the EXE or DLL.
  42. #pragma pack( push )
  43. #pragma pack( 2 )
  44. typedef struct
  45. {
  46.    WORD            idReserved;   // Reserved (must be 0)
  47.    WORD            idType;       // Resource type (1 for icons)
  48.    WORD            idCount;      // How many images?
  49.    GRPICONDIRENTRY   idEntries[1]; // The entries for each image
  50. } GRPICONDIR, *LPGRPICONDIR;
  51. #pragma pack( pop )
  52.  
  53.  
  54. typedef struct {
  55.     WORD           idReserved;   // Reserved (must be 0)
  56.     WORD           idType;       // Resource Type (1 for icons)
  57.     WORD           idCount;      // How many images?
  58.     ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
  59. } ICONDIR, *LPICONDIR;
  60.  
  61. typedef struct
  62. {
  63.    BITMAPINFOHEADER   icHeader;      // DIB header
  64.    RGBQUAD         icColors[1];   // Color table
  65.    BYTE            icXOR[1];      // DIB bits for XOR mask
  66.    BYTE            icAND[1];      // DIB bits for AND mask
  67. } ICONIMAGE, *LPICONIMAGE;
  68.  
  69. typedef BOOL (CALLBACK *EnumResNameProc)( HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam);
  70.  
  71. int main(int argc, char* argv[])
  72. {
  73.     /*
  74.     // Credit to my friend *** thanks for you elp and explination :)
  75.     HMODULE hExe = LoadLibrary(TEXT("stubpe.exe"));
  76.     EnumResourceTypes(hExe, (ENUMRESTYPEPROC)ResTypes, 0);
  77.     FreeLibrary(hExe)*/
  78.  
  79.     // Find the group resource which lists its images
  80.     HRSRC hRsrc = FindResource( hExe, MAKEINTRESOURCE(1), RT_GROUP_ICON );
  81.     // Load and Lock to get a pointer to a GRPICONDIR
  82.     HGLOBAL hGlobal = LoadResource( hExe, hRsrc );
  83.     GRPICONDIR *lpGrpIconDir = (GRPICONDIR*)LockResource( hGlobal );
  84.  
  85.     // Using an ID from the group, Find, Load and Lock the RT_ICON
  86.  
  87.     hRsrc = FindResource( hExe, MAKEINTRESOURCE( 1 ), RT_ICON );
  88.     hGlobal = LoadResource( hExe, hRsrc );
  89.     ICONIMAGE *lpIconImage = (ICONIMAGE*)LockResource( hGlobal );
  90.     // Here, lpIconImage points to an ICONIMAGE structure
  91.  
  92.  
  93.     system("PAUSE");
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment