#include <oleidl.h>
#include <richedit.h>
#include <richole.h>
//...................
void __fastcall InsertBmpToRich(TRichEdit *re, WideString wstrBmpFile)
{
IRichEditOle *RichOle;
SendMessage(re->Handle, EM_GETOLEINTERFACE, 0, int(&RichOle));
ILockBytes *FLockBytes;
CreateILockBytesOnHGlobal(0,1,&FLockBytes);
IStorage *FStorage;
StgCreateDocfileOnILockBytes(FLockBytes,STGM_SHARE_EXCLUSIVE |
STGM_CREATE | STGM_READWRITE,0,&FStorage);
TFormatEtc FormatEtc;
FormatEtc.cfFormat=0;
FormatEtc.ptd=NULL;
FormatEtc.dwAspect=DVASPECT_CONTENT;
FormatEtc.lindex=-1;
FormatEtc.tymed=TYMED_NULL;
IOleObject *FOle;
OleCreateFromFile(GUID_NULL, wstrBmpFile, ::IID_IOleObject,
0, &FormatEtc, NULL, FStorage, (void**)&FOle);
OleSetContainedObject(FOle, true);
REOBJECT ReObject;
ZeroMemory(&ReObject, sizeof(REOBJECT));
ReObject.cbStruct=sizeof(REOBJECT);
CLSID xt;
FOle->GetUserClassID(&xt);
ReObject.clsid=xt;
ReObject.cp=REO_CP_SELECTION;
ReObject.dvaspect=DVASPECT_CONTENT;
ReObject.dwFlags=REO_STATIC | REO_BELOWBASELINE;
ReObject.dwUser=0;
ReObject.poleobj=FOle;
IOleClientSite *FClientSite;
RichOle->GetClientSite(&FClientSite);
ReObject.polesite=FClientSite;
ReObject.pstg=FStorage;
ReObject.sizel.cx=0;
ReObject.sizel.cy=0;
RichOle->InsertObject(&ReObject);
}
//调用方法:
InsertBmpToRich(RichEdit1, WideString("D:\\source\\Linux_Image\\header-projects.png"));
From:CSDN->happyct(绿叶对大树的情怀)
posted on 2007-05-25 12:31
我风 阅读(3538)
评论(1) 编辑 收藏 引用