Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET4 Internet Explorer , +
Hey Guys,
 
I'm just working on an automation tool for IE. First thing is to start it through the script which works well, but now I want to catch Mouse Events. Currently I'm using SHDocVw and MSHTML, I also tried to work with
using System.Windows.Forms.WebBrowser;
but that confused me even more.
 
In practice: I want the IE to start and capture every link/button that was clicked with tag or name (at first simply through console output). It's not gonna be an invisible logging tool!!!
 
One test also tried to work with including JavaScript into the code, but I couldn't bring that to life either. If you have any idea on this, I'd be glad to read it.
 
My Code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHDocVw;
using mshtml;
using System.Windows.Forms;
 

namespace IETesting
{
    class EventHandlers
    {
        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            Console.WriteLine("DocumentComplete fired!");
        }
 
        public void OnNavigateComplete(object pDisp, ref object URL)
        {
            Console.WriteLine("NavigateComplete2 fired!");
        }
 
        public void OnMouseDown(IHTMLEventObj pEvtObj)
        {
            Console.WriteLine("MouseDown fired!");
        }
    }
 
    class Program
    {
        static void Main(String[] args)
        {
            EventHandlers e = new EventHandlers();
            SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
            mshtml.HTMLDocument htmlDoc = new HTMLDocument();
            object Empty = 0;
            object URL = "http://www.google.de";
 
            IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(e.OnDocumentComplete); // event that is actually fired
            IE.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(e.OnNavigateComplete); // event that is actually fired
            ((HTMLDocumentEvents2_Event)htmlDoc).onmousedown += new mshtml.HTMLDocumentEvents2_onmousedownEventHandler(e.OnMouseDown); // never triggered

            IE.Visible = true;
            IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
 
            IE.Quit();
        }
    }
}
 
I already spent hours and days searching the web so don't just point me to the first pseudo-solution you find on google. Don't even dare to point me to this article: Working With Microsoft.mshtml.dll and SHDocVw.dll - because really NOTHING here described seems to work in any way.
 
I hope you can help me since I'm pretty close to freaking out. Wink | ;-)
 
Thank you in advance!
Posted 9-Oct-12 0:32am
Seyor102

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Peter Leow 338
1 Kornfeld Eliyahu Peter 230
2 OriginalGriff 223
3 Maciej Los 210
4 Sergey Alexandrovich Kryukov 152
0 OriginalGriff 383
1 Peter Leow 318
2 Kornfeld Eliyahu Peter 260
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 212


Advertise | Privacy | Mobile
Web01 | 2.8.150301.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100