我用的是VC8,使用WIN32API。平时建工程都是空模板,自己添加一些常用头文件如windows.h tchar.h等。不知使用下面代码需要添加什么头文件,引用什么链接库,或还需要加载什么DLL ?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"));//或者用RichView
{
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"));//或者用RichView
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货