473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 HTMLDocumnetEve nt2_Event events like this:

HTMLDocumentEve nts2_Event DocEvents = this.Browser.Do cument as
HTMLDocumentEve nts2_Event ;
DocEvents.oncon textmenu += new
HTMLDocumentEve nts2_oncontextm enuEventHandler (Browser_Contex tMenu);

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 4476
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programmin g 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.parentWind ow.@event; }
}

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

public delegate void DHTMLEvent(IHTM LEventObj e);

public class DHTMLEventHandl er
{
public DHTMLEventHandl er(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(documen t.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(DH TMLDoc d,object e)
{
if(!(e is IHTMLElement))t hrow new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLEleme nt)e;
}

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

if(old.GetType( )==typeof(DHTML EventHandler))h =((DHTMLEventHa ndler)old);
else elm.onclick=h=n ew DHTMLEventHandl er(doc);
h.Handler+=valu e;
}
remove
{
object old=elm.onclick ;
if(old.GetType( )==typeof(DHTML EventHandler))
((DHTMLEventHan dler)old).Handl er-=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(I HTMLEventObj 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
DocumentComplet e handler:

DHTMLElement elm=new DHTMLElement(do c,doc["text1"]);
elm.onClick+=ne w DHTMLEvent(DHTM LEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hot mail.com> wrote in message
news:Oa******** ******@TK2MSFTN GP10.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 HTMLDocumnetEve nt2_Event events like this:

HTMLDocumentEve nts2_Event DocEvents = this.Browser.Do cument as
HTMLDocumentEve nts2_Event ;
DocEvents.oncon textmenu += new
HTMLDocumentEve nts2_oncontextm enuEventHandler (Browser_Contex tMenu);

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*******@yaho o.com> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programmin g 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.parentWind ow.@event; }
}

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

public delegate void DHTMLEvent(IHTM LEventObj e);

public class DHTMLEventHandl er
{
public DHTMLEventHandl er(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(documen t.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(DH TMLDoc d,object e)
{
if(!(e is IHTMLElement))t hrow new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLEleme nt)e;
}

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

if(old.GetType( )==typeof(DHTML EventHandler))h =((DHTMLEventHa ndler)old);
else elm.onclick=h=n ew DHTMLEventHandl er(doc);
h.Handler+=valu e;
}
remove
{
object old=elm.onclick ;
if(old.GetType( )==typeof(DHTML EventHandler))
((DHTMLEventHan dler)old).Handl er-=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(I HTMLEventObj 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
DocumentComplet e handler:

DHTMLElement elm=new DHTMLElement(do c,doc["text1"]);
elm.onClick+=ne w DHTMLEvent(DHTM LEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hot mail.com> wrote in message
news:Oa******** ******@TK2MSFTN GP10.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 HTMLDocumnetEve nt2_Event events like this:

HTMLDocumentEve nts2_Event DocEvents = this.Browser.Do cument as
HTMLDocumentEve nts2_Event ;
DocEvents.oncon textmenu += new
HTMLDocumentEve nts2_oncontextm enuEventHandler (Browser_Contex tMenu);

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********@hot mail.com> wrote in message
news:uk******** ******@tk2msftn gp13.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*******@yaho o.com> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Rick,

Nikit Zykov had a fine "mini book" that was originally published on C#
Today called "Programmin g 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.parentWind ow.@event; }
}

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

public delegate void DHTMLEvent(IHTM LEventObj e);

public class DHTMLEventHandl er
{
public DHTMLEventHandl er(DHTMLDoc doc)
{
document=doc;
}

[DispId(0)]
public void Call()
{
Handler(documen t.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(DH TMLDoc d,object e)
{
if(!(e is IHTMLElement))t hrow new Exception("This is not a DHTML
element!");
doc=d;
elm=(IHTMLEleme nt)e;
}

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

if(old.GetType( )==typeof(DHTML EventHandler))h =((DHTMLEventHa ndler)old);
else elm.onclick=h=n ew DHTMLEventHandl er(doc);
h.Handler+=valu e;
}
remove
{
object old=elm.onclick ;
if(old.GetType( )==typeof(DHTML EventHandler))
((DHTMLEventHan dler)old).Handl er-=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(I HTMLEventObj 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
DocumentComplet e handler:

DHTMLElement elm=new DHTMLElement(do c,doc["text1"]);
elm.onClick+=ne w DHTMLEvent(DHTM LEvtClick);

Hope this help!
Peter


"Rick Strahl [MVP]" <ri********@hot mail.com> wrote in message
news:Oa******** ******@TK2MSFTN GP10.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 HTMLDocumnetEve nt2_Event events like this:

HTMLDocumentEve nts2_Event DocEvents = this.Browser.Do cument as
HTMLDocumentEve nts2_Event ;
DocEvents.oncon textmenu += new
HTMLDocumentEve nts2_oncontextm enuEventHandler (Browser_Contex tMenu);

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
1357
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> <title>Event test</title>
1
5356
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 works fine). I am also trying to make this project capable of "Rearrange the keyboard" (example type "e" and "K" is sent to the application) by using SendInput function and I am not able to get it to work. I am finding the use of SendInput...
5
3756
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 processing on certain key/mouse events 3) If key/mouse events interrupt processing, the events should not be discarded since they need to be handled but AFTER the current processing is complete
3
2061
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 forecolor, backcolor and font. The labels also are rotatable and the text can also be flipped 180 degrees (the flipped text part is still being worked on). I have one context menu for all 30 labels that allows for the property changes to the labels....
5
2394
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: http://gerromorpha.cs.uoregon.edu/moveAndOver.html (The above link is only meant for Windows/Firefox.) It's not much code, but it's probably too much to paste here. The gist of it is, when a user clicks on element #1, I attach
8
1959
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 hooks. Please (and thankyou), James Randle.
7
1920
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 the re-fired to its parent. eg class MyCollection : Collection<MyType> { public AddAnObject(MyType obj)
1
1396
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 active one). I have found a nice way to do it with hooking mouse events and reactring accordingly. but I'm affriad that this method is a performances killer for the OS. Is there a better way to do it? How "killer" is my way anyway? Thanks!
0
969
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 access the DOM objects as needed. With my latest changes I want to utilize the MsHTM.dll to parse some text for me. For instance, I'd like to be able to parse the following
0
7939
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8428
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6753
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.