Click here to Skip to main content
15,886,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm playing around with implementing a web browser based on the Internet Explorer Web Browser control. I've created an MFC project and created a wrapper class for the control, so that class now has Create() methods and a bunch of methods that call InvokeHelper(). In and of itself, that all works; I can run the project and I do indeed get a nicely-functioning web browser in my view.

Now I would like to start tapping into the advanced functionality of the control - for example, adding an event sink for DWebBrowserEvents2. Unfortunately this is where I have hit a brick wall, as I don't seem to have a way of doing anything COM-like, such as QueryInterface() or whatever is required for the event sink from that wrapper class.

The article here:

http://www.codeproject.com/Articles/9014/Understanding-COM-Event-Handling

talks about using a smart pointer to start implementing the sink (e.g.: m_spIEventFiringObject.CreateInstance(__uuidof(EventFiringObject)); ), but the wrapper class doesn't seem to expose anything IID / uuid-related to do that.

I had a look at COleControlSite, which I can get from the class, but that didn't give too many clues.

The code for my wrapper class starts with this sort of thing:

class CWebBrowser : public CWnd
{
protected:
    DECLARE_DYNCREATE(CWebBrowser)
public:
    CLSID const& GetClsid()
    {
        static CLSID const clsid
            = { 0x8856F961, 0x340A, 0x11D0, { 0xA9, 0x6B, 0x0, 0xC0, 0x4F, 0xD7, 0x5, 0xA2 } };
        return clsid;
    }
    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
                        const RECT& rect, CWnd* pParentWnd, UINT nID, 
                        CCreateContext* pContext = NULL)
    { 
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); 
    }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, 
                UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
                BSTR bstrLicKey = NULL)
    { 
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
        pPersist, bStorage, bstrLicKey); 
    }

// Attributes
public:
enum
...

// Operations
public:

// IWebBrowser2

// Functions
//

    void GoBack()
    {
        InvokeHelper(0x64, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    void GoForward()
    {
        InvokeHelper(0x65, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }

Can anyone help guide me as to how to proceed?

Thanks.
Posted
Comments
[no name] 5-Apr-13 10:58am    
if you need to use web browser as skin mode, add "web browser" from com components to your project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900