none
OLE Container not displaying on the window

    Question

  • Hi i am trying to embed browser object inside a window using OLE automation in simple C++ without atl/mfc frameworks.

    class AContainer : public CBaseComObject, public IOleClientSite, public IOleInPlaceFrame, public IOleInPlaceSite, public IOleControlSite
    {
    };
    

    I have declared all the methods of these interfaces and implemented addref release and queryinterface. Right now I have defined other interfaces also but they return E_NOTIMPL. I will implement them when required.

    Now when I try to display a simple browser web page inside this container IOleObject::DoVerb method returns E_FAIL instead of S_OK. Can anyone tell me what is the problem with my code. Thanks in advance.

    AContainer *obj = new AContainer();
    LPCLASSFACTORY		pClassFactory;
    IOleObject			*browserObject;
    IWebBrowser2		*webBrowser2;
    RECT				rect;
    
    pClassFactory = 0;
    if (OleInitialize(NULL) == S_OK)
    {
    	if (!CoGetClassObject(CLSID_WebBrowser, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, NULL, IID_IClassFactory, (void **)&pClassFactory) && pClassFactory)
    	{
    		
    	if (!pClassFactory->CreateInstance(0, IID_IOleObject, (void**)&browserObject))
    	{		
    		pClassFactory->Release();
    		if (!browserObject->SetClientSite(static_cast<IOleClientSite*>(obj)))
    		{  			
    			browserObject->SetHostNames(L"MyName", 0);			
    
    			HRESULT a = OleSetContainedObject((struct IUnknown *)browserObject, TRUE); // this returns S_OK
    
    			rect.top = 500;
    			rect.left = 700;
    			rect.right = 1000;
    			rect.bottom = 700;
    			
    			//the handle of the window "hwnd" is passed to my function.The window is already created and visible. 
    			HRESULT b = browserObject->DoVerb(OLEIVERB_SHOW, NULL, static_cast<IOleClientSite*>(obj), 0, hwnd, &rect); // this returns E_FAIL !!!!!!!!!!
    
    			HRESULT c = browserObject->QueryInterface(IID_IWebBrowser2, (void**)&webBrowser2);  // this returns S_OK
    			
    			..................................................................................
    			..................................................................................
    			..................................................................................
    			
    		}
    	}
    }
    


    OM
    Friday, March 18, 2011 10:27 PM

Answers

  • Thanks Jesse for your help. Actually I was able to display browser object properly. I had to properly implement IOleInPlaceSite::OnPosRectChange so it will call IOleInPlaceObject::SetObjectRects to set the proper positon. Also I had to set OnInPlaceActivate and CanInPlaceActivate to return S_OK. This has solved my problem of diplaying the browser object and COMCTL.ListViewCtrl inisde the container in a window.

    Now one more task is to handle the events which are triggered from the COM listview control. "ColumnClick" and "ItemClick". Can anyone tell me how to do this?


    OM
    • Marked as answer by momukhtar Thursday, April 28, 2011 9:43 PM
    Friday, March 25, 2011 7:16 PM

All replies

  •  

    Hello,

     

    First, I suggest you use GetLastError() to find out more error messages about these codes. Also  the browserObject->DoVerb function will return other error messages like OLE_E_NOT_INPLACEACTIVE. Please see the return value section in the IOleObject::DoVerb Method document.

     

    Second, the hwndParent parameter should be the handle of the document window containing the object. This and lprcPosRect together make it possible to open a temporary window for an object, where hwndParent is the parent window in which the object's window is to be displayed, and lprcPosRect defines the area available for displaying the object window within that parent. A temporary window is useful, for example, to a multimedia object that opens itself for playback but not for editing.

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 6:12 AM
    Moderator
  • Thanks Jesse for your help. Actually I was able to display browser object properly. I had to properly implement IOleInPlaceSite::OnPosRectChange so it will call IOleInPlaceObject::SetObjectRects to set the proper positon. Also I had to set OnInPlaceActivate and CanInPlaceActivate to return S_OK. This has solved my problem of diplaying the browser object and COMCTL.ListViewCtrl inisde the container in a window.

    Now one more task is to handle the events which are triggered from the COM listview control. "ColumnClick" and "ItemClick". Can anyone tell me how to do this?


    OM
    • Marked as answer by momukhtar Thursday, April 28, 2011 9:43 PM
    Friday, March 25, 2011 7:16 PM