欢迎来到天天文库
浏览记录
ID:50829906
大小:31.37 KB
页数:2页
时间:2020-03-15
《ritchdeit中插入图片代码.docx》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、void InsertBitmap(CRichEditCtrl *pRichEdit, HBITMAP hBitmap)//底层的一个InsertBitmap{STGMEDIUM stgm;stgm.tymed = TYMED_GDI; // Storage medium = HBITMAP handlestgm.hBitmap = hBitmap;stgm.pUnkForRelease = NULL; // Use ReleaseStgMediumFORMATETC fm;fm.cfFormat = CF_BITMAP; // Clipboard format = CF_B
2、ITMAPfm.ptd = NULL; // Target Device = Screenfm.dwAspect = DVASPECT_CONTENT; // Level of detail = Full contentfm.lindex = -1; // Index = Not applicaplefm.tymed = TYMED_GDI; //创建输入数据源IStorage *pStorage; //分配内存LPLOCKBYTES lpLockBytes = NULL;SCODE sc = ::CreateILockBytesOnHGlobal(NULL
3、, TRUE, &lpLockBytes);if (sc != S_OK)AfxThrowOleException(sc);ASSERT(lpLockBytes != NULL);sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,STGM_SHARE_EXCLUSIVE
4、STGM_CREATE
5、STGM_READWRITE, 0, &pStorage);if (sc != S_OK){VERIFY(lpLockBytes->Release() == 0);lpLockBytes = NULL;AfxThrowOleException(sc);
6、}ASSERT(pStorage != NULL);COleDataSource *pDataSource = new COleDataSource;pDataSource->CacheData(CF_BITMAP, &stgm);LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pDataSource->GetInterface(&IID_IDataObject);//获取RichEdit的OLEClientSiteLPOLECLIENTSITE lpClientSite;pRichEdit->GetIRichEditOle()->GetClientS
7、ite( &lpClientSite );//创建OLE对象IOleObject *pOleObject;sc = OleCreateStaticFromData(lpDataObject,IID_IOleObject,OLERENDER_FORMAT,&fm,lpClientSite,pStorage,(void **)&pOleObject);if(sc!=S_OK)AfxThrowOleException(sc);//插入OLE对象REOBJECT reobject;ZeroMemory(&reobject, sizeof(REOBJECT));reobject.cbStruct
8、= sizeof(REOBJECT);CLSID clsid;sc = pOleObject->GetUserClassID(&clsid);if (sc != S_OK)AfxThrowOleException(sc);reobject.clsid = clsid;reobject.cp = REO_CP_SELECTION;reobject.dvaspect = DVASPECT_CONTENT;reobject.poleobj = pOleObject;reobject.polesite = lpClientSite;reobject.pstg = pStorage;HRESULT
9、 hr = pRichEdit->GetIRichEditOle()->InsertObject( &reobject );delete pDataSource;}
此文档下载收益归作者所有