Delphi RichEdit的实现MSN / QQ 中的动画表情

unitUnit1;
interface
uses
 
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ActiveX,ComCtrls, RxRichEd,ImageOleLib_TLB;
//RxRichEd单元是Rxlib下的RxRichEdit,一套增强功能的RichEdit
//ImageOleLib_TLB是从qq的ImageOle.dll引入的类型库
const
 
IID_IOleObject: TGUID = (
    D1: $00000112; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00,
    $46));
  EM_GETOLEINTERFACE                  = WM_USER + 60;
type
 
TForm1 = class(TForm)
    Button1: TButton;
    Editor: TRxRichEdit;
    procedure Button1Click(Sender:TObject);
  private
   
{ Private declarations }
 
public
   
{ Public declarations }
 
end;
var
 
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender:TObject);
var
 
FRTF: IRichEditOle;
  FLockBytes: ILockBytes;
  FStorage: ISTORAGE;
  FClientSite: IOLECLIENTSITE;
  m_lpObject: IOleObject;
  m_lpAnimator: TGifAnimator;
  i_GifAnimator: IGifAnimator;
  reobject: TReObject;
  clsid: TGuid;
  sizel: tagSize;
  dwStart, dwEnd:DWORD;
  Rect:TRect;
begin
try
  if
CreateILockBytesOnHGlobal(0,True, FLockBytes) <>S_OK then
  begin
   
showmessage('Error to create Global Heap');
    exit;
  end;
  //建立一个混合文档存取对象
 
if StgCreateDocfileOnILockBytes(FLockBytes,STGM_SHARE_EXCLUSIVE or
   
STGM_CREATE orSTGM_READWRITE, 0, FStorage) <> S_OK then
  begin
   
Showmessage('Error to create storage');
    exit;
  end;
  //取得RichEdit的接口
 
Sendmessage(Editor.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF));

  if FRTF.GetClientSite(FClientSite)<>S_OKthen
   begin
  
ShowMessage('Error to get ClentSite');
   Exit;
   end;
  CoInitializeEx(nil,COINIT_APARTMENTTHREADED);
  m_lpAnimator := TGifAnimator.Create(Self);
  i_GifAnimator := m_lpAnimator.ControlInterface;
  i_GifAnimator.LoadFromFile('c:\ti.gif');
  i_GifAnimator.QueryInterface(IID_IOleObject,m_lpObject);
  OleSetContainedObject(m_lpObject,True);
  FillChar(ReObject,SizeOf(ReObject), 0);
  ReObject.cbStruct:= SizeOf(ReObject);
  m_lpObject.GetUserClassID(clsid);
  ReObject.clsid := clsid;
  reobject.cp := REO_CP_SELECTION;
  //content, but not static
 
reobject.dvaspect:= DVASPECT_CONTENT;
  //goes in the same line of text line
 
reobject.dwFlags:= REO_BELOWBASELINE; //REO_RESIZABLE |
 
reobject.dwUser:= 0;
  //the very object
 
reobject.poleobj:= m_lpObject;
  //client site contain the object
 
reobject.polesite:= FClientSite;
  //the storage
 
reobject.pstg:= FStorage;
  sizel.cx := 0;
  sizel.cy := 0;
  reobject.sizel := sizel;
  //Sel all text
 
SendMessage(Editor.Handle,EM_SETSEL, 0, -1);
  SendMessage(Editor.Handle,EM_GETSEL, dwStart,dwEnd);
  SendMessage(Editor.Handle,EM_SETSEL, dwEnd + 1, dwEnd + 1);
  //Insert after the line of text
 
FRTF.InsertObject(reobject);
  SendMessage(Editor.Handle,EM_SCROLLCARET, 0, 0);
  //VARIANT_BOOL ret;
  //do frame changing
  
m_lpAnimator.TriggerFrameChange();
  //show it
 
m_lpObject.DoVerb(OLEIVERB_UIACTIVATE,Nil, FClientSite, 0, Editor.Handle,Rect);
// m_lpObject.DoVerb(
 
m_lpObject.DoVerb(OLEIVERB_SHOW,Nil, FClientSite, 0, Editor.Handle,Rect);
  //redraw the window to show animation
 
redrawwindow(Handle,nil, 0, RDW_ERASE or RDW_INVALIDATEor RDW_FRAMEor RDW_ERASENOWor RDW_ALLCHILDREN);
  finally
 
FRTF:=nil;
  FClientSite := nil;
  FStorage :=nil;
  end;
end;
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RX Library 2.75 with Delphi 2009 support (by FlexGraphics software) ====================================================================== The Set of Native Delphi Components for Borland Delphi versions 1, 2, 3, 4, 5, 6, 7, 2005, 2006, 2009 and Borland C++ Builder 1, 3, 4, 5, 6, 2006 & 2009. 100% Source Code. Last revision date Oct 12, 1999. PLEASE FOLLOW THE INSTRUCTIONS PROVIDED IN THE INSTALLATION SECTION! TABLE OF CONTENTS ----------------- Latest Changes Overview History License Agreement Installation Demonstration Programs Source Files Using GIF Images Copyright Notes NEW FOR VERSION 2.75 -------------------- Delphi 5.0 & C++Builder 4.0 Compatibility New components: TRxLoginDialog New properties, events: TFormPlacement.RegistryRoot TFormPlacement.Version TFontComboBox.UseFonts TRxDBGrid.OnTopLeftChanged TRxDBLookupCombo.DisplayValues TStrHolder.Macros, TStrHolder.OnExpandMacros RxSpin.TValueType.vtHex New routines, methods, constants: SaveClipboardToStream, LoadClipboardFromStream (clipmon.pas) AppFileName, AppVerInfo (rxverinf.pas) XorString, XorEncode, XorDecode (strutils.pas) BUG FIXES. Overview -------- This version is the result of long unactivity of RX Library authors and some imperfections and bugs of other RX adaptations to Delphi 6. The authors of this version disclaim all warranties as to this software, whether express or implied, including without limitation any implied warranties of merchantability or fitness for a particular purpose. Use under your own responsibility, but comments (even critique) in English (or in Russian) are welcome. RX Library contains a large number of components, objects and routines for Borland Delphi with full source code. This library is compatible with Borland Delphi 1, 2, 3, 4, 5, 6 and Borland C++ Builder 1, 3, 4. This collection includes over 60 native Delphi components. RX Library is a freeware product. Feel free to distribute the library as long as all files are unmodified and kep
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值