Internet Explorer 5.5Internet Explorer 6.0IEVisual C++ 7.1Visual Studio .NET 2003Windows 2003.NET 1.1MFCHTML中级开发Visual StudioWindowsC++.NET
处理 CHtmlView 中的 HTML 元素事件并重用 CDHtmlDialog 序列类






4.75/5 (17投票s)
2005 年 5 月 15 日

543273

5824
增强的 CHtmlView 类处理 HTML 元素事件并在视图中交换数据。
前言
CDHtmlSpecEventSink
和 CDHtmlViewSpec
非常棒,它们提供了处理文档事件的宏。请参阅 MSDN 文章:如何为 WebBrowser 主机接收 HTML 文档事件。
结构类 CDHtmlViewSpec
CDHtmlDialog
类直接继承自 CDHtmlEventSink
类,CDHtmlViewSpec
类也一样。CDHtmlSpecEventSink
类的内容如下
class CDHtmlSpecEventSink: public CDHtmlEventSink { public: //implement abstrace method virtual const DHtmlEventMapEntry* GetDHtmlEventMap(); virtual BOOL DHtmlEventHook(HRESULT *phr, DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr); virtual HRESULT GetDHtmlDocument(IHTMLDocument2 **pphtmlDoc); //struct CDHtmlSpecEventSink(); //give the interface to IHTMLDocument2,and //I can't find reference in CDHtmlDialog void InitEventSink(IHTMLDocument2* pDoc); protected: IHTMLDocument2* m_pDocHtml; CHtmlView* m_pView; }; CDHtmlViewSpec: class CDHtmlViewSpec : public CHtmlView, public CDHtmlSpecEventSink { //add releated function and copy //the code from CDHtmlDialog };
当您想要修改时,请从 CDHtmlDialog
复制您的函数。
使用类 CDHtmlViewSpec
使用这个类非常简单。直接从 CHtmlView
继承一个类,然后将 CHtmlView
类更改为 CDHtmlViewSpec
。添加事件和 DDx。请查阅 CDHtmlDialog
的帮助。如果您不想查看帮助,请参考下面的代码
添加事件支持
Add DECLARE_DHTML_EVENT_MAP() into your HtmlView header file. //Add the code into your htmlView Implement file: BEGIN_DHTML_EVENT_MAP(ChtmlExView) DHTML_EVENT_ONCLICK(_T("btnEnd"), OnButtonEnd) END_DHTML_EVENT_MAP() //and then add OnButtonEnd function.
添加数据交换支持
将代码添加到 DoDataExchange
函数中
void ChtmlExView::DoDataExchange(CDataExchange* pDX) { CDHtmlViewSpec::DoDataExchange(pDX); //support radio DDX_DHtml_Radio(pDX,_T("btnControl"),m_iControl); }
关于作者和代码
如果您有任何问题或建议,请通过 (luomh AT haitai.Com.Cn) 发送电子邮件给我。您可以自由使用和修改这个类。如果您的中文好,请访问我的 网站。谢谢!