你看这个资料对你有没有帮助吧<br>这个技巧是参考Delphi的剪贴板类的实现来完成的。将一个流的内容放入剪贴板,<br>首先要注册你自已的格式,使用RegisterClipboardFormat()函数<br>然后做下面三步:<br> 1.创建一个内容流,并将内容写进去<br> 2.创建一个全局的内容区,并将流的内容写入<br> 3.调用ClipBoard.SetAsHandle()将内容写入剪贴板<br><br><br>将内容写入剪贴板中<br>var<br> hbuf : THandle;<br> bufptr : Pointer;<br> mstream : TMemoryStream;<br>begin<br> mstream := TMemoryStream.Create;<br> try<br> {-- 处理流的代码 --}<br> hbuf := GlobalAlloc(GMEM_MOVEABLE, mstream.size);<br> try<br> bufptr := GlobalLock(hbuf);<br> try<br> Move(mstream.Memory^, bufptr^, mstream.size);<br> Clipboard.SetAsHandle(CF_MYFORMAT, hbuf);<br> finally<br> GlobalUnlock(hbuf);<br> end;<br> except<br> GlobalFree(hbuf);<br> raise;<br> end;<br> finally<br> mstream.Free;<br> end;<br>end;<br>请注意不要将分配的全局缓冲区释放,这个工作由剪贴板来完成,在读出数据中<br>你应该将它复制后处理。<br><br>将剪贴板内容读出来<br>var<br> hbuf : THandle;<br> bufptr : Pointer;<br> mstream : TMemoryStream;<br>begin<br> hbuf := Clipboard.GetAsHandle(CF_MYFORMAT);<br> if hbuf <> 0 then begin<br> bufptr := GlobalLock(hbuf);<br> if bufptr <> nil then begin<br> try<br> mstream := TMemoryStream.Create;<br> try<br> mstream.WriteBuffer(bufptr^, GlobalSize(hbuf));<br> mstream.Position := 0;<br> {-- 处理流的代码 --}<br> finally<br> mstream.Free;<br> end;<br> finally<br> GlobalUnlock(hbuf);<br> end;<br> end;<br> end;<br>end;<br>********************************************<br>gototop99 (巴蒂) :怎样拷贝 特殊记录? 200分相送!!!<br>如:拷贝<br> TMyddd=record<br> a1:string;<br> a2:integer;<br> end;<br><br>类型的记录到 剪贴板中,怎么做啊??<br><br>回复人: laihecongxi(兴哥) ( ) 信誉:100 2002-12-02 11:22:00 得分:0 <br> <br> <br> //delphi6测试通过<br>type<br> TMyddd=record<br> a1:string;<br> a2:integer;<br> end;<br>................<br>var <br> Myddd : Tmyddd;<br> pMyddd : ^Tmyddd;<br>procedure .............................<br>var<br> mHnd : Thandle;<br>begin<br> //记录赋值<br> Myddd.a1 := 'AAA';<br> Myddd.a2 := 222;<br> //存数据<br> OurFormat:=RegisterClipboardFormat('CF_TMyddd');<br> if OpenClipboard(Handle) then<br> EmptyClipboard;<br> mHnd := GlobalAlloc(GMEM_DDESHARE or GMEM_MOVEABLE,SizeO(TMyddd));<br> pMyddd := GlobalLock(mHnd);<br> new(pMyddd);<br> pMyddd^.a1 := Myddd.a1;<br> pMyddd^.a2 := Myddd.a2;<br> GlobalUnLock(mHnd);<br> SetClipboardData(OurFormat,mHnd);<br>end;<br><br>var MemberInClip : Thandle;<br>begin //读数据<br> if Clipboard.HasFormat(OurFormat) then begin<br> if OpenClipboard(Handle) then<br> begin<br> MemberInClip:=GetClipboardData(OurFormat);<br> //new(PMyddd);<br> //pMyddd := GlobalLock(MemberInClip);<br> Myddd.a1 := pMyddd^.a1;<br> Myddd.a2 := pMyddd^.a2;<br> GlobalUnLock(MemberInClip);<br> CloseClipboard();<br> with Memo1.Lines do begin<br> Clear;<br> Add('Clipboard has TMember data:');<br> Add(Myddd.a1);<br> Add(inttostr(Myddd.a2));<br> end;<br> end;<br> end; <br>end;<br> <br>