Foreword
CDHtmlSpecEventSink
and CDHtmlViewSpec
are very cool, they give you the macro that deals with the document event. Please have a look at the MSDN article: How to sink HTML document events for WebBrowser host.
Structure class CDHtmlViewSpec
CDHtmlDialog
class inherits directly from CDHtmlEventSink
class, CDHtmlViewSpec
class does the same. The content of CDHtmlSpecEventSink
class is given below:
class CDHtmlSpecEventSink: public CDHtmlEventSink
{
public:
virtual const DHtmlEventMapEntry* GetDHtmlEventMap();
virtual BOOL DHtmlEventHook(HRESULT *phr, DISPID dispIdMember,
DISPPARAMS *pDispParams, VARIANT *pVarResult,
EXCEPINFO *pExcepInfo, UINT *puArgErr);
virtual HRESULT GetDHtmlDocument(IHTMLDocument2 **pphtmlDoc);
CDHtmlSpecEventSink();
void InitEventSink(IHTMLDocument2* pDoc);
protected:
IHTMLDocument2* m_pDocHtml;
CHtmlView* m_pView;
};
CDHtmlViewSpec:
class CDHtmlViewSpec : public CHtmlView,
public CDHtmlSpecEventSink
{
};
Copy your function from CDHtmlDialog
when you want to modify.
Use class CDHtmlViewSpec
Using this class is very simple. Inherit a class directly from CHtmlView
, then change CHtmlView
class to CDHtmlViewSpec
. Add the events and DDx. Please go through CDHtmlDialog
's help. If you don't want to look at the help, refer to the code given below:
Add events support
Add DECLARE_DHTML_EVENT_MAP() into your HtmlView header file.
BEGIN_DHTML_EVENT_MAP(ChtmlExView)
DHTML_EVENT_ONCLICK(_T("btnEnd"), OnButtonEnd)
END_DHTML_EVENT_MAP()
Add data exchange support
Add the code into the DoDataExchange
function:
void ChtmlExView::DoDataExchange(CDataExchange* pDX)
{
CDHtmlViewSpec::DoDataExchange(pDX);
DDX_DHtml_Radio(pDX,_T("btnControl"),m_iControl);
}
About the author and the code
If you have any questions or suggestions, please email me at (luomh AT haitai.Com.Cn). You are free to use and revise this class. If your Chinese is good, please visit my website. Thanks!