bgerby Posted April 16, 2003 Posted April 16, 2003 Same issue as mooman_fl mooman_fl or anyone else, Has anyone found a solution. I can capture document events using addHandler, but I cannot then return focus to the browser so it can act normally. In a nutshell, I want to capture the event when someone makes a selection. Quote
vsdotnetguy Posted April 16, 2003 Posted April 16, 2003 There is a bug in the COM Interop between mshtml and .Net. I have received both a VB and C# based workaround from MS. Which do you require? Quote
mooman_fl Posted April 16, 2003 Author Posted April 16, 2003 by all means... post the VB.NET workaround. Still haven't gotten this problem solved. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
vsdotnetguy Posted April 17, 2003 Posted April 17, 2003 (edited) Here is vbrevised.zip attachment From Lauru Xu of MS... The whole problem is related to how delegate classes are implemented (especially when event handler return type has some meaning). So the onclick handler is returning false even when you are returning true from your code. This behavior seems to be by design. When creating COM event sinks in .NET it is natural to use delegates. However, when an event sink contains more than one method, the delegate model may not preserve the return value. The delegate model may also introduce other overhead that is not desirable. When .NET hooks a delegate to a sink interface, it generates an entire sink but only passes on the call for the one method wrapped by the delegate. The rest of the event methods in the generated sink return a default value. Fortunately, there is another way to hook up to a COM event interface from managed code. The workaround is to use connection points. You could hook up to a COM event interface from managed code. You can use the COM connection point interfaces. All COM event classes provide the IConnectionPointContainer interface. When you have the IConnectionPointContainer interface, you must find the specific connection point for the event interface to which you want to subscribe. To do this, follow these steps: 1. Use a FindConnectionPoint call to obtain the IConnectionPoint interface. 2. To subscribe to the event, provide the IConnectionPoint::Advise method with an instance of a class that is inheriting from the event interface. In the .NET Framework libraries, the names of the COM connection point interfaces are located in the System.Runtime.InteropServices namespace, as in the following table: +============================+============================+ | COM Interface Name | .NET Class Name | +============================+============================+ | IConnectionPointContainer | UCOMIConnectPointContainer | +============================+============================+ | IConnectionPoint | UCOMIConnectionPoint | +============================+============================+ Establish a COM Event Sink To establish a COM event sink, follow these steps: 1. Create the class that will sink (handle) the event, 2. Query for the connection point container, and then find the connection point for the event. 3. Hook up the instance of the event class (from step 1) to the connection point hope this helpsvbrevised.zip Edited December 21, 2005 by PlausiblyDamp Quote
vsdotnetguy Posted April 17, 2003 Posted April 17, 2003 BTW...You must include the method signature code for each of the document event methods because the winform must now implement the mshtml.HTMLDocumentEvents2 interface Quote
bgerby Posted April 17, 2003 Posted April 17, 2003 vsdotnetguy, Thank you so much. That works perfectly. I thought I had tried everything, but I guess not. Hope I can return the favor. Quote
bgerby Posted April 17, 2003 Posted April 17, 2003 Events being called as many times as pages loaded I have a strange issue now. If I load one page, I can capture event such as a click or a an onkeydown. Only 1 event is fired. But, if I load one page after another (I am calling Me.AxWebBrowser1.Navigate2(strUrl) where strUrl is the url to load a new page), the new document loads, but now all of my events are doubled. So, if i capture the onclick event, it acts as if it is clicking on the new document and the old document. If I load 10 pages, I get 10 events. It is as if I need to dispose of the first document before I load a new one. But, I have tried a number of things and cannot get the original document to be gone so I only have 1 event. Is Navigate2 the wrong function to load a document? I have tried Navigate. vsdotnet or other To see an example of this, add "AxWebBrowser1.GoHome()" to the onclick event of the sample vsdotnet posted. You will see now the listbox starts to exponentially add more items. Gotta love this stuff. I am sure there is an easy solution, but not easy for me I guess. Thanks in advance. Quote
bgerby Posted April 17, 2003 Posted April 17, 2003 I actually solved my last issue on my own. I'm not sure how good a fix it is, but it works. I set a global boolean variable that tells me whether to do the UCOMIConnectionPointContainer stuff in the AxWebBrowser1_DocumentComplete function. Once, I load the first doc, I change the boolean variable so I only do it once and that seems to work. It actually makes senses to me now too. If this seems off-base, let me know. Quote
maxter Posted May 15, 2003 Posted May 15, 2003 Well we can capture click events, but in a HTML document there are forms, inputs, textareas, .... and if I want capture change events of several html components like inputs areas, textareas,... I've thinking about: - parse html document to extract each html control and add a eventhandler for it, is it possible?? or - wait until web page go to next page, but before capture the state of all html controls. Because i want record user actions over web pages. And after play user actions recorded automatically. Can u help me??? Thanks so much. Quote
chandra Posted July 4, 2003 Posted July 4, 2003 hi i have tried this examples but focus is not going to textbox and push ing of buttons not coming. i get the events why it happening? Quote
cutiti Posted July 18, 2003 Posted July 18, 2003 Hi , I experienced similar problems too that all other events are ignored if I tried to catch one specific event, such as click or double-click. Did anyone have an answer to this? Many thanks. Kim. Quote
bkpsu Posted September 5, 2003 Posted September 5, 2003 wow, I've spent a whole week trying to figure out what I was doing wrong and why my browser window wasn't getting the focus back after a click event. I even followed MSDN examples to the "T". Then, I found this site and fixed my problem in 5 mins, thanks!!! :-D Quote
Drapondur Posted September 13, 2003 Posted September 13, 2003 Hello everybody, I think there's a mistake in the code with this UCOMIConnectionPointContainer stuff. I guess it is is in Sub Dispose: Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() If cookie = -1 Then '!!! THINK it mst be: If cookie <> -1 then ... icp.Unadvise(cookie) Else cookie = -1 End If End If End If MyBase.Dispose(disposing) End Sub Since i don't know exactly what all this UCOMIConnectionPoint-ing means I am not sure if it's really a mistake. Bye D. Quote
jasonboland Posted November 7, 2003 Posted November 7, 2003 Sorry to dig up old threads, but was anyone able to resolve the other events not firing problem? Quote
Leaders dynamic_sysop Posted November 7, 2003 Leaders Posted November 7, 2003 yes :) i've done a bit there , for C# ..... public SHDocVw.WebBrowser_V1 ie;// this will handle the events that dont normally trigger. private void Form1_Load(object sender, System.EventArgs e) { ie=(SHDocVw.WebBrowser_V1)this.axWebBrowser1.Application; this.ie.BeforeNavigate+=new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler(this.ie_BeforeNavigate); this.ie.NewWindow+=new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(this.ie_NewWindow); object o=null; axWebBrowser1.Navigate("http://google.com",ref o,ref o,ref o,ref o); } private void ie_BeforeNavigate(string URL,int Flags, string TargetFrameName,ref object PostData, string Headers, ref bool Cancel) { MessageBox.Show("you are about to navigate to...\n" + URL); } private void ie_NewWindow(string URL,int Flags, string TargetFrameName,ref object PostData, string Headers, ref bool Cancel) { MessageBox.Show("a new window is trying to open, the url is...\n" + URL); } private void button1_Click(object sender, System.EventArgs e) { object o=null; axWebBrowser1.Navigate("http://www.autotrader.co.uk",ref o,ref o,ref o,ref o); } an article i posted a long time ago on the codeproject for vb.net... Extending the axWebbrowser control events. basically like this... Private WithEvents doc As SHDocVw.DWebBrowserEvents_Event '/// doc will handle all the events for brweb now... Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim b As Object = brWeb.Application doc = DirectCast(b, SHDocVw.WebBrowser_V1) '///set doc as the active handler for brweb's events. End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click brWeb.Navigate("http://google.com") '///lets navigate to a website. End Sub Private Sub doc_BeforeNavigate(ByVal URL As String, ByVal Flags As Integer, ByVal TargetFrameName As String, ByRef PostData As Object, ByVal Headers As String, ByRef Cancel As Boolean) Handles doc.BeforeNavigate MessageBox.Show(URL) '/// check that before navigate now works. End Sub Private Sub doc_StatusTextChange(ByVal [Text] As String) Handles doc.StatusTextChange Label1.Text = Text '///show the status text in a label. End Sub Private Sub doc_TitleChange(ByVal [Text] As String) Handles doc.TitleChange MyBase.Text = Text '/// set the form's caption to the current url End Sub maybe these could go in the code section of this forum? Quote
jtal Posted March 8, 2005 Posted March 8, 2005 Yes, but what about the GUI? Capturing events is something that I've also been working on. Using the Web Browser control is great for changing an application layout, or as a natural interface when dealing with xml-based data, but... I'd like to "tweak" the control itself. Specifically, I'd like the control to be displayed flat instead of as Fixed3d. Any ideas? I can't seem to find anyone else that cares. :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.