一
一剑飘雪
Unregistered / Unconfirmed
GUEST, unregistred user!
为什么下面二段改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;