Click here to Skip to main content
13,352,408 members (60,107 online)
Click here to Skip to main content
Add your own
alternative version


58 bookmarked
Posted 15 May 2005

Handling HTML Element Events in CHtmlView and Reusing CDHtmlDialog Serial Class

, 9 Jun 2005
Rate this:
Please Sign up or sign in to vote.
The enhanced CHtmlView class handles the HTML element event and exchanges data in the view.


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
    //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);
    //give the interface to IHTMLDocument2,and 
    //I can't find reference in CDHtmlDialog 
    void InitEventSink(IHTMLDocument2* pDoc);
    IHTMLDocument2* m_pDocHtml;
    CHtmlView* m_pView;
class CDHtmlViewSpec : public CHtmlView,
                       public CDHtmlSpecEventSink
    //add releated function and copy 
    //the code from CDHtmlDialog

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.
      //Add the code into your htmlView Implement file:
           DHTML_EVENT_ONCLICK(_T("btnEnd"), OnButtonEnd)
      //and then add OnButtonEnd function.

Add data exchange support

Add the code into the DoDataExchange function:

void ChtmlExView::DoDataExchange(CDataExchange* pDX)
         //support radio

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!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
If your chinese is good,pls visit my website:

You may also be interested in...


Comments and Discussions

QuestionWhere is the tutorial? Pin
PRMARJORAM15-May-09 6:00
memberPRMARJORAM15-May-09 6:00 
GeneralPlease help for CDHtmlDialog Pin
ATS++2-Jun-08 8:27
memberATS++2-Jun-08 8:27 
Answercode of getting links Pin
xinguomindang8-Apr-08 20:29
memberxinguomindang8-Apr-08 20:29 
Generalget a version for vc6.0 Pin
yuguichong2-Sep-07 22:39
memberyuguichong2-Sep-07 22:39 
GeneralVery good , thanks Pin
evgesha14-Aug-07 8:52
memberevgesha14-Aug-07 8:52 
Questionhow to get input text ? Pin
for3h11-May-07 2:05
memberfor3h11-May-07 2:05 
AnswerRe: how to get input text ? Pin
BilliamR15-Oct-07 7:55
memberBilliamR15-Oct-07 7:55 

DDX_DHtml_ElementText( pDX, _T("Text1"), DISPID_IHTMLINPUTTEXTELEMENT_VALUE, m_csText1String );

Generala problem about the use of CDHtmlViewSpec class Pin
choulery10-Dec-06 22:00
memberchoulery10-Dec-06 22:00 
GeneralApplet in WebBrowser Pin
colin-12313-Sep-06 1:26
membercolin-12313-Sep-06 1:26 
QuestionNeed Help on Http Header to add my own User-Agent Pin
rex_chen13-May-06 7:59
memberrex_chen13-May-06 7:59 
GeneralVery good article,nice job Pin
Anonymous30-Sep-05 7:10
sussAnonymous30-Sep-05 7:10 
GeneralNeed it to work for VC 6 Pin
andrew.truckle@atkinsglobal.com21-Sep-05 2:01
memberandrew.truckle@atkinsglobal.com21-Sep-05 2:01 
Generalsink frameset events Pin
hecchan23-Jun-05 0:40
memberhecchan23-Jun-05 0:40 
GeneralGood article Pin
Perry Zh19-May-05 19:11
memberPerry Zh19-May-05 19:11 
Generalthe demo is damaged. Pin
prog coney16-May-05 16:19
memberprog coney16-May-05 16:19 
GeneralRe: the demo is damaged. Pin
luo3116-May-05 19:16
memberluo3116-May-05 19:16 
GeneralWow Pin
Anonymous16-May-05 6:24
sussAnonymous16-May-05 6:24 
GeneralRe: Wow Pin
luo3116-May-05 15:36
memberluo3116-May-05 15:36 
GeneralRe: Wow Pin
Smitha Vijayan18-May-05 19:09
staffSmitha Vijayan18-May-05 19:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 9 Jun 2005
Article Copyright 2005 by luo31
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid