Replace the application EXE icon, the main use of the API function is Beginupdateresource (), Updateresource (), Endupdateresource () to use the custom ICO file class to replace the original icon of the EXE program.
[CPP]View PlainCopy
- The first parameter is the EXE file path that will replace the icon, and the second parameter is the alternate ICO file path
- void Replaceexeico (lpctstr lpszapp, lpctstr lpszico)
- {
- Try
- {
- CFile file (Lpszico, cfile::moderead);
- LONG loffset = 0;
- DWORD dwsize = 0;
- DWORD dwbytes = 0;
- CONST BYTE bgroupicosize = 0x18;
- byte* Lpgroupico = new byte[bgroupicosize];
- memset (Lpgroupico, 0, bgroupicosize);
- File. Read (Lpgroupico, 0x06);
- File. Read (lpgroupico+0x08, 0x0C);
- memcpy (&dwsize, lpgroupico+0x10, sizeof (DWORD));
- File. Read (&loffset, sizeof (Loffset));
- byte* lpres = new byte[dwsize];
- memset (lpres, 0, dwsize);
- File. Seek (Loffset, Cfile::begin);
- File. Read (Lpres, dwsize);
- HANDLE hApp = Beginupdateresource (Lpszapp, NULL);
- Updateresource (hApp, Rt_group_icon, Makeintresource (1), 0, Lpgroupico, bgroupicosize);
- Updateresource (hApp, Rt_icon, Makeintresource (1), 0, Lpres, dwsize);
- Endupdateresource (HAPP, FALSE);
- delete[] lpres;
- delete[] Lpgroupico;
- File. Close ();
- }
- catch (cexception* e)
- {
- E->reporterror ();
- E->delete ();
- }
- }
- The invocation method is simple, such as the following.
- Replaceexeico (_t ("F://11.exe"), _t ("F://11.ico"));
http://blog.csdn.net/visualeleven/article/details/5754831
Replace the application EXE icon, mainly using the Beginupdateresource,updateresource API function