为什么下面二段改ICON的代码都改不了。<br>我只是想把一个*.ICO写到一个EXE程序里面去,但为什么每次写的时候都写不进去。请教解答。谢谢!<br><br>var<br> Handle: THandle;<br> P: Pointer;<br> FileStrSize: Integer;<br> FileStr, FS: TFileStream;<br>begin<br> FileStr := TFileStream.Create(PChar(Edit1.Text), fmOpenRead);<br> FileStrSize := FileStr.Size;<br> GetMem(P, FileStrSize);<br> FileStr.Read(P^, FileStrSize);<br><br> Handle := BeginUpdateResource(PChar(Edit2.Text), false);<br> UpdateResource(Handle, RT_GROUP_ICON, 'MAINICON', LANG_SPANISH , p, FileStrSize);<br> EndUpdateResource(Handle, false);<br> FreeMem(P, FileStrSize);<br> FileStr.Free;<br>end;<br><br><br>var<br> Ico: TIcon;<br> Stream : TMemoryStream;<br> hInst: THandle;<br> ptr : Pointer;<br>begin<br> Ico:=TIcon.Create;<br> Ico.LoadFromFile(Edit1.Text);<br><br> Stream := TMemoryStream.Create;<br> Ico.SaveToStream(Stream);<br> Ico.Free;<br> getmem(ptr, Stream.size + 1); //函数是用来在堆中分配指定数量的内存的<br> try<br> Stream.Seek(soFromBeginning, 0);<br> Stream.read(ptr^, Stream.size);<br> hInst := BeginUpdateResource(Pchar(Edit2.Text), False);<br> if hInst > 0 then<br> begin<br> UpdateResource(hInst, RT_GROUP_ICON, 'MAINICON', 1031, ptr, Stream.size);<br> EndUpdateResource(hInst, False);<br> end;<br> finally<br> freemem (ptr, Stream.size + 1);<br> stream.Free;<br> end;<br>end;<br><br><br>以下是我又写的一个,但还是不能换*.ico 第当我换的时候程序的ico就没了,我的*.ico文件也没有写上去,请教高手。急。在线等待<br><br>var<br> Icon: TIcon;<br> Handle: THandle;<br> MemStream: TMemoryStream;<br>begin<br> Icon := TIcon.Create;<br> Icon.LoadFromFile(Edit1.Text);<br> MemStream := TMemoryStream.Create;<br> Icon.SaveToStream(MemStream);<br> Icon.Free;<br><br> Handle := BeginUpdateResource(Pchar(Edit2.Text), True);<br> UpdateResource(Handle, RT_ICON, MAKEINTRESOURCE(RT_ICON), 0, @Icon, MemStream.Size);<br> EndUpdateResource(Handle, False);<br> FreeResource(Handle);<br>end;