B
battfly
Unregistered / Unconfirmed
GUEST, unregistred user!
根据 http://www.delphibbs.com/delphibbs/dispq.asp?lid=2914522 文章中的介绍,决定自己采用 TJvGIFAnimator 编写一个Ole组件插入Richedit中。
代码如下:
Activex:
procedure TOleGif.LoadGif(const FileName: WideString);
begin
GifFileName:=FileName;
IF FileExists(GifFileName) Then
Begin
Try
JvGIFAnimator1.Image.LoadFromFile(GifFileName);
Self.Height:=JvGIFAnimator1.Height;
Self.Width :=JvGIFAnimator1.Width;
JvGIFAnimator1.Left:=0;
JvGIFAnimator1.Top:=0;
Self.AutoSize:=TRUE;
JvGIFAnimator1.Animate:=TRUE;
Finally
End;
End;
end;
插入代码如下:
procedure InsertGif(re: TRxRichEdit; sFileName: string; dwUser: integer);
type
tagSize = TSize;
var
FRTF: IRichEditOle;
FLockBytes: ILockBytes;
FStorage: ISTORAGE;
FClientSite: IOLECLIENTSITE;
m_lpObject: IOleObject;
m_lpAnimator: TLive4GGif;
i_GifAnimator: ILive4GGif;
reobject: TReObject;
clsid: TGuid;
sizel: tagSize;
Rect: TRect;
begin
try
if CreateILockBytesOnHGlobal(0, True, FLockBytes) <> S_OK then
begin
exit;
end;
if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or STGM_CREATE or STGM_READWRITE, 0, FStorage) <> S_OK then
begin
exit;
end;
Sendmessage(re.handle, EM_GETOLEINTERFACE, 0, LongInt(@FRTF));
if FRTF.GetClientSite(FClientSite) <> S_OK then
begin
Exit;
end;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
m_lpAnimator := TLive4GGif.Create(re);
i_GifAnimator := m_lpAnimator.ControlInterface;
i_GifAnimator.LoadGif(sFileName);
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;
reobject.dvaspect := DVASPECT_CONTENT;
reobject.dwFlags := REO_BELOWBASELINE;
reobject.dwUser := 0;
reobject.poleobj := m_lpObject;
reobject.polesite := FClientSite;
reobject.pstg := FStorage;
sizel.cx := 0;
sizel.cy := 0;
reobject.sizel := sizel;
re.SelText := '';
re.SelLength := 0;
re.SelStart := re.SelStart;
reobject.dwUser := dwUser;
FRTF.InsertObject(reobject);
SendMessage(re.Handle, EM_SCROLLCARET, 0, 0);
finally
FRTF := nil;
FClientSite := nil;
FStorage := nil;
end;
end;
能正常插入。但GIF 图片不动!!!为什么?
代码如下:
Activex:
procedure TOleGif.LoadGif(const FileName: WideString);
begin
GifFileName:=FileName;
IF FileExists(GifFileName) Then
Begin
Try
JvGIFAnimator1.Image.LoadFromFile(GifFileName);
Self.Height:=JvGIFAnimator1.Height;
Self.Width :=JvGIFAnimator1.Width;
JvGIFAnimator1.Left:=0;
JvGIFAnimator1.Top:=0;
Self.AutoSize:=TRUE;
JvGIFAnimator1.Animate:=TRUE;
Finally
End;
End;
end;
插入代码如下:
procedure InsertGif(re: TRxRichEdit; sFileName: string; dwUser: integer);
type
tagSize = TSize;
var
FRTF: IRichEditOle;
FLockBytes: ILockBytes;
FStorage: ISTORAGE;
FClientSite: IOLECLIENTSITE;
m_lpObject: IOleObject;
m_lpAnimator: TLive4GGif;
i_GifAnimator: ILive4GGif;
reobject: TReObject;
clsid: TGuid;
sizel: tagSize;
Rect: TRect;
begin
try
if CreateILockBytesOnHGlobal(0, True, FLockBytes) <> S_OK then
begin
exit;
end;
if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or STGM_CREATE or STGM_READWRITE, 0, FStorage) <> S_OK then
begin
exit;
end;
Sendmessage(re.handle, EM_GETOLEINTERFACE, 0, LongInt(@FRTF));
if FRTF.GetClientSite(FClientSite) <> S_OK then
begin
Exit;
end;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
m_lpAnimator := TLive4GGif.Create(re);
i_GifAnimator := m_lpAnimator.ControlInterface;
i_GifAnimator.LoadGif(sFileName);
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;
reobject.dvaspect := DVASPECT_CONTENT;
reobject.dwFlags := REO_BELOWBASELINE;
reobject.dwUser := 0;
reobject.poleobj := m_lpObject;
reobject.polesite := FClientSite;
reobject.pstg := FStorage;
sizel.cx := 0;
sizel.cy := 0;
reobject.sizel := sizel;
re.SelText := '';
re.SelLength := 0;
re.SelStart := re.SelStart;
reobject.dwUser := dwUser;
FRTF.InsertObject(reobject);
SendMessage(re.Handle, EM_SCROLLCARET, 0, 0);
finally
FRTF := nil;
FClientSite := nil;
FStorage := nil;
end;
end;
能正常插入。但GIF 图片不动!!!为什么?