龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC++ 替换 exe 可执行文件的图标

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
替换exe可执行文件的图标: 1、首先取得源资源的指针; 2、利用UpdateResource函数进行替换; void CDlgTest2Dlg::OnBTNUpdateResource() { // TODO: Add your control notification handler code here HMODULE hExe; HANDLE
替换exe可执行文件的图标:
1、首先取得源资源的指针;
2、利用UpdateResource函数进行替换;
 void CDlgTest2Dlg::OnBTNUpdateResource()
{
 // TODO: Add your control notification handler code here
 HMODULE hExe;
 HANDLE hUpdateRes;
 HRSRC hRes;
 HANDLE hResLoad;
 char *lpResLock;
 BOOL result;
 hExe=LoadLibrary("a.exe");
 if (!hExe)
 {
  MessageBox("载入可执行文件失败!");
 }
 hRes=FindResource(hExe,MAKEINTRESOURCE(IDI_ICON1),RT_GROUP_ICON);
 if (!hRes)
 {
  MessageBox("FindResource失败!");
 }
 hResLoad=LoadResource(hExe,hRes);
 if (!hResLoad)
 {
  MessageBox("LoadResource失败!");
 }
 lpResLock=(char*)LockResource(hResLoad);
 if (!lpResLock)
 {
  MessageBox("LockResource失败!");
 }
 hUpdateRes=BeginUpdateResource("switch.exe",FALSE);
 if (!hUpdateRes)
 {
  MessageBox("BeginUpdateResource失败!");
 }
 result=UpdateResource(hUpdateRes,RT_GROUP_ICON,MAKEINTRESOURCE(IDR_MAINFRAME),
  MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),lpResLock,SizeofResource(hExe,hRes));
 if (!result)
 {
  MessageBox("UpdateResource失败!");
 }
 if (!EndUpdateResource(hUpdateRes, FALSE))
 {
  MessageBox("Could not write changes to file.");
 }
 
 // Clean up.
 if (!FreeLibrary(hExe))
 {
  MessageBox("Could not free executable.");
 }
}
精彩图集

赞助商链接