Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. COM Container for office file

COM Container for office file

Scheduled Pinned Locked Moved C / C++ / MFC
comc++sysadmindockerquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vishalmore
    wrote on last edited by
    #1

    Hi, All... I am writing a COM container using MFC OLE classes. The purpose of the container is to display and/or print MS Word doc as portion of a bigger display/plot. For this I am trying to get the Enhance Metafile representation of the word doc file using MSWord as COM Server. I have had limited success in the sense that only first page of the document is visible in the metafile. Here is what I have tried: CMyContainerDoc* pDoc = new CMyContainerDoc; //derived from COleDocument CMyCtrlItem* pCtrlItem = new CMyCtrlItem(pDoc); //derived from COleClientItem pCtrlItem->CreateFromFile("mytestfile.doc"); //path and name of a MS word file CSize clientSize; BOOL bRet = pCtrlItem->GetCachedExtent(&clientSize, DVASPECT CONTENT); HDC hDC = ::CreateEnhMetaFile(NULL, "c:\\drawtest.emf", 0, NULL); CDC::FromHandle(hDC)->HIMETRICtoLP(&clientSize); CRect rect( 0, 0, clientSize.cx, clientSize.cy); pCtrlItem->Draw(CDC::FromHandle(hDC), &rect, DVASPECT CONTENT); HENHMETAFILE hMetaFile = CloseEnhMetaFile( hDC ); DeleteEnhMetaFile( hMetaFile); This results in just the first page of document to be represented in the metafile. How could I get the whole document in the metafile? 2. Alternatively, I tried to use GetData function of IDataObject interface . It returns success status code, but when I try to use the metafile handle, returned through STGMEDIUM structure, it still contains only the first page. Here is the relevant code: FORMATETC fmtetc; fmtetc.cfFormat = CF METAFILEPICT; fmtetc.dwAspect = DVASPECT CONTENT; fmtetc.ptd = NULL; fmtetc.tymed = TYMED MFPICT; fmtetc.lindex = -1; STGMEDIUM stgMed; memset(&stgMed, 0, sizeof(stgMed)); LPDATAOBJECT lpDataObject = 0; pCtrlItem->m lpObject->QueryInterface(IID IDataObject, (void**)&lpDataObject); sc = lpDataObject->GetData( &fmtetc, &stgMed ); LPMETAFILEPICT pMF = (LPMETAFILEPICT)GlobalLock(stgMed.hEnhMetaFile); //Draw the picture. HDC hDC2 = ::CreateEnhMetaFile(NULL, "c:\\testGetdata.emf", 0, NULL); BOOL bRetPlay = PlayMetaFile(hDC2, pMF->hMF); GlobalUnlock(stgMed.hEnhMetaFile); ReleaseStgMedium(&stgMed); HENHMETAFILE hMetaFile = CloseEnhMetaFile( hDC2 ); DeleteEnhMetaFile( hMetaFile ); Here again, the metafile testGetData.emf contains just the first page of the document. Is there something I am missing here? Or if there is another better way of achieving the intended results. any suggestion appriciated ! Thanks in Advance Vishal

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups