HighTechTalks DotNet Forums  

Hooking mshtm Documentl Events and Mouse going dead

Dotnet Framework (SDK) microsoft.public.dotnet.framework.sdk


Discuss Hooking mshtm Documentl Events and Mouse going dead in the Dotnet Framework (SDK) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Rick Strahl [MVP]
 
Posts: n/a

Default Hooking mshtm Documentl Events and Mouse going dead - 04-24-2004 , 12:40 AM






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




Reply With Quote
  #2  
Old   
Peter Bromberg [C# MVP]
 
Posts: n/a

Default Re: Hooking mshtm Documentl Events and Mouse going dead - 04-24-2004 , 04:04 PM






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]" <rickstrahl (AT) hotmail (DOT) com> wrote

Quote:
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






Reply With Quote
  #3  
Old   
Rick Strahl [MVP]
 
Posts: n/a

Default Re: Hooking mshtm Documentl Events and Mouse going dead - 04-24-2004 , 07:00 PM



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]" <pbromberg (AT) yahoo (DOT) com> wrote

Quote:
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]" <rickstrahl (AT) hotmail (DOT) com> wrote in message
news:Oajkk6bKEHA.3916 (AT) TK2MSFTNGP10 (DOT) 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








Reply With Quote
  #4  
Old   
Peter Bromberg [C# MVP]
 
Posts: n/a

Default Re: Hooking mshtm Documentl Events and Mouse going dead - 04-24-2004 , 07:32 PM



You bet. Some of your excellent code has certainly helped me.
Cheers.

"Rick Strahl [MVP]" <rickstrahl (AT) hotmail (DOT) com> wrote

Quote:
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]" <pbromberg (AT) yahoo (DOT) com> wrote in message
news:OaxOMicrosoftjKEHA.2100 (AT) TK2MSFTNGP10 (DOT) 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]" <rickstrahl (AT) hotmail (DOT) com> wrote in message
news:Oajkk6bKEHA.3916 (AT) TK2MSFTNGP10 (DOT) 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










Reply With Quote
  #5  
Old   
Str Noetika
 
Posts: n/a

Default Re: Hooking mshtm Documentl Events and Mouse going dead - 04-29-2004 , 04:21 PM



Hi,

I got a similar problem but with internet explorer
(shdocvw.internetexplorer) & mshtml. I found a description to handle
these events with webbrowser on
http://support.microsoft.com/default.aspx?scid=kb;en-us;311284, the
example is complete but... my problem is that it doesn't work
completely. I trapped events, by example on click but ie doesn't carry
on doing the selection as it was suppose to do after an hold down click.
It seems that my function ends without giving back the hand to ie. Could
you give me an idea ?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #6  
Old   
Rick Strahl [MVP]
 
Posts: n/a

Default Re: Hooking mshtm Documentl Events and Mouse going dead - 05-14-2004 , 03:36 AM




Well, this is exactly the problem I mentioned to start with. I can't tell
whether VB.Net's event hookups are any different than the direct delegate
assigmments I have to do in C# (I assume they are), but the code sample will
yield the exact problems that I am seeing even though the event hooked
fires.

I think the events are firing but something is wrong with the way these
events are handled that causes the document to disconnect from the host
container in some way, which is why I think you can't do things like click
on the mouse any longer. Who knows what the mshtml wrapper does under the
covers, but it's not working correctly with the document events.

Anyway. The code Peter posted should solve that problem for you - it did for
me and it works for all events that I tried to hook up. I modified the
example code a little to make it simpler yet, but it does appear to work all
the way through.

+++ Rick ---

--

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


"Str Noetika" <developersdex (AT) noetika (DOT) com> wrote

Quote:
Hi,

I got a similar problem but with internet explorer
(shdocvw.internetexplorer) & mshtml. I found a description to handle
these events with webbrowser on
http://support.microsoft.com/default.aspx?scid=kb;en-us;311284, the
example is complete but... my problem is that it doesn't work
completely. I trapped events, by example on click but ie doesn't carry
on doing the selection as it was suppose to do after an hold down click.
It seems that my function ends without giving back the hand to ie. Could
you give me an idea ?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply With Quote
  #7  
Old   
nahla
 
Posts: n/a

Default RE: Hooking mshtm Documentl Events and Mouse going dead - 04-15-2006 , 06:58 PM



Rick,
i'm having the same problem(Handling mshtml Document Events disables browser)
i tried to use Peter's Code ,but i did'nt configure what is DHTMLDoc class that he mentioned.
plzzzzzz reply
thanx in advance


From http://www.developmentnow.com/g/25_2004_4_0_0_111721/Hooking-mshtm-Documentl-Events-and-Mouse-going-dead.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.