修改EXE文件的图标

 修改EXE文件的图片可以参考如下代码: 

#include <windows.h>

  BOOL CALLBACK DeleteExistingIcons(  
  HMODULE hModule,     
  LPCTSTR lpszType,   
  LPTSTR lpszName,     
  LONG lParam);
   
  BOOL CALLBACK UpdateIcons(  
  HMODULE hModule,   
  LPCTSTR lpszType,   
  LPTSTR lpszName,   
  LONG lParam);
   
  void IconExchange(LPSTR lpSrcExe , LPSTR lpDestExe, LPSTR lpOutExe );
   
   

void main(int argc, char *argv[])
{
     
    IconExchange(argv[1] , argv[2] , argv[3]);
     
}

BOOL CALLBACK DeleteExistingIcons(  
  HMODULE hModule,     
  LPCTSTR lpszType,   
  LPTSTR lpszName,     
  LONG lParam)
  {
       HANDLE hUpdate = (HANDLE)lParam;
        
  UpdateResource(hUpdate,lpszType,lpszName,MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,0);  
  return 1;
}

BOOL CALLBACK UpdateIcons(  
  HMODULE hModule,   
  LPCTSTR lpszType,   
  LPTSTR lpszName,   
  LONG lParam)        
{  
  HANDLE hUpdate  = (HANDLE)lParam;   
  HRSRC hRes =  FindResource(hModule,lpszName,lpszType);
  HGLOBAL hResLoaded =  LoadResource(hModule, hRes);  
  void* pData =  LockResource(hResLoaded);  
  int nSizeOfIconRes = SizeofResource(hModule,hRes);  
   

UpdateResource(hUpdate,lpszType,lpszName,MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),pData,nSizeOfIconRes);  


  UnlockResource(hResLoaded);  
  FreeResource(hResLoaded);  


  return TRUE;  


}

void IconExchange(LPSTR lpSrcExe , LPSTR lpDestExe ,LPSTR lpOutExe)
{
     CopyFile(lpDestExe , lpOutExe , FALSE);
      
     HANDLE  hUpdate = BeginUpdateResource(lpOutExe,FALSE);
           
     HMODULE hOldExe = LoadLibraryEx(lpDestExe ,NULL,LOAD_LIBRARY_AS_DATAFILE);  
      
     EnumResourceNames(hOldExe,RT_ICON,DeleteExistingIcons,(long)hUpdate);  
      
     EnumResourceNames(hOldExe,RT_GROUP_ICON,DeleteExistingIcons,(long)hUpdate);  
      
     FreeLibrary(hOldExe);
      
     HMODULE hIconSrcExe = LoadLibraryEx(lpSrcExe ,NULL,LOAD_LIBRARY_AS_DATAFILE);
      
     EnumResourceNames(hIconSrcExe,RT_ICON,UpdateIcons,(long)hUpdate);  
      
     EnumResourceNames(hIconSrcExe,RT_GROUP_ICON,UpdateIcons,(long)hUpdate);
      
     FreeLibrary(hIconSrcExe);
      
     EndUpdateResource(hUpdate,FALSE);
      
     } 

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享