S
songjy
Unregistered / Unconfirmed
GUEST, unregistred user!
我编译的时候<br>FRTF: IRichEditOle<br>报错,我安装了RxLib2.75 for Delphi7 ,不知道为什么?<br><br>下面是网络上找到的原代码:<br>兄弟们,多帮忙!<br><br><br><br><br>MSN / QQ 中的动画表情 在Delphi中RichEdit的实现 <br> <br>作者:本站收集 文章来源:互联网 点击数:23 更新时间:2005-5-31 <br> <br>相信用过QQ、MSN中的动画表情对我们的吸引力了吧。在前几天我的一个小应用中需要添加这样的一个功能,首先从网上下载了RXLib2.75(包括RxRichEdit),安装后测试了一下它提供的例子$(DELPHI)/RX/Demo/RICHED2/Richedit.dpr,在使用插入GIF图片时我发现了一个严重的问题:就是GIF图片是不会动的。因为原来对COM这些技术接触较少,只有上网查询资料,首先我去了大富翁www.delphibbs.com查找,不过没有查到,后来终于在网上查到了dtianx大侠的资料(见文章前面的链接),不过我发现他提供的代码是C++下的,于是把这些代码转换了一下,使其在Delphi下也能用。以下是代码<br><br><br>unit Unit1;<br>interface<br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, ActiveX, ComCtrls, RxRichEd, ImageOleLib_TLB;<br>//RxRichEd单元是Rxlib下的RxRichEdit,一套增强功能的RichEdit<br>//ImageOleLib_TLB是从qq的ImageOle.dll引入的类型库<br>const<br> IID_IOleObject: TGUID = (<br> D1: $00000112; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00,<br> $46));<br> EM_GETOLEINTERFACE = WM_USER + 60;<br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Editor: TRxRichEdit;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br>var<br> Form1: TForm1;<br>implementation<br>{$R *.DFM}<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> FRTF: IRichEditOle;<br> FLockBytes: ILockBytes;<br> FStorage: ISTORAGE;<br> FClientSite: IOLECLIENTSITE;<br> m_lpObject: IOleObject;<br> m_lpAnimator: TGifAnimator;<br> i_GifAnimator: IGifAnimator;<br> reobject: TReObject;<br> clsid: TGuid;<br> sizel: tagSize;<br> dwStart, dwEnd: DWORD;<br> Rect:TRect;<br>begin<br>try<br> if CreateILockBytesOnHGlobal(0, True, FLockBytes) <> S_OK then<br> begin<br> showmessage('Error to create Global Heap');<br> exit;<br> end;<br> //建立一个混合文档存取对象<br> if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or<br> STGM_CREATE or STGM_READWRITE, 0, FStorage) <> S_OK then<br> begin<br> Showmessage('Error to create storage');<br> exit;<br> end;<br> //取得RichEdit的接口<br> Sendmessage(Editor.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF));<br><br> if FRTF.GetClientSite(FClientSite)<>S_OK then<br> begin<br> ShowMessage('Error to get ClentSite');<br> Exit;<br> end;<br> CoInitializeEx(nil, COINIT_APARTMENTTHREADED);<br> m_lpAnimator := TGifAnimator.Create(Self);<br> i_GifAnimator := m_lpAnimator.ControlInterface;<br> i_GifAnimator.LoadFromFile('c:/ti.gif');<br> i_GifAnimator.QueryInterface(IID_IOleObject, m_lpObject);<br> OleSetContainedObject(m_lpObject, True);<br> FillChar(ReObject, SizeOf(ReObject), 0);<br> ReObject.cbStruct := SizeOf(ReObject);<br> m_lpObject.GetUserClassID(clsid);<br> ReObject.clsid := clsid;<br> reobject.cp := REO_CP_SELECTION;<br> //content, but not static<br> reobject.dvaspect := DVASPECT_CONTENT;<br> //goes in the same line of text line<br> reobject.dwFlags := REO_BELOWBASELINE; //REO_RESIZABLE |<br> reobject.dwUser := 0;<br> //the very object<br> reobject.poleobj := m_lpObject;<br> //client site contain the object<br> reobject.polesite := FClientSite;<br> //the storage<br> reobject.pstg := FStorage;<br> sizel.cx := 0;<br> sizel.cy := 0;<br> reobject.sizel := sizel;<br> //Sel all text<br> SendMessage(Editor.Handle, EM_SETSEL, 0, -1);<br> SendMessage(Editor.Handle, EM_GETSEL, dwStart, dwEnd);<br> SendMessage(Editor.Handle, EM_SETSEL, dwEnd + 1, dwEnd + 1);<br> //Insert after the line of text<br> FRTF.InsertObject(reobject);<br> SendMessage(Editor.Handle, EM_SCROLLCARET, 0, 0);<br> //VARIANT_BOOL ret;<br> //do frame changing<br> m_lpAnimator.TriggerFrameChange();<br> //show it<br> m_lpObject.DoVerb(OLEIVERB_UIACTIVATE, Nil, FClientSite, 0, Editor.Handle,Rect);<br> // m_lpObject.DoVerb(<br> m_lpObject.DoVerb(OLEIVERB_SHOW, Nil, FClientSite, 0, Editor.Handle, Rect);<br> //redraw the window to show animation<br> redrawwindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ERASENOW or RDW_ALLCHILDREN);<br> finally<br> FRTF:=nil;<br> FClientSite := nil;<br> FStorage :=nil;<br> end;<br>end;<br>end.