1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to embed a MS Word in a window

Discussion in 'C' started by yajneshilu, May 12, 2008.

  1. yajneshilu

    yajneshilu New Member

    Joined:
    May 8, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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.
    Code:
    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 urgent.
    Thanks Yajnesh
     
    Last edited by a moderator: May 12, 2008
  2. yajneshilu

    yajneshilu New Member

    Joined:
    May 8, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 is valuable in this regard.
     

Share This Page