B
Ben Rush
Hello,
I hope someone out there can help me. This one has been bothering me
for a while and I'm sure it's a result of me not having understood
something properly somewhere along the line. I would very much
appreciate someone to set me straight.
My goal is to be able to trace a user's activity as he/she uses a
instance of the axWebBrowser control on my Windows Form. He/She visits
a site and I want to track their motion. Essentially I want to
investiage and monitor Buttons, DropDownLists, and CheckBox clicks. I
do not want to interfere with their use of the browser; simply monitor
what they do.
The problem I'm finding, however, is that when I start recieving
events from the active document via MSHTML, I somehow corrupt them.
For example, when I click on a button, the button submits, but the
button doesn't visually "push down", and when I click on a Select tag,
the drop down list doesn't Drop. It's like I've muted some of the
events on the page.
The source I have as of now is attached at the bottom of this message
(for the Windows Form). I have removed certain regions to make the
message smaller, etc. in the source code. When I try and trap events
at the document level (in other attempts not show below in the source
code), I can even sometimes kill all events on the page, and I get
notification that a click occured and on what element, but the element
itself never responds to the click.
What have I done? Thank you VERY much in advance,
Ben
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MsHtmHstInterop;
using System.Runtime.InteropServices;
namespace DomExampleClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form,
MsHtmHstInterop.IDocHostUIHandler
{
private System.Windows.Forms.TextBox textBox_URL;
private System.Windows.Forms.Button button_Go;
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
....
....
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button_Go_Click(object sender, System.EventArgs e)
{
System.Object url = textBox_URL.Text;
System.Object o = null;
axWebBrowser1.Navigate2(ref url, ref o, ref o, ref o, ref o);
}
private void Form1_Load(object sender, System.EventArgs e)
{
button_Go_Click(null,null);
}
mshtml.HTMLButtonElementEvents_Event bEvent = null;
private mshtml.IHTMLDocument2 doc;
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
this.bEvent = (mshtml.HTMLButtonElementEvents_Event)this.doc.all.item("Button1",0);
this.bEvent.onclick += new
mshtml.HTMLButtonElementEvents_onclickEventHandler(bEvent_onclick);
MsHtmHstInterop.ICustomDoc idoc =
(MsHtmHstInterop.ICustomDoc)this.doc;
idoc.SetUIHandler((MsHtmHstInterop.IDocHostUIHandler)this);
}
#region IDocHostUIHandler Members
....
....
#endregion
private bool bEvent_onclick()
{
listBox1.Items.Add("Button Clicked");
return true;
}
}
}
I hope someone out there can help me. This one has been bothering me
for a while and I'm sure it's a result of me not having understood
something properly somewhere along the line. I would very much
appreciate someone to set me straight.
My goal is to be able to trace a user's activity as he/she uses a
instance of the axWebBrowser control on my Windows Form. He/She visits
a site and I want to track their motion. Essentially I want to
investiage and monitor Buttons, DropDownLists, and CheckBox clicks. I
do not want to interfere with their use of the browser; simply monitor
what they do.
The problem I'm finding, however, is that when I start recieving
events from the active document via MSHTML, I somehow corrupt them.
For example, when I click on a button, the button submits, but the
button doesn't visually "push down", and when I click on a Select tag,
the drop down list doesn't Drop. It's like I've muted some of the
events on the page.
The source I have as of now is attached at the bottom of this message
(for the Windows Form). I have removed certain regions to make the
message smaller, etc. in the source code. When I try and trap events
at the document level (in other attempts not show below in the source
code), I can even sometimes kill all events on the page, and I get
notification that a click occured and on what element, but the element
itself never responds to the click.
What have I done? Thank you VERY much in advance,
Ben
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MsHtmHstInterop;
using System.Runtime.InteropServices;
namespace DomExampleClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form,
MsHtmHstInterop.IDocHostUIHandler
{
private System.Windows.Forms.TextBox textBox_URL;
private System.Windows.Forms.Button button_Go;
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
....
....
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button_Go_Click(object sender, System.EventArgs e)
{
System.Object url = textBox_URL.Text;
System.Object o = null;
axWebBrowser1.Navigate2(ref url, ref o, ref o, ref o, ref o);
}
private void Form1_Load(object sender, System.EventArgs e)
{
button_Go_Click(null,null);
}
mshtml.HTMLButtonElementEvents_Event bEvent = null;
private mshtml.IHTMLDocument2 doc;
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
this.bEvent = (mshtml.HTMLButtonElementEvents_Event)this.doc.all.item("Button1",0);
this.bEvent.onclick += new
mshtml.HTMLButtonElementEvents_onclickEventHandler(bEvent_onclick);
MsHtmHstInterop.ICustomDoc idoc =
(MsHtmHstInterop.ICustomDoc)this.doc;
idoc.SetUIHandler((MsHtmHstInterop.IDocHostUIHandler)this);
}
#region IDocHostUIHandler Members
....
....
#endregion
private bool bEvent_onclick()
{
listBox1.Items.Add("Button Clicked");
return true;
}
}
}