Simple VC++ DHTML Hooking Technique

Environment: VC6 SP4, ie5, ie5-lib

This example demonstrates how to access DHTML object model and how to intercept the DHTML element events, it also demonstrates how to use connectionpoint with MFC. The demo program first loads up a sample html page containing two button elements and a listbox element. Then it accesses a button element DHTML object and intercepts its Click, DoubleClick, MouseMove, MouseOver, MouseDown, MouseUp events. After the program intercepts an event, it records the event information to a ListBox element on sample html page. The example is showing that MSHTML is very useful for internet and web programming. I hope this example provides some help for any one who want to use MSHTML library. (You need to download ie5_lib or a later IE library to compile the demo project)

Downloads

Download demo project - 48 Kb


Comments

  • Problem setting connection point on Input Image type elements.

    Posted by kamleshsoni1979 on 11/25/2004 09:49am

    Hi,
      I modified the mshtmlhook demo code a bit to also add one more element in the html page loaded by the dialog. The element is Input image type. And the code added to the html page is .
    I modified the code for CMshtmlhookDlg and added one more api for setting connection points on this Input Image element.
    
    void CMshtmlhookDlg::ConnectImage(IHTMLInputImage* pImageElem)
    {
    
        ////////////////////////////////////////////////////////
    	HRESULT hr = 0;
        
    	IConnectionPointContainer* pCPC = NULL;
        
    	IConnectionPoint* pCP = NULL;
        
    	IUnknown* pUnk = NULL;
    	
    	DWORD dwCookie;
    
           // Check that this is a connectable object.
    	hr = pImageElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
    
        if (hr == S_OK)
        {
    
    		//AfxMessageBox("ConnectionPointContainer");
    		// Find the connection point.
    	hr = pCPC->FindConnectionPoint(DIID_HTMLInputImageEvents, &pCP);
    
    
    		if (hr == S_OK)
    	{
    
    			//AfxMessageBox("Find connection point ");
    			// Advise the connection point.
    	    // pUnk is the IUnknown interface pointer for your event sink
    
    			CDHTMLEventSink* pSink = new CDHTMLEventSink;
    
    	    pSink->SetParent(this);
    
    			IUnknown* pUnk = pSink->GetInterface(&IID_IUnknown);
    
    			hr = pCP->Advise(pUnk, &dwCookie);
    
    
    
    			pCP->Release();
    	}
    	else
    	{
    		if(pCP == NULL)
    		{
    			AfxMessageBox("Find connection point input image elment failed");
    		}
    	}
    
    
    	pCPC->Release();
        }
    }
    
    
    But FindConnectionPoint(DIID_HTMLInputImageEvents, &pCP) api used above fails to find the connection point on Input Image Element. Can any one suggest any reason for this failure or is there any workaround for this. The connection points gets set properly for all the other kinds of html elements but for Input Image type. Please help.
    
    Thanks and Regards,
    Kamlesh.

    Reply
  • Great implementation of event sink!

    Posted by piotrmb on 06/14/2004 06:37am

    Simple, yet functional implementation of event sink! Great job.

    Reply
  • how can i get the click event on IHTMLInputButtonElement

    Posted by Legacy on 08/28/2003 12:00am

    Originally posted by: east zhang

       
    
    My dear friend:
    This program is very helpful for me. I can get the click event on my IHTMLInputButtonElement and Now I want to get the IHTMLInputButtonElement via IHTMLEventObj too,I tried many times,but all failed.Can anyone help me? Thank you for advance!

    • ok

      Posted by journeyMFC on 10/17/2008 11:03am

      very good!

      Reply
    Reply
  • Clicking formatted links: how can I get anchor value?

    Posted by Legacy on 07/22/2003 12:00am

    Originally posted by: Vladimir Kamsky

    Situation: <A HREF=url><B>Some link</B></A>

    I'd like to intercept anchor clicking.
    When clicking at this link I've got "clicking bold text" (most internal). How can I get outer <A HREF=url>?

    Reply
  • MSHTMLHOOK in netscape also?

    Posted by Legacy on 06/22/2003 12:00am

    Originally posted by: Jayaprabha

    Can MSHTMLHOOK be used to access the document of netscape also?

    Reply
  • why don't work "VTS_DISPATCH" option in "DISP_FUNCTION_ID" macro

    Posted by Legacy on 04/17/2003 12:00am

    Originally posted by: Jin4309

    hi~ i'm a beginning Programmer....download this sample ago 3 weeks....

    but, can't compile....i readed yours reply Message, and find measures....that say modify code can compile....that is right...

    But....Modify Code have a big trouble....DISP_FUNCTION_ID macro option(6th) is VTS_NONE....it is no argument function's option....but i need EventObj...

    but change VTS_NONE to VTS_DISPATCH(or other opton) function haven't Run Time

    Why? plz help me....

    Reply
  • Don't work

    Posted by Legacy on 03/12/2003 12:00am

    Originally posted by: hongwei

    I download this example and compiled it. after run ,sink evnet don't work,why?
    
    

    win2000 + vc6 sp5 + ie5.0

    • use ie6,it can work

      Posted by xqyz8888 on 04/12/2004 01:36am

      i do not know the reason

      Reply
    Reply
  • OK but capture mouse click for all the web page ?

    Posted by Legacy on 01/31/2003 12:00am

    Originally posted by: jeremyS

    with this example i understand to capture mouse click on buttons, but i want detect mouse click down et mouse click up for all web page.
    when someone selct text in the html document i want to know the mouse position when clisk down and the position when click up !
    you know how to do this??

    Reply
  • Can you embed a contol in an HTML page that can do this?

    Posted by Legacy on 12/05/2002 12:00am

    Originally posted by: Joseph Mueller

    I noticed that the code you have works by having an application (exe) open a browser.  Is it possible for an ActiveX control to do the same thing if it is embeded in an HTML page?  When I have tried doing this I get a memory access violation.  If this is possible, how do you do this?  I have been trying to do this for weeks now and I can't get anywhere.
    
    

    <html>
    <body>
    <OBJECT
    ID="SR_MFC_COMP"
    CLASSID="CLSID:E564A57A-8AF6-4945-975B-06352CFA5B86"
    CODEBASE="C:\SR_MFC_COMP\Release\SR_MFC_COMP.ocx"
    height=100
    width=100
    >
    </OBJECT>

    Reply
  • What does the mshtmlhook.odl do?

    Posted by Legacy on 10/22/2002 12:00am

    Originally posted by: nodman

    Hello everyone, I just downloaded the hook example and found it is pretty good! I have it modified and merge it into my project, much thanks to author!

    I found there is a "mshtmlhook.odl" file in the example. I dont know what it is, I removed it from project and it works properly anyway, what I want to know about is what can this ODL file do? Will I meet some trouble in the future without the ODL file?

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds