CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Location
    Kolkata,India
    Posts
    45

    Red face How to embed a MS Word in a window

    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.

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    Kolkata,India
    Posts
    45

    Re: How to embed a MS Word in a window

    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.

    Quote Originally Posted by yajneshilu
    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.

    Thanks

  3. #3
    Join Date
    Jun 2005
    Location
    Kolkata,India
    Posts
    45

    Re: How to embed a MS Word in a window

    [/QUOTE]
    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.

  4. #4
    Join Date
    Jan 2008
    Posts
    178

    Re: How to embed a MS Word in a window

    It's a Usenet FAQ.
    2 lines of code to embed Word...
    (see win32 api ngs)

  5. #5
    Join Date
    Jun 2005
    Location
    Kolkata,India
    Posts
    45

    Re: How to embed a MS Word in a window

    I have searched a lot. Can you tell what is the exact method name?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured