次の方法で共有


Creating a Browser Class (Windows Embedded CE 6.0)

1/6/2010

To create an Internet browser, you must define a class for the browser that inherits OLE interfaces to facilitate OLE activation. The following table shows the interfaces that the class must inherit:

Interface Description

IOleContainer

Used to enumerate objects in a compound document or to lock a container in the running state. Container and object applications both implement this interface.

IOleClientSite

Primary means by which an embedded object obtains information about the location and the extent of its display site, moniker, user interface, and other resources that are provided by its container.

IOleInPlaceSite

Manages interaction between the container and the object's in-place client site. The client site is the display site for embedded objects, and provides position and conceptual information about the object.

IOleControlSite

Provides the methods that enable a site object to manage each embedded control in a container. A site object provides this interface and other site interfaces such as IOleClientSite and IOleInPlaceSite. When a control requires the services expressed through this interface, it will query one of the other client site interfaces for IOleControlSite.

DWebBrowserEvents2

Designates an event sink interface that an application must implement in order to receive event notifications from a WebBrowser control or from the Internet Explorer application.

The following code example shows a browser class, CBrowser, that implements the browser object.

class CBrowser : 
    public IOleContainer,
    public IOleClientSite,
    public IOleInPlaceSite,
    public IOleControlSite,
    public DWebBrowserEvents2
{
public:
// Declare new and delete clear allocators.
    inline void * __cdecl operator new(size_t cb) { return LocalAlloc(LPTR, cb); } 
    inline void __cdecl operator delete(void * pv) { LocalFree(pv); }
// Constructor and Destructor
  CBrowser();
  ~CBrowser();
  //IUnknown methods
  STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv)
  {
    //QueryInterface for IoleContainer.
    if ((riid == IID_IOleContainer) || (riid == IID_IUnknown))
    {
        RETAILMSG(1, (L"Browser QueryInterface for IOleContainer"));
        *ppv = (IOleContainer *) this;
    }     
    else if (...//Inerface)
    {
      ...//Query Interface for other interfaces.
    }
    AddRef();
    return S_OK;
  }
  STDMETHOD_(ULONG, AddRef) (void)
  {
    ...
  }
  
  STDMETHOD_(ULONG, Release) (void)
  {
    ...
  }
  ...// IOleContainer methods
  ...// IOleClientSite methods
  ...// IOleWindow methods
  ...// IOleInPlaceSite methods
  ...// IOleControlSite methods
  ...// DWebBrowserEvents
  ...// IDispatch methods
// public methods
  HRESULT StartBrowser(LPWSTR szURL);     // Start a browser.
  HRESULT NavigateToURL(LPWSTR szURL);    // Browse to a URL.
  void CloseBrowser(); // Close the browser.
//static WndProc wrapper and actual WndProc
  static LRESULT  CALLBACK s_BrowseWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  LRESULT BrowseWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
private:
  HRESULT CreateBrowserWindow();    // Create the main window.
  HRESULT CreateBrowserObject();    // Create a web browser object.
  HRESULT RegisterBrowserEventSink(); // Connect up the event sink
// private members
  HWND _hWnd;   //The main window
  IoleObject *_pObject; // The browser object
  IConnectionPoint *_pCP;  // Pointer to the browser event connection-point (for DWebBrowserEvents2)
  IWebBrowser2 *_pWB2; // Pointer to the Web browser object
  BOOL _bInPlaceActive;  // Determines if the document is active
  DWORD _dwEventCookie; // Stores cookies that will be received when the 
                        // browser registers to receive DWebBrowserEvents2
  ULONG _ulRefs; //reference count for the interfaces supported by the 
                 //container.
};

See Also

Concepts

Creating an Internet Browser
Registering the Browser Window

Other Resources