C
cooldren
Unregistered / Unconfirmed
GUEST, unregistred user!
function ReplaceMediaRes2(SrcFileName:String;MediaFileName:String):Boolean;var bitmap:TBitmap; MM:TMemorystream; bufferChar; hUpdateRes:THandle;begin result:=false; if not FileExists(SrcFileName) then begin MessageBox(Application.Handle,pchar('打开文件:'+SrcFileName+'出错'),pchar(Application.Title),MB_ICONERROR); exit; end; if not (FileExists(MediaFileName)) then begin MessageBox(Application.Handle,pchar('打开文件:'+MediaFileName+'出错'),pchar(Application.Title),MB_ICONERROR); exit; end; MM:=TMemorystream.Create; bitmap:=TBitmap.Create; bitmap.LoadFromFile(MediaFileName); bitmap.SaveToStream(MM); MM.Position:=0; try GetMem(buffer,MM.Size-0); try mm.ReadBuffer(buffer^,MM.Size-0); //开始更新资源 hUpdateRes:=BeginUpdateResource(pchar(SrcFileName),false); if(hUpdateRes=0) then begin MessageBox(Application.Handle,pchar('开始修改资源出现异常.'),pchar(Application.Title),MB_ICONERROR); exit; end; result:=UpdateResource(hUpdateRes,RT_BITMAP,MAKEINTRESOURCE(1),2052,buffer,MM.Size-0); if not result then begin MessageBox(Application.Handle,pchar('修改资源出现异常。'),pchar(Application.Title),MB_ICONERROR); exit; end; if not EndUpdateResource(hUpdateRes,false) then begin MessageBox(Application.Handle,pchar('修改资源结束出现异常.'),pchar(Application.Title),MB_ICONERROR); exit; end; finally FreeMem(buffer); end; finally mm.Free; end; result:=true; end;修改后的位图在exeScope中都不能打开,提示“当扩展内存流时内存不足”请指点谢谢