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