![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
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! |
#7
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |