473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hooking mshtm Documentl Events and Mouse going dead

I'm working on an app that's using the WebBrowser control.

I got the control working fine, hooking to the document object. But I've run
into a major issue with hooking the Document events. Whenever I hook any of
the HTMLDocumnetEvent2_Event events like this:

HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as
HTMLDocumentEvents2_Event ;
DocEvents.oncontextmenu += new
HTMLDocumentEvents2_oncontextmenuEventHandler(Brow ser_ContextMenu);

the browser document becomes unresposinve. The events fire fine and the
Document otherwise works - links highlight, status events fire and I can
select linsk with the keyboard. But all mouse clicks are eaten.

It doesn't matter which event I hook - just to verify I used the onhelp
event instead of one that hooks mouse events. As soon as the event gets
hooked up the mouse clicks die. Take it out - all is well (well within
reason).

Any ideas?

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web

Nov 16 '05 #1
3 4456
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programming Internet Explorer in C#". I am not sure you can
still get hold of it because of all the Wrox stuff in the last year or so,
but if you haven't seen it, I recommend it highly.

Zykov's implementation snippet (greatly simplified, but usable nonetheless)
follows:
================================================== =
Create a handler class able to give us access to the DHTML event object
interface that we need in order to access to some supplemental information
about the event we're managing, like mouse click coordinates or the event
source object. You can get the event property of the window object attached
to the document. Extend your DHTMLDoc class by adding a new Event property
to it:

public IHTMLEventObj Event
{
get{ return doc2.parentWindow.@event; }
}

Now you can create a new fully functional DHTMLEventHandler class and a
corresponding delegate

public delegate void DHTMLEvent(IHTMLEventObj e);

public class DHTMLEventHandler
{
public DHTMLEventHandler(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(document.Event);
}

public DHTMLEvent Handler;
DHTMLDoc document;
}

Now create a new DHTMLElement class to allow you to encapsulate the generic
DHTML element functionality.
The first bit will be event handling. In the code below, we implement the
onclick event template:

public class DHTMLElement
{
public DHTMLElement(DHTMLDoc d,object e)
{
if(!(e is IHTMLElement))throw new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLElement)e;
}

public event DHTMLEvent onClick
{
add
{
object old=elm.onclick;
DHTMLEventHandler h;

if(old.GetType()==typeof(DHTMLEventHandler))h=((DH TMLEventHandler)old);
else elm.onclick=h=new DHTMLEventHandler(doc);
h.Handler+=value;
}
remove
{
object old=elm.onclick;
if(old.GetType()==typeof(DHTMLEventHandler))
((DHTMLEventHandler)old).Handler-=value;
}
}

IHTMLElement elm;
DHTMLDoc doc;
}

You can do copy-and-paste to create other events handlers; the only
additional work you'll probably have to do concerns querying for special
interfaces for the events that don't concern all the DHTML element types
(like onclick).

Once this work is done, you can add an event handler to any DHTML element by
using only two lines of code, like with DHTML except that in our case, you
are sure it works and you can share one delegate type for all your events.
To give you an example, we'll create the following handler in our Form1
class:

private void DHTMLEvtClick(IHTMLEventObj e)
{
MessageBox.Show("Click detected at: "+e.x+"/"+e.y,"C# event handler");
}

To attach this to the event, just add these two lines to your
DocumentComplete handler:

DHTMLElement elm=new DHTMLElement(doc,doc["text1"]);
elm.onClick+=new DHTMLEvent(DHTMLEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
I'm working on an app that's using the WebBrowser control.

I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this:

HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as
HTMLDocumentEvents2_Event ;
DocEvents.oncontextmenu += new
HTMLDocumentEvents2_oncontextmenuEventHandler(Brow ser_ContextMenu);

the browser document becomes unresposinve. The events fire fine and the
Document otherwise works - links highlight, status events fire and I can
select linsk with the keyboard. But all mouse clicks are eaten.

It doesn't matter which event I hook - just to verify I used the onhelp
event instead of one that hooks mouse events. As soon as the event gets
hooked up the mouse clicks die. Take it out - all is well (well within
reason).

Any ideas?

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web

Nov 16 '05 #2
Thanks a bunch Peter. I picked up a download version of the book from
Amazon.
Damn I wish I would have found this a little earlier <g>...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Peter Bromberg [C# MVP]" <pb*******@yahoo.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programming Internet Explorer in C#". I am not sure you can
still get hold of it because of all the Wrox stuff in the last year or so,
but if you haven't seen it, I recommend it highly.

Zykov's implementation snippet (greatly simplified, but usable nonetheless) follows:
================================================== =
Create a handler class able to give us access to the DHTML event object
interface that we need in order to access to some supplemental information
about the event we're managing, like mouse click coordinates or the event
source object. You can get the event property of the window object attached to the document. Extend your DHTMLDoc class by adding a new Event property
to it:

public IHTMLEventObj Event
{
get{ return doc2.parentWindow.@event; }
}

Now you can create a new fully functional DHTMLEventHandler class and a
corresponding delegate

public delegate void DHTMLEvent(IHTMLEventObj e);

public class DHTMLEventHandler
{
public DHTMLEventHandler(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(document.Event);
}

public DHTMLEvent Handler;
DHTMLDoc document;
}

Now create a new DHTMLElement class to allow you to encapsulate the generic DHTML element functionality.
The first bit will be event handling. In the code below, we implement the
onclick event template:

public class DHTMLElement
{
public DHTMLElement(DHTMLDoc d,object e)
{
if(!(e is IHTMLElement))throw new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLElement)e;
}

public event DHTMLEvent onClick
{
add
{
object old=elm.onclick;
DHTMLEventHandler h;

if(old.GetType()==typeof(DHTMLEventHandler))h=((DH TMLEventHandler)old);
else elm.onclick=h=new DHTMLEventHandler(doc);
h.Handler+=value;
}
remove
{
object old=elm.onclick;
if(old.GetType()==typeof(DHTMLEventHandler))
((DHTMLEventHandler)old).Handler-=value;
}
}

IHTMLElement elm;
DHTMLDoc doc;
}

You can do copy-and-paste to create other events handlers; the only
additional work you'll probably have to do concerns querying for special
interfaces for the events that don't concern all the DHTML element types
(like onclick).

Once this work is done, you can add an event handler to any DHTML element by using only two lines of code, like with DHTML except that in our case, you
are sure it works and you can share one delegate type for all your events.
To give you an example, we'll create the following handler in our Form1
class:

private void DHTMLEvtClick(IHTMLEventObj e)
{
MessageBox.Show("Click detected at: "+e.x+"/"+e.y,"C# event handler");
}

To attach this to the event, just add these two lines to your
DocumentComplete handler:

DHTMLElement elm=new DHTMLElement(doc,doc["text1"]);
elm.onClick+=new DHTMLEvent(DHTMLEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
I'm working on an app that's using the WebBrowser control.

I got the control working fine, hooking to the document object. But I've

run
into a major issue with hooking the Document events. Whenever I hook any

of
the HTMLDocumnetEvent2_Event events like this:

HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as
HTMLDocumentEvents2_Event ;
DocEvents.oncontextmenu += new
HTMLDocumentEvents2_oncontextmenuEventHandler(Brow ser_ContextMenu);

the browser document becomes unresposinve. The events fire fine and the
Document otherwise works - links highlight, status events fire and I can
select linsk with the keyboard. But all mouse clicks are eaten.

It doesn't matter which event I hook - just to verify I used the onhelp
event instead of one that hooks mouse events. As soon as the event gets
hooked up the mouse clicks die. Take it out - all is well (well within
reason).

Any ideas?

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web


Nov 16 '05 #3
You bet. Some of your excellent code has certainly helped me.
Cheers.

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
Thanks a bunch Peter. I picked up a download version of the book from
Amazon.
Damn I wish I would have found this a little earlier <g>...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Peter Bromberg [C# MVP]" <pb*******@yahoo.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programming Internet Explorer in C#". I am not sure you can still get hold of it because of all the Wrox stuff in the last year or so, but if you haven't seen it, I recommend it highly.

Zykov's implementation snippet (greatly simplified, but usable nonetheless)
follows:
================================================== =
Create a handler class able to give us access to the DHTML event object
interface that we need in order to access to some supplemental information about the event we're managing, like mouse click coordinates or the event source object. You can get the event property of the window object

attached
to the document. Extend your DHTMLDoc class by adding a new Event property to it:

public IHTMLEventObj Event
{
get{ return doc2.parentWindow.@event; }
}

Now you can create a new fully functional DHTMLEventHandler class and a
corresponding delegate

public delegate void DHTMLEvent(IHTMLEventObj e);

public class DHTMLEventHandler
{
public DHTMLEventHandler(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(document.Event);
}

public DHTMLEvent Handler;
DHTMLDoc document;
}

Now create a new DHTMLElement class to allow you to encapsulate the

generic
DHTML element functionality.
The first bit will be event handling. In the code below, we implement the onclick event template:

public class DHTMLElement
{
public DHTMLElement(DHTMLDoc d,object e)
{
if(!(e is IHTMLElement))throw new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLElement)e;
}

public event DHTMLEvent onClick
{
add
{
object old=elm.onclick;
DHTMLEventHandler h;

if(old.GetType()==typeof(DHTMLEventHandler))h=((DH TMLEventHandler)old);
else elm.onclick=h=new DHTMLEventHandler(doc);
h.Handler+=value;
}
remove
{
object old=elm.onclick;
if(old.GetType()==typeof(DHTMLEventHandler))
((DHTMLEventHandler)old).Handler-=value;
}
}

IHTMLElement elm;
DHTMLDoc doc;
}

You can do copy-and-paste to create other events handlers; the only
additional work you'll probably have to do concerns querying for special
interfaces for the events that don't concern all the DHTML element types
(like onclick).

Once this work is done, you can add an event handler to any DHTML element by
using only two lines of code, like with DHTML except that in our case,

you are sure it works and you can share one delegate type for all your events. To give you an example, we'll create the following handler in our Form1
class:

private void DHTMLEvtClick(IHTMLEventObj e)
{
MessageBox.Show("Click detected at: "+e.x+"/"+e.y,"C# event handler"); }

To attach this to the event, just add these two lines to your
DocumentComplete handler:

DHTMLElement elm=new DHTMLElement(doc,doc["text1"]);
elm.onClick+=new DHTMLEvent(DHTMLEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
I'm working on an app that's using the WebBrowser control.

I got the control working fine, hooking to the document object. But I've
run
into a major issue with hooking the Document events. Whenever I hook
any of
the HTMLDocumnetEvent2_Event events like this:

HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as
HTMLDocumentEvents2_Event ;
DocEvents.oncontextmenu += new
HTMLDocumentEvents2_oncontextmenuEventHandler(Brow ser_ContextMenu);

the browser document becomes unresposinve. The events fire fine and

the Document otherwise works - links highlight, status events fire and I can select linsk with the keyboard. But all mouse clicks are eaten.

It doesn't matter which event I hook - just to verify I used the onhelp event instead of one that hooks mouse events. As soon as the event gets hooked up the mouse clicks die. Take it out - all is well (well within
reason).

Any ideas?

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: VK | last post by:
To PointedEars with my deep respect. Author ;-) There were a question a while ago about events. Now I see that my original explanation was not full. Check this sample out: <html> <head>...
1
by: Matthew Kelly | last post by:
I have pulled together a VB.net project that hooks the keyboard (Ref. Paul Kimmel's hooking program) and allow the user to send "mouse right clicks" via the SendInpuut function (mouse emulation...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
5
by: JB | last post by:
I am struggling to figure out a way to allow one element to be dragged, but still capture 'mouseover' events on other elements. I've created a simple example to demonstrate what I mean:...
8
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse...
7
by: nick.fletcher | last post by:
I have a custom collection which derives from Collection<which stores a number of objects. Before each item is added to the collection - an event which it exposes is hooked by the collection and...
1
by: Tom Rahav | last post by:
Hello, I try to develop application that runs in the background and suppose to display a small form with menu whenever the user clicks the middle mouse button (also when my application is not the...
0
by: hzgt9b | last post by:
Using VB.NET under .NET 1.1 in VS2003, BACKGROUND I have a windows application that dereferences the MsHTM.dll. The app is successfully able to parse existing HTM documents allowing me to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.