Compartilhar via


Creating a Web Browser Object (Windows CE 5.0)

Send Feedback

After you create the browser window as described in Creating a Browser Window, you must create a Web browser object. To do so, create an instance of the IWebBrowser and use the IOleObject to setup OLE activation, and IOleClientSite to setup a client site.

The following code example shows a method defined in the browser class, CreateBrowserObject that retrieves the IWebBrowser2 interface from the OLE object.

//Create the Web browser object. 
HRESULT CBrowser::CreateBrowserObject()
{
  HRESULT hr;
  IUnknown *pUnk = NULL;
  IOleObject *pObject = NULL;
  RECT rc;  // for activate
  if (!_pWB2)
  {
// Create an instance of a web browser object (from Shdocvw.dll).
    hr = CoCreateInstance(CLSID_WebBrowser, NULL,
                          CLSCTX_INPROC_SERVER | 
                          CLSCTX_INPROC_HANDLER,
                          IID_IUnknown, (LPVOID *)(&pUnk));
    if (FAILED(hr))
          goto Cleanup;
// Retrieve an IOleObject interface to set up OLE activation.
    hr = pUnk->QueryInterface(IID_IOleObject, (LPVOID *)(&pObject));
    if (FAILED(hr))
          goto Cleanup;
// Check if Shdocvw requires a client site to be created first.
    DWORD dwFlags;
    hr = pObject->GetMiscStatus(DVASPECT_CONTENT, &dwFlags);
    if (FAILED(hr))
        goto Cleanup;
    if (dwFlags & OLEMISC_SETCLIENTSITEFIRST)
    {
// Get an IOleClientSite instance from the browser and pass it to the browser.
        IOleClientSite *pClientSite;
        hr = QueryInterface(IID_IOleClientSite, (LPVOID *)(&pClientSite));
        if (FAILED(hr))
              goto Cleanup;
        hr = pObject->SetClientSite(pClientSite);
        pClientSite->Release();
        if (FAILED(hr))
            goto Cleanup;
    }
// Activate the object. 
// Store off the IOleObject reference.
    _pObject = pObject;
    _pObject->AddRef();
    ::GetClientRect(_hWnd, &rc);
    hr = _pObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, this, 0, _hWnd, &rc);
    if (FAILED(hr))
        goto Cleanup;
// Retrieve the IWebBrowser2 interface from the IOleObject.
    hr = _pObject->QueryInterface(IID_IWebBrowser2, (void **)&_pWB2);
    if (FAILED(hr))
        goto Cleanup;
  }
Cleanup:
  if (pUnk)
      pUnk->Release();
  if (pObject)
      pObject->Release();
  return hr;
}

See Also

Setting Up Event Sinks | Creating an Internet Browser

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.