Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please help

Please help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nemok
    wrote on last edited by
    #1

    Hi guys, I am developing a program that replaces executables icons with icons from other applications (executables) or from icon files. For now I am using this code in order to do it: HMODULE hLibrary; HRSRC hResource; HGLOBAL hResourceLoaded; LPBYTE lpBuffer; HICON hIcon; int skip=0; hLibrary = LoadLibrary(icon); if((int) ExtractIcon(AfxGetInstanceHandle(), icon, (UINT) -1)) for(unsigned long n=0;n<=1000000;n++) { hResource = FindResource(hLibrary,MAKEINTRESOURCE(n), RT_ICON); if(hResource) if(skip==IconIndex) n=1000001; else skip++; } else MessageBox("The icon file or the first file contains no icon"); if(hResource) { hResourceLoaded = LoadResource(hLibrary,hResource); lpBuffer = (LPBYTE) LockResource(hResourceLoaded); hIcon=CreateIconFromResource((PBYTE)lpBuffer,SizeofResource(hLibrary,hResource),1,0x00030000); HANDLE hUpd=BeginUpdateResource(my_name,0); UpdateResource((HMODULE)hUpd,RT_ICON,MAKEINTRESOURCE(1),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),lpBuffer,SizeofResource(hLibrary,hResource)); EndUpdateResource(hUpd, FALSE); } FreeLibrary(hLibrary); So now I am using LoadLibrary, FindResource, LockResource to extract icon from executable or dll and then I use UpdateResource(...) to write icon to new exe. The problem is that this options does not suport icon files (.ico) and also it doesn't allow the user to extract the specified icon. I am using ExtractIcon() to get icon number. Another way, more efficient and better would be to use ExtractIcon() to get icon form exe, dll or ico file. The problem of this mettod is that ExtractIcon() does not return a pointer to the data to be written by UpdateResource(...) instead it returns a HICON handle. My question is how could I write this HICON handle to the new exe using UpdateResource(...). Itried several different methods but achieved one worked? Please help anyone, this is very important to me. Thanks.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups