Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to embed a MS Word in a window (http://www.go4expert.com/forums/embed-ms-word-window-t10551/)

yajneshilu 12May2008 14:40

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.
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

yajneshilu 14May2008 15:58

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


All times are GMT +5.5. The time now is 05:25.