BOOL CEmbeddedItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize) { if (dwDrawAspect != DVASPECT_CONTENT) return COleServerItem::OnGetExtent(dwDrawAspect, rSize); CClientDC dc(NULL); return OnDrawEx(&dc, rSize, FALSE); }
BOOL CEmbeddedItem::OnDraw(CDC* pDC, CSize& rSize) { return OnDrawEx(pDC, rSize, TRUE); }
BOOL COleServerItem::GetMetafileData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE)); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); ASSERT(lpStgMedium->tymed == TYMED_NULL); // GetDataHere not valid ASSERT(lpStgMedium->pUnkForRelease == NULL); // medium must be TYMED_MFPICT -- cannot fill in existing HGLOBAL if (!(lpFormatEtc->tymed & TYMED_MFPICT) || lpStgMedium->hGlobal != NULL) return FALSE; // create appropriate memory metafile DC CMetaFileDC dc; if (!dc.Create()) return FALSE; // create attribute DC according to lpFormatEtc->ptd HDC hAttribDC = _AfxOleCreateDC(lpFormatEtc->ptd); if (hAttribDC == NULL) return FALSE; dc.SetAttribDC(hAttribDC); // Paint directly into the metafile. CSize size(0, 0); BOOL bResult = OnDrawEx(&dc, (DVASPECT)lpFormatEtc->dwAspect, size); // attribute DC is no longer necessary dc.SetAttribDC(NULL); ::DeleteDC(hAttribDC); if (!bResult) { #ifdef _DEBUG if (afxTraceFlags & traceOle) TRACE0("calling COleServerItem::OnDrawEx()failed.\n"); #endif return FALSE; } HMETAFILE hMF = dc.Close(); if (hMF == NULL) return FALSE; HGLOBAL hPict; if ((hPict = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, sizeof(METAFILEPICT))) == NULL) { DeleteMetaFile(hMF); return FALSE; } LPMETAFILEPICT lpPict; if ((lpPict = (LPMETAFILEPICT)::GlobalLock(hPict)) == NULL) { DeleteMetaFile(hMF); ::GlobalFree(hPict); return FALSE; } // set the metafile size lpPict->mm = MM_ANISOTROPIC; lpPict->hMF = hMF; if (size.cx == 0 && size.cy == 0 && !OnGetExtent((DVASPECT)lpFormatEtc->dwAspect, size)) { TRACE0("Warning: OnGetExtent failed during OnDrawEx --\n"); TRACE0("\tpresentation metafile may be badly formed!\n"); } lpPict->xExt = size.cx; lpPict->yExt = size.cy; // HIMETRIC height if (lpPict->yExt < 0) { TRACE0("Warning: HIMETRIC natural size is negative.\n"); lpPict->yExt = -lpPict->yExt; // backward compatibility fix } #ifdef _DEBUG if (lpPict->xExt == 0 || lpPict->yExt == 0) { // usually the natural extent is set to something interesting TRACE0("Warning: COleServerItem has no natural size --\n"); TRACE0("\twill not work with some apps like MS Write.\n"); } #endif // return the medium with the hGlobal to the METAFILEPICT ::GlobalUnlock(hPict); lpStgMedium->hGlobal = hPict; lpStgMedium->tymed = TYMED_MFPICT; return TRUE; }