Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4604596
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: C/C++

2007-03-10 10:19:49

替换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.");
 }
}
 
阅读(3031) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~