如何修改其他文件的图标(100分)

  • 主题发起人 主题发起人 coolfly
  • 开始时间 开始时间
C

coolfly

Unregistered / Unconfirmed
GUEST, unregistred user!
用UpdateResource修改字符串资源可以,可是修改图标资源时总是不成功。<br>网上找的相关代码,替换另一个程序图标的,可被替换程序的图标消失了。。。:(<br>代码如下:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;hExe,hUpdateRes:THandle;<br> &nbsp;hRes,hResLoad:HRSRC;<br> &nbsp;lpResLock:pchar;<br> &nbsp;b:Boolean;<br>begin<br> &nbsp;hExe := LoadLibrary(pchar(opendialog1.FileName));<br> &nbsp;if hExe=0 then begin<br> &nbsp; &nbsp;showmessage('Can''t load notepad!');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br> &nbsp;hRes := FindResource(hExe, 'MAINICON',RT_GROUP_ICON);<br> &nbsp;if hRes=0 then begin<br> &nbsp; &nbsp;showmessage('Can''t load Icon!');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br> &nbsp;hResLoad := LoadResource(hExe, hRes);<br> &nbsp;if hResLoad=0 then begin<br> &nbsp; &nbsp;showmessage('Can''t load !');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br> &nbsp;lpResLock := LockResource(hRes);<br> &nbsp;if lpResLock=nil then begin<br> &nbsp; &nbsp;showmessage('Can''t lock !');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br><br> &nbsp;hUpdateRes := BeginUpdateResource( PChar (opendialog2.FileName), false);<br> &nbsp;if hUpdateRes=0 then begin<br> &nbsp; &nbsp;// 98下运行出现的错误:此功能仅在 Win32 模式下有效。<br> &nbsp; &nbsp;showmessage('Could not open file for writing.');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br> &nbsp;b:= UpdateResource(hUpdateRes, &nbsp; &nbsp; &nbsp; // update resource handle<br> &nbsp; &nbsp; RT_GROUP_ICON,<br> &nbsp; &nbsp; &nbsp;'MAINICON', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// dialog box name<br> &nbsp; &nbsp; 0, &nbsp;// neutral language<br> &nbsp; &nbsp; lpResLock, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ptr to resource info<br> &nbsp; &nbsp; SizeofResource(hExe, hRes)); // size of resource info.<br><br> &nbsp;if not(b) then begin<br> &nbsp; &nbsp;showmessage('Could not add resource.');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br>// Write changes to FOOT.EXE and then close it.<br> &nbsp;if (not(EndUpdateResource(hUpdateRes, FALSE)))<br> &nbsp;then begin<br> &nbsp; &nbsp;showmessage('Could not write changes to file.');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br>// Clean up.<br> &nbsp;if (not(FreeLibrary(hExe)))<br> &nbsp;then &nbsp; showmessage('Could not free executable.');<br><br>end;<br>而且我想用UpdateResource(hUpdateRes,RT_GROUP_ICON,'MAINICON',0,nil,0)删除图标时也不成功。<br>高手指教。。。。。。。。。。谢谢
 
后退
顶部