This article refers to
http://blog.9cbs.net/dtianx/archive/2004/11/17/184949.aspx
I believe that the animation expressions in QQ, MSN are attractive to us. In a few days ago, I need to add such a feature, first downloading RXLIB2.75 (including rxrichedit) from the Internet. After installation, I have tested the example $ (DELPHI) / RX / DEMO / RICHED2 / Richedit.dpr, I found a serious problem when using the insert GIF picture: the GIF picture is not movable. Because the original contact with COM is less, only the online query information, first of all, I went to the rich
Www.delphibbs.com lookup, but did not find it, and finally I finally found the DTianx heroes in the Internet (see the link in front of the article), but I found that the code he provided was C , so I converted these code. To make it available in Delphi. The following is the code
Unit unit1;
Interface
Uses
Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,
Stdctrls, ActiveX, Comctrls, RxRiched, ImageoLIB_TLB;
// RXRICHED unit is RXRICHEDIT under RXLIB, a set of enhanced Richedit
// ImageOleLib_TLB is the type library introduced from the qq imageole.dll
Const
IID_IOLOBJECT: Tguid =
D1: $ 00000112; D2: $ 0000; D3: $ 0000; D4: ($ C0, $ 00, $ 00, $ 00, $ 00, $ 00, $ 00,
$ 46));
EM_GETOLINTERFACE = 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;
// Establish a mixed document access object
If stegcreatedocfileonilockbytes (flockbytes, str_share_exclusive or
STGM_CREATE OR STGM_READWRITE, 0, FSTORAGE) <> s_ok thenbegin
ShowMessage ('Error to Create Storage');
EXIT;
END;
// Get the interface of Richedit
SendMessage (editor.handle, em_getoleinterface, 0, longint);
If FRTF.GETCLIENTSIENTSIENTSIENTSIENTSIENTSIENTSIENTSITE (FCLIENTSITE) <> S_OK THEN
Begin
ShowMessage ('Error To Get Clentite');
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_IOLOBJECT, 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 return;
// 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, rev);
// redraw the window to show animation
RedRawwindow (Handle, NIL, 0, RDW_ERASE or RDW_INVALIDATE OR RDW_FRAME OR RDW_ERASENOW or RDW_ALLCHILDREN);
Finally
FRTF: = NIL;
FclientSite: = NIL;
FSTORAGE: = NIL;
END;
END;
End.