MSN / QQ 中的动画表情 在Delphi中RichEdit的实现 ( 积分: 80 )

  • 主题发起人 主题发起人 songjy
  • 开始时间 开始时间
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>作者:本站收集 &nbsp; &nbsp;文章来源:互联网 &nbsp; &nbsp;点击数:23 &nbsp; &nbsp;更新时间: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> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;StdCtrls, ActiveX, ComCtrls, RxRichEd, ImageOleLib_TLB;<br>//RxRichEd单元是Rxlib下的RxRichEdit,一套增强功能的RichEdit<br>//ImageOleLib_TLB是从qq的ImageOle.dll引入的类型库<br>const<br> &nbsp;IID_IOleObject: TGUID = (<br> &nbsp; &nbsp;D1: $00000112; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00,<br> &nbsp; &nbsp;$46));<br> &nbsp;EM_GETOLEINTERFACE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= WM_USER + 60;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Editor: TRxRichEdit;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br>implementation<br>{$R *.DFM}<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;FRTF: IRichEditOle;<br> &nbsp;FLockBytes: ILockBytes;<br> &nbsp;FStorage: ISTORAGE;<br> &nbsp;FClientSite: IOLECLIENTSITE;<br> &nbsp;m_lpObject: IOleObject;<br> &nbsp;m_lpAnimator: TGifAnimator;<br> &nbsp;i_GifAnimator: IGifAnimator;<br> &nbsp;reobject: TReObject;<br> &nbsp;clsid: TGuid;<br> &nbsp;sizel: tagSize;<br> &nbsp;dwStart, dwEnd: DWORD;<br> &nbsp;Rect:TRect;<br>begin<br>try<br> &nbsp;if CreateILockBytesOnHGlobal(0, True, FLockBytes) &lt;&gt; S_OK then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('Error to create Global Heap');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//建立一个混合文档存取对象<br> &nbsp;if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or<br> &nbsp; &nbsp;STGM_CREATE or STGM_READWRITE, 0, FStorage) &lt;&gt; S_OK then<br> &nbsp;begin<br> &nbsp; &nbsp;Showmessage('Error to create storage');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//取得RichEdit的接口<br> &nbsp;Sendmessage(Editor.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF));<br><br> &nbsp;if FRTF.GetClientSite(FClientSite)&lt;&gt;S_OK then<br> &nbsp; begin<br> &nbsp; ShowMessage('Error to get ClentSite');<br> &nbsp; Exit;<br> &nbsp; end;<br> &nbsp;CoInitializeEx(nil, COINIT_APARTMENTTHREADED);<br> &nbsp;m_lpAnimator := TGifAnimator.Create(Self);<br> &nbsp;i_GifAnimator := m_lpAnimator.ControlInterface;<br> &nbsp;i_GifAnimator.LoadFromFile('c:/ti.gif');<br> &nbsp;i_GifAnimator.QueryInterface(IID_IOleObject, m_lpObject);<br> &nbsp;OleSetContainedObject(m_lpObject, True);<br> &nbsp;FillChar(ReObject, SizeOf(ReObject), 0);<br> &nbsp;ReObject.cbStruct := SizeOf(ReObject);<br> &nbsp;m_lpObject.GetUserClassID(clsid);<br> &nbsp;ReObject.clsid := clsid;<br> &nbsp;reobject.cp := REO_CP_SELECTION;<br> &nbsp;//content, but not static<br> &nbsp;reobject.dvaspect := DVASPECT_CONTENT;<br> &nbsp;//goes in the same line of text line<br> &nbsp;reobject.dwFlags := REO_BELOWBASELINE; //REO_RESIZABLE |<br> &nbsp;reobject.dwUser := 0;<br> &nbsp;//the very object<br> &nbsp;reobject.poleobj := m_lpObject;<br> &nbsp;//client site contain the object<br> &nbsp;reobject.polesite := FClientSite;<br> &nbsp;//the storage<br> &nbsp;reobject.pstg := FStorage;<br> &nbsp;sizel.cx := 0;<br> &nbsp;sizel.cy := 0;<br> &nbsp;reobject.sizel := sizel;<br> &nbsp;//Sel all text<br> &nbsp;SendMessage(Editor.Handle, EM_SETSEL, 0, -1);<br> &nbsp;SendMessage(Editor.Handle, EM_GETSEL, dwStart, dwEnd);<br> &nbsp;SendMessage(Editor.Handle, EM_SETSEL, dwEnd + 1, dwEnd + 1);<br> &nbsp;//Insert after the line of text<br> &nbsp;FRTF.InsertObject(reobject);<br> &nbsp;SendMessage(Editor.Handle, EM_SCROLLCARET, 0, 0);<br> &nbsp;//VARIANT_BOOL ret;<br> &nbsp;//do frame changing<br> &nbsp; m_lpAnimator.TriggerFrameChange();<br> &nbsp;//show it<br> &nbsp;m_lpObject.DoVerb(OLEIVERB_UIACTIVATE, Nil, FClientSite, 0, Editor.Handle,Rect);<br> // m_lpObject.DoVerb(<br> &nbsp;m_lpObject.DoVerb(OLEIVERB_SHOW, Nil, FClientSite, 0, Editor.Handle, Rect);<br> &nbsp;//redraw the window to show animation<br> &nbsp;redrawwindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ERASENOW or RDW_ALLCHILDREN);<br> &nbsp;finally<br> &nbsp;FRTF:=nil;<br> &nbsp;FClientSite := nil;<br> &nbsp;FStorage :=nil;<br> &nbsp;end;<br>end;<br>end.
 
我编译的时候<br>FRTF: IRichEditOle<br>报错,我安装了RxLib2.75 for Delphi7 ,不知道为什么?<br><br>下面是网络上找到的原代码:<br>兄弟们,多帮忙!<br><br><br><br><br>MSN / QQ 中的动画表情 在Delphi中RichEdit的实现 <br> <br>作者:本站收集 &nbsp; &nbsp;文章来源:互联网 &nbsp; &nbsp;点击数:23 &nbsp; &nbsp;更新时间: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> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;StdCtrls, ActiveX, ComCtrls, RxRichEd, ImageOleLib_TLB;<br>//RxRichEd单元是Rxlib下的RxRichEdit,一套增强功能的RichEdit<br>//ImageOleLib_TLB是从qq的ImageOle.dll引入的类型库<br>const<br> &nbsp;IID_IOleObject: TGUID = (<br> &nbsp; &nbsp;D1: $00000112; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00,<br> &nbsp; &nbsp;$46));<br> &nbsp;EM_GETOLEINTERFACE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= WM_USER + 60;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Editor: TRxRichEdit;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br>implementation<br>{$R *.DFM}<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;FRTF: IRichEditOle;<br> &nbsp;FLockBytes: ILockBytes;<br> &nbsp;FStorage: ISTORAGE;<br> &nbsp;FClientSite: IOLECLIENTSITE;<br> &nbsp;m_lpObject: IOleObject;<br> &nbsp;m_lpAnimator: TGifAnimator;<br> &nbsp;i_GifAnimator: IGifAnimator;<br> &nbsp;reobject: TReObject;<br> &nbsp;clsid: TGuid;<br> &nbsp;sizel: tagSize;<br> &nbsp;dwStart, dwEnd: DWORD;<br> &nbsp;Rect:TRect;<br>begin<br>try<br> &nbsp;if CreateILockBytesOnHGlobal(0, True, FLockBytes) &lt;&gt; S_OK then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('Error to create Global Heap');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//建立一个混合文档存取对象<br> &nbsp;if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or<br> &nbsp; &nbsp;STGM_CREATE or STGM_READWRITE, 0, FStorage) &lt;&gt; S_OK then<br> &nbsp;begin<br> &nbsp; &nbsp;Showmessage('Error to create storage');<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//取得RichEdit的接口<br> &nbsp;Sendmessage(Editor.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF));<br><br> &nbsp;if FRTF.GetClientSite(FClientSite)&lt;&gt;S_OK then<br> &nbsp; begin<br> &nbsp; ShowMessage('Error to get ClentSite');<br> &nbsp; Exit;<br> &nbsp; end;<br> &nbsp;CoInitializeEx(nil, COINIT_APARTMENTTHREADED);<br> &nbsp;m_lpAnimator := TGifAnimator.Create(Self);<br> &nbsp;i_GifAnimator := m_lpAnimator.ControlInterface;<br> &nbsp;i_GifAnimator.LoadFromFile('c:/ti.gif');<br> &nbsp;i_GifAnimator.QueryInterface(IID_IOleObject, m_lpObject);<br> &nbsp;OleSetContainedObject(m_lpObject, True);<br> &nbsp;FillChar(ReObject, SizeOf(ReObject), 0);<br> &nbsp;ReObject.cbStruct := SizeOf(ReObject);<br> &nbsp;m_lpObject.GetUserClassID(clsid);<br> &nbsp;ReObject.clsid := clsid;<br> &nbsp;reobject.cp := REO_CP_SELECTION;<br> &nbsp;//content, but not static<br> &nbsp;reobject.dvaspect := DVASPECT_CONTENT;<br> &nbsp;//goes in the same line of text line<br> &nbsp;reobject.dwFlags := REO_BELOWBASELINE; //REO_RESIZABLE |<br> &nbsp;reobject.dwUser := 0;<br> &nbsp;//the very object<br> &nbsp;reobject.poleobj := m_lpObject;<br> &nbsp;//client site contain the object<br> &nbsp;reobject.polesite := FClientSite;<br> &nbsp;//the storage<br> &nbsp;reobject.pstg := FStorage;<br> &nbsp;sizel.cx := 0;<br> &nbsp;sizel.cy := 0;<br> &nbsp;reobject.sizel := sizel;<br> &nbsp;//Sel all text<br> &nbsp;SendMessage(Editor.Handle, EM_SETSEL, 0, -1);<br> &nbsp;SendMessage(Editor.Handle, EM_GETSEL, dwStart, dwEnd);<br> &nbsp;SendMessage(Editor.Handle, EM_SETSEL, dwEnd + 1, dwEnd + 1);<br> &nbsp;//Insert after the line of text<br> &nbsp;FRTF.InsertObject(reobject);<br> &nbsp;SendMessage(Editor.Handle, EM_SCROLLCARET, 0, 0);<br> &nbsp;//VARIANT_BOOL ret;<br> &nbsp;//do frame changing<br> &nbsp; m_lpAnimator.TriggerFrameChange();<br> &nbsp;//show it<br> &nbsp;m_lpObject.DoVerb(OLEIVERB_UIACTIVATE, Nil, FClientSite, 0, Editor.Handle,Rect);<br> // m_lpObject.DoVerb(<br> &nbsp;m_lpObject.DoVerb(OLEIVERB_SHOW, Nil, FClientSite, 0, Editor.Handle, Rect);<br> &nbsp;//redraw the window to show animation<br> &nbsp;redrawwindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ERASENOW or RDW_ALLCHILDREN);<br> &nbsp;finally<br> &nbsp;FRTF:=nil;<br> &nbsp;FClientSite := nil;<br> &nbsp;FStorage :=nil;<br> &nbsp;end;<br>end;<br>end.
 
后退
顶部