chenybin:
请帮忙看看如下代码那里出问题了,根据阁下提供的插入GifAnimator改编,Flash对象是插入了,但却不能正常播放.
procedure RichEditAddFlash(FlashFile:string;Editor:TRxRichEdit);
type
tagSize = TSize;
var
FRTF: IRichEditOle;
FLockBytes: ILockBytes;
FStorage: ISTORAGE;
FClientSite: IOLECLIENTSITE;
m_lpObject: IOleObject;
m_lpFlash: TShockwaveFlash;
i_Flash: IShockwaveFlash;
reobject: TReObject;
clsid: TGUID;
sizel: tagSize;
dwStart, dwEnd: DWORD;
Rect: TRect;
SystemDir
char;
AppDir:string;
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 or STGM_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_OK then
begin
showmessage('Error to get ClentSite');
exit;
end;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
m_lpFlash:= TShockwaveFlash.Create(Application);
i_Flash:= m_lpFlash.ControlInterface;
i_Flash.LoadMovie(0,FlashFile);
i_Flash.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 [red]此处本来为m_lpAnimator.TriggerFrameChange();
但m_lpFlash找不到相应的方法,因此不知用什么方法?[/red]
//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(Editor.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;