5,661,954 members and growing! (260 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate

Handling HTML Element Events in CHtmlView and Reusing CDHtmlDialog Serial Class

By luo31

The enhanced CHtmlView class handles the HTML element event and exchanges data in the view.
VC7.1, C++, HTMLWindows, .NET, .NET 1.1, Win2003, MFC, VS.NET2003, IE 6.0, IE 5.5, Visual Studio, IE, Dev

Posted: 15 May 2005
Updated: 9 Jun 2005
Views: 36,527
Bookmarked: 29 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
14 votes for this Article.
Popularity: 5.16 Rating: 4.50 out of 5
1 vote, 7.1%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
4 votes, 28.6%
4
9 votes, 64.3%
5

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:
    
    //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

};

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:

        BEGIN_DHTML_EVENT_MAP(ChtmlExView)
           DHTML_EVENT_ONCLICK(_T("btnEnd"), OnButtonEnd)
        END_DHTML_EVENT_MAP()
      //and then add OnButtonEnd function.

Add data exchange support

Add the code into the DoDataExchange function:

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

         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!

License

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

luo31


If your chinese is good,pls visit my website:http://blog.mvpcn.net/luo31/.
Occupation: Web Developer
Location: China China

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralPlease help for CDHtmlDialogmemberATS++8:27 2 Jun '08  
Answercode of getting linksmemberxinguomindang20:29 8 Apr '08  
Generalget a version for vc6.0memberyuguichong22:39 2 Sep '07  
GeneralVery good , thanksmemberevgesha8:52 14 Aug '07  
Generalhow to get input text ?memberfor3h2:05 11 May '07  
GeneralRe: how to get input text ?memberBilliamR7:55 15 Oct '07  
Generala problem about the use of CDHtmlViewSpec classmemberchoulery22:00 10 Dec '06  
GeneralApplet in WebBrowsermembercolin-1231:26 13 Sep '06  
QuestionNeed Help on Http Header to add my own User-Agentmemberrex_chen7:59 13 May '06  
GeneralVery good article,nice jobsussAnonymous7:10 30 Sep '05  
GeneralNeed it to work for VC 6memberandrew.truckle@atkinsglobal.com2:01 21 Sep '05  
Generalsink frameset eventsmemberhecchan0:40 23 Jun '05  
GeneralGood articlememberPerry Zh19:11 19 May '05  
Generalthe demo is damaged.memberprog coney16:19 16 May '05  
GeneralRe: the demo is damaged.memberluo3119:16 16 May '05  
GeneralWowsussAnonymous6:24 16 May '05  
GeneralRe: Wowmemberluo3115:36 16 May '05  
GeneralRe: WowstaffSmitha Vijayan19:09 18 May '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Jun 2005
Editor: Rinish Biju
Copyright 2005 by luo31
Everything else Copyright © CodeProject, 1999-2008
Java | Advertise on the Code Project