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. How to embed a MS Word in a window

How to embed a MS Word in a window

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomdockerhardwaretutorial
6 Posts 2 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.
  • Y Offline
    Y Offline
    Yajnesh Narayan Behera
    wrote on last edited by
    #1

    Hi in my project there is a window where I have to embed a word application using OLE. It is fine for Internet explorer, but for Word rather embedding it is opening as a separate application. One thing if I use IWebBrowser2 to achieve it is fine, but there is a problem relating to history so I am trying to do it in this way. The flow is as follows: The syntax is based on plain C. CLSID idMsWord; HRESULT hr; IStorage *pStorage; IOleObject *browserObject; _IOleClientSiteEx *_iOleClientSiteEx; hr = CLSIDFromProgID(L"word.document", &idMsWord); hr = StgCreateStorageEx(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT | STGM_CREATE, STGFMT_DOCFILE, 0, NULL, 0, &IID_IStorage, (LPVOID*) &pStorage); if (!OleCreate(&idMsWord, &IID_IOleObject, OLERENDER_DRAW, 0, (IOleClientSite *)_iOleClientSiteEx, (void**)pStorage, (void**)&browserObject)) { GetClientRect(hwnd, &rect); rect = *R; // Let word object know that it is embedded in an OLE container. if (!OleSetContainedObject((struct IUnknown *)browserObject, TRUE)) { browserObject->lpVtbl->DoVerb(browserObject, OLEIVERB_INPLACEACTIVATE, NULL, (IOleClientSite *)_iOleClientSiteEx, -1, hwnd, &rect); browserObject->lpVtbl->Release(browserObject); } } _IOleClientSiteEx is the structure which holds IOleClientsite. Now when DoVerb is beieng executed a new word application is being opened as a separate application rather as an embedded one. Please help to resolve this issue as it is related to my project.

    R 1 Reply Last reply
    0
    • Y Yajnesh Narayan Behera

      Hi in my project there is a window where I have to embed a word application using OLE. It is fine for Internet explorer, but for Word rather embedding it is opening as a separate application. One thing if I use IWebBrowser2 to achieve it is fine, but there is a problem relating to history so I am trying to do it in this way. The flow is as follows: The syntax is based on plain C. CLSID idMsWord; HRESULT hr; IStorage *pStorage; IOleObject *browserObject; _IOleClientSiteEx *_iOleClientSiteEx; hr = CLSIDFromProgID(L"word.document", &idMsWord); hr = StgCreateStorageEx(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT | STGM_CREATE, STGFMT_DOCFILE, 0, NULL, 0, &IID_IStorage, (LPVOID*) &pStorage); if (!OleCreate(&idMsWord, &IID_IOleObject, OLERENDER_DRAW, 0, (IOleClientSite *)_iOleClientSiteEx, (void**)pStorage, (void**)&browserObject)) { GetClientRect(hwnd, &rect); rect = *R; // Let word object know that it is embedded in an OLE container. if (!OleSetContainedObject((struct IUnknown *)browserObject, TRUE)) { browserObject->lpVtbl->DoVerb(browserObject, OLEIVERB_INPLACEACTIVATE, NULL, (IOleClientSite *)_iOleClientSiteEx, -1, hwnd, &rect); browserObject->lpVtbl->Release(browserObject); } } _IOleClientSiteEx is the structure which holds IOleClientsite. Now when DoVerb is beieng executed a new word application is being opened as a separate application rather as an embedded one. Please help to resolve this issue as it is related to my project.

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Here is an example, if that might help: Using MS Office in an MFC application[^]

      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

      Y 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Here is an example, if that might help: Using MS Office in an MFC application[^]

        Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

        Y Offline
        Y Offline
        Yajnesh Narayan Behera
        wrote on last edited by
        #3

        Thanks As you look at my code there is no use of MFC class. So I have to achieve this without MFC class.

        R 1 Reply Last reply
        0
        • Y Yajnesh Narayan Behera

          Thanks As you look at my code there is no use of MFC class. So I have to achieve this without MFC class.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Yajnesh Naraya Behera wrote:

          So I have to achieve this without MFC class.

          That must be a real pain. Good luck. :)

          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

          Y 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            Yajnesh Naraya Behera wrote:

            So I have to achieve this without MFC class.

            That must be a real pain. Good luck. :)

            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

            Y Offline
            Y Offline
            Yajnesh Narayan Behera
            wrote on last edited by
            #5

            Yap it is really. Now I got some concept, I have to implement an OLECONTAINER to host MS Word, again from where I will get the interfaces for Word. In other way I can use all the proeprties & methods of MS Word using IDispatch, but what about other interfaces IOleClientSite, IOleInPlaceFrame. All your sugestions valuable in this regard.

            R 1 Reply Last reply
            0
            • Y Yajnesh Narayan Behera

              Yap it is really. Now I got some concept, I have to implement an OLECONTAINER to host MS Word, again from where I will get the interfaces for Word. In other way I can use all the proeprties & methods of MS Word using IDispatch, but what about other interfaces IOleClientSite, IOleInPlaceFrame. All your sugestions valuable in this regard.

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              This thread is pretty much buried now. You may want to start a new thread, explaining your problem. :)

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              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