// @pymethod |PyIOleObject|GetUserClassID|Description of GetUserClassID. PyObject *PyIOleObject::GetUserClassID(PyObject *self, PyObject *args) { IOleObject *pIOO = GetI(self); if ( pIOO == NULL ) return NULL; IID pClsid; if ( !PyArg_ParseTuple(args, ":GetUserClassID") ) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIOO->GetUserClassID( &pClsid ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return OleSetOleError(hr); PyObject *obpClsid; obpClsid = PyWinObject_FromIID(pClsid); PyObject *pyretval = Py_BuildValue("O", obpClsid); Py_XDECREF(obpClsid); return pyretval; }
void CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) { SCODE sc; // Get the image data object // CImageDataObject *pods = new CImageDataObject; LPDATAOBJECT lpDataObject; pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject); pods->SetBitmap(hBitmap); // Get the RichEdit container site // IOleClientSite *pOleClientSite; pRichEditOle->GetClientSite(&pOleClientSite); // Initialize a Storage Object // IStorage *pStorage; LPLOCKBYTES lpLockBytes = NULL; sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); lpLockBytes = NULL; AfxThrowOleException(sc); } ASSERT(pStorage != NULL); // The final ole object which will be inserted in the richedit control // IOleObject *pOleObject; pOleObject = pods->GetOleObject(pOleClientSite, pStorage); if(!pOleObject) AfxThrowOleException(sc); // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(pOleObject, TRUE); // Now Add the object to the RichEdit // REOBJECT reobject; ZeroMemory(&reobject, sizeof(REOBJECT)); reobject.cbStruct = 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 = pOleClientSite; reobject.pstg = pStorage; // Insert the bitmap at the current location in the richedit control // pRichEditOle->InsertObject(&reobject); // Release all unnecessary interfaces // pOleObject->Release(); pOleClientSite->Release(); pStorage->Release(); lpDataObject->Release(); }
// returns true on success, false on failure //bool InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap, HGLOBAL hGlobal) bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) { SCODE sc; // Get the image data object // static const FORMATETC lc_format[] = { { CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF }//, // { CF_BITMAP, 0, DVASPECT_CONTENT, -1, TYMED_GDI }, // { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL } }; STGMEDIUM lc_stgmed[] = { { TYMED_ENHMF, { (HBITMAP)hEmf }, 0 }//, // { TYMED_GDI, { hBitmap }, 0 }, // { TYMED_HGLOBAL, { (HBITMAP)hGlobal }, 0 } }; IDataObject *pods; CreateDataObject(lc_format, lc_stgmed, 1, &pods); // Get the RichEdit container site // IOleClientSite *pOleClientSite; pRichEditOle->GetClientSite(&pOleClientSite); // Initialize a Storage Object // LPLOCKBYTES lpLockBytes = NULL; sc = CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) { pOleClientSite->Release(); return false; } IStorage *pStorage; sc = StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); if (sc != S_OK) { lpLockBytes->Release(); pOleClientSite->Release(); return false; } // The final ole object which will be inserted in the richedit control // IOleObject *pOleObject; sc = OleCreateStaticFromData(pods, IID_IOleObject, OLERENDER_FORMAT, (LPFORMATETC)lc_format, pOleClientSite, pStorage, (void **)&pOleObject); if (sc != S_OK) { pStorage->Release(); lpLockBytes->Release(); pOleClientSite->Release(); return false; } // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(pOleObject, TRUE); // Now Add the object to the RichEdit // REOBJECT reobject = { 0 }; reobject.cbStruct = sizeof(REOBJECT); reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.poleobj = pOleObject; reobject.polesite = pOleClientSite; reobject.pstg = pStorage; reobject.dwFlags = REO_BELOWBASELINE; sc = pOleObject->GetUserClassID(&reobject.clsid); if (sc != S_OK) { pOleObject->Release(); pStorage->Release(); lpLockBytes->Release(); pOleClientSite->Release(); return false; } // Insert the bitmap at the current location in the richedit control // sc = pRichEditOle->InsertObject(&reobject); // Release all unnecessary interfaces // pOleObject->Release(); pStorage->Release(); lpLockBytes->Release(); pOleClientSite->Release(); pods->Release(); return sc == S_OK; }
// Static member functions void CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) { LPLOCKBYTES lpLockBytes = NULL; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if(sc != S_OK) { DeleteObject(hBitmap); pRichEditOle->Release(); dcdebug("Thrown OLE Exception: %d\n", sc); return; } dcassert(lpLockBytes != NULL); // Initialize a Storage Object IStorage *pStorage = NULL; sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage); if(sc != S_OK) { DeleteObject(hBitmap); pRichEditOle->Release(); lpLockBytes->Release(); lpLockBytes = NULL; dcdebug("Thrown OLE Exception: %d\n", sc); return; } dcassert(pStorage != NULL); CImageDataObject pods; pods.SetBitmap(hBitmap); // Get the RichEdit container site IOleClientSite *pOleClientSite; pRichEditOle->GetClientSite(&pOleClientSite); // The final ole object which will be inserted in the richedit control IOleObject* pOleObject = pods.GetOleObject(pOleClientSite, pStorage); if(pOleObject != NULL) { // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(pOleObject, TRUE); // Now Add the object to the RichEdit REOBJECT reobject = { 0 }; reobject.cbStruct = sizeof(REOBJECT); CLSID clsid; sc = pOleObject->GetUserClassID(&clsid); if(sc != S_OK) { pRichEditOle->Release(); DeleteObject(hBitmap); dcdebug("Thrown OLE Exception: %d\n", sc); return; } reobject.clsid = clsid; reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.dwFlags = REO_BELOWBASELINE; reobject.poleobj = pOleObject; reobject.polesite = pOleClientSite; reobject.pstg = pStorage; // Insert the bitmap at the current location in the richedit control pRichEditOle->InsertObject(&reobject); // Release all unnecessary interfaces pOleObject->Release(); } pOleClientSite->Release(); lpLockBytes->Release(); pStorage->Release(); pRichEditOle->Release(); DeleteObject(hBitmap); }
// returns true on success, false on failure bool ImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) { BITMAP bminfo; // Get the image data object // ImageDataObject *pods = new ImageDataObject; GetObject(hBitmap, sizeof(bminfo), &bminfo); pods->SetBitmap(hBitmap); // Get the RichEdit container site // IOleClientSite *pOleClientSite; pRichEditOle->GetClientSite(&pOleClientSite); // Initialize a Storage Object // LPLOCKBYTES lpLockBytes = nullptr; SCODE sc = ::CreateILockBytesOnHGlobal(nullptr, TRUE, &lpLockBytes); if (sc != S_OK) { pOleClientSite->Release(); return false; } IStorage *pStorage; sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); if (sc != S_OK) { lpLockBytes = nullptr; pOleClientSite->Release(); return false; } // The final ole object which will be inserted in the richedit control // IOleObject *pOleObject; pOleObject = pods->GetOleObject(pOleClientSite, pStorage); if (pOleObject == nullptr) { pStorage->Release(); pOleClientSite->Release(); return false; } // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(pOleObject, TRUE); // Now Add the object to the RichEdit // REOBJECT reobject; memset(&reobject, 0, sizeof(REOBJECT)); reobject.cbStruct = sizeof(REOBJECT); CLSID clsid; sc = pOleObject->GetUserClassID(&clsid); if (sc != S_OK) { pOleObject->Release(); pStorage->Release(); pOleClientSite->Release(); return false; } reobject.clsid = clsid; reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.poleobj = pOleObject; reobject.polesite = pOleClientSite; reobject.pstg = pStorage; reobject.dwFlags = bminfo.bmHeight <= 12 ? 0 : REO_BELOWBASELINE; // Insert the bitmap at the current location in the richedit control // sc = pRichEditOle->InsertObject(&reobject); // Release all unnecessary interfaces // pOleObject->Release(); pOleClientSite->Release(); lpLockBytes->Release(); pStorage->Release(); return sc == S_OK; }