Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with frames using .NET & webbrowser control

Problem with frames using .NET & webbrowser control

Scheduled Pinned Locked Moved C#
helpquestioncsharpc++html
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GriffonRL
    wrote on last edited by
    #1

    Hello, I am currently porting a webbrowser application from C++ to C#/.NET. I already struggled with the beforenavigate2 bug everybody was talking about and I can't wait for the .NET SP3. My current problem is when trying to traverse the DOM tree after a documentcomplete event. It works properly for non framed document but not for framed pages. Everytime a documentcomplete event is fired I always get the same document (the top level one). It should mean that I am always getting the same document, but I must be missing something because I don't know how to get a specific frame document. Here is the C# piece of code: private void documentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ AxSHDocVw.AxWebBrowser Frame; IHTMLDocument3 Doc; IHTMLDOMChildrenCollection Tags; IHTMLElement Tag; int NumTags; Console.WriteLine("URL: "+e.uRL); // Good frame URL try{ Frame=(AxSHDocVw.AxWebBrowser)sender; // Is it really the frame ? if(Frame!=null){ Doc=(IHTMLDocument3)Frame.Document; // Top level document ??? if(Doc!=null){ Tags=(IHTMLDOMChildrenCollection)Doc.childNodes; if(Tags!=null){ NumTags=Tags.length; for(int i=0;i Another question is: what is e.pDisp ? How to cast it ? It tried to cast it into an AxSHDocVw.AxWebBrowser and I got an error. Regards, R. L.

    S A 2 Replies Last reply
    0
    • G GriffonRL

      Hello, I am currently porting a webbrowser application from C++ to C#/.NET. I already struggled with the beforenavigate2 bug everybody was talking about and I can't wait for the .NET SP3. My current problem is when trying to traverse the DOM tree after a documentcomplete event. It works properly for non framed document but not for framed pages. Everytime a documentcomplete event is fired I always get the same document (the top level one). It should mean that I am always getting the same document, but I must be missing something because I don't know how to get a specific frame document. Here is the C# piece of code: private void documentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ AxSHDocVw.AxWebBrowser Frame; IHTMLDocument3 Doc; IHTMLDOMChildrenCollection Tags; IHTMLElement Tag; int NumTags; Console.WriteLine("URL: "+e.uRL); // Good frame URL try{ Frame=(AxSHDocVw.AxWebBrowser)sender; // Is it really the frame ? if(Frame!=null){ Doc=(IHTMLDocument3)Frame.Document; // Top level document ??? if(Doc!=null){ Tags=(IHTMLDOMChildrenCollection)Doc.childNodes; if(Tags!=null){ NumTags=Tags.length; for(int i=0;i Another question is: what is e.pDisp ? How to cast it ? It tried to cast it into an AxSHDocVw.AxWebBrowser and I got an error. Regards, R. L.

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      This article [^]might help you. I have included frame events. GriffonRL wrote: what is e.pDisp ? How to cast it ? It tried to cast it into an AxSHDocVw.AxWebBrowser and I got an error. This one should not really appear in public interfaces, but anyway, that's the instance of the underlying web browser control. You can't do much with C# about it, and in fact you don't need since the public IE interfaces are all available to you.


      She's so dirty, she threw a boomerang and it wouldn't even come back.

      G 1 Reply Last reply
      0
      • S Stephane Rodriguez

        This article [^]might help you. I have included frame events. GriffonRL wrote: what is e.pDisp ? How to cast it ? It tried to cast it into an AxSHDocVw.AxWebBrowser and I got an error. This one should not really appear in public interfaces, but anyway, that's the instance of the underlying web browser control. You can't do much with C# about it, and in fact you don't need since the public IE interfaces are all available to you.


        She's so dirty, she threw a boomerang and it wouldn't even come back.

        G Offline
        G Offline
        GriffonRL
        wrote on last edited by
        #3

        Hello Stephane, Thanks for your answer :). I am looking at the article. But this pDisp is not clear for me. You wrote: This one should not really appear in public interfaces, but anyway, that's the instance of the underlying web browser control. You can't do much with C# about it, and in fact you don't need since the public IE interfaces are all available to you. Since I used to write webbrowser applications with VC++, I was actually getting the frame browser control instance in pDisp. What I can't understand, is why e.pDisp exists if we can't cast it ? Regards, R. L.

        S 1 Reply Last reply
        0
        • G GriffonRL

          Hello Stephane, Thanks for your answer :). I am looking at the article. But this pDisp is not clear for me. You wrote: This one should not really appear in public interfaces, but anyway, that's the instance of the underlying web browser control. You can't do much with C# about it, and in fact you don't need since the public IE interfaces are all available to you. Since I used to write webbrowser applications with VC++, I was actually getting the frame browser control instance in pDisp. What I can't understand, is why e.pDisp exists if we can't cast it ? Regards, R. L.

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          GriffonRL wrote: What I can't understand, is why e.pDisp exists if we can't cast it ? the IE namespace you use once you have imported the IE web control ocx (drag&drop, add reference, ...) is actually the result of an automated type-library import which simply creates a thin wrapper around the idl interfaces. Because the IDispatch *pDisp appears in some members of some of the interfaces, it thus appears in the resulting wrapper. But as I have said already, this is a case where it's not useful : IDispatch* is seen as a raw untyped object. Furthermore, the namespace already provides interfaces from which you can invoke the methods you would with a C++ ptr on the web control. So, you don't lose power by using C# or other .NET languages. The thing you lose is that the marshaller (at the heart of all the interop stuff) is not able to comply with all kind of variant subtypes (limitation known by MS people). As long as MS doesn't fix it, whevener we import a type-library, we may or may not for any reason be able to call certain methods depending on the parameter types. That's it. We'll have to live with it. And by the way, the article I have suggested bypasses the standard tlbimp.


          She's so dirty, she threw a boomerang and it wouldn't even come back.

          G 1 Reply Last reply
          0
          • S Stephane Rodriguez

            GriffonRL wrote: What I can't understand, is why e.pDisp exists if we can't cast it ? the IE namespace you use once you have imported the IE web control ocx (drag&drop, add reference, ...) is actually the result of an automated type-library import which simply creates a thin wrapper around the idl interfaces. Because the IDispatch *pDisp appears in some members of some of the interfaces, it thus appears in the resulting wrapper. But as I have said already, this is a case where it's not useful : IDispatch* is seen as a raw untyped object. Furthermore, the namespace already provides interfaces from which you can invoke the methods you would with a C++ ptr on the web control. So, you don't lose power by using C# or other .NET languages. The thing you lose is that the marshaller (at the heart of all the interop stuff) is not able to comply with all kind of variant subtypes (limitation known by MS people). As long as MS doesn't fix it, whevener we import a type-library, we may or may not for any reason be able to call certain methods depending on the parameter types. That's it. We'll have to live with it. And by the way, the article I have suggested bypasses the standard tlbimp.


            She's so dirty, she threw a boomerang and it wouldn't even come back.

            G Offline
            G Offline
            GriffonRL
            wrote on last edited by
            #5

            Yep ! Here is the solution working with frames ;): private void documentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ SHDocVw.IWebBrowser2 Frame; IHTMLDocument3 Doc; IHTMLDOMChildrenCollection Tags; IHTMLElement Tag; int NumTags; Console.WriteLine("URL: "+e.uRL); try{ Frame=(SHDocVw.IWebBrowser2)e.pDisp; if(Frame!=null){ Doc=(IHTMLDocument3)Frame.Document; Console.WriteLine("Document URL: " (IHTMLDocument2)Doc).location.href); if(Doc!=null){ Tags=(IHTMLDOMChildrenCollection)Doc.childNodes; if(Tags!=null){ NumTags=Tags.length; for(int i=0;i Enjoy, R. L.

            S 1 Reply Last reply
            0
            • G GriffonRL

              Yep ! Here is the solution working with frames ;): private void documentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ SHDocVw.IWebBrowser2 Frame; IHTMLDocument3 Doc; IHTMLDOMChildrenCollection Tags; IHTMLElement Tag; int NumTags; Console.WriteLine("URL: "+e.uRL); try{ Frame=(SHDocVw.IWebBrowser2)e.pDisp; if(Frame!=null){ Doc=(IHTMLDocument3)Frame.Document; Console.WriteLine("Document URL: " (IHTMLDocument2)Doc).location.href); if(Doc!=null){ Tags=(IHTMLDOMChildrenCollection)Doc.childNodes; if(Tags!=null){ NumTags=Tags.length; for(int i=0;i Enjoy, R. L.

              S Offline
              S Offline
              Stephane Rodriguez
              wrote on last edited by
              #6

              I haven't run it, but I don't buy it. Why ? Not only MS clearly says in MSDN that frame events are signaled within their own frame space, but I know that there are 3 frame related events which actually get signaled on individual frames : that's FrameBeforeNavigate(dispid=200), FrameNavigateComplete(dispid=201) and FrameNewWindow(dispid=204). That said, whatever the code you have, if it does what you are looking for, then it's probably because it's fine.:cool:


              She's so dirty, she threw a boomerang and it wouldn't even come back.

              1 Reply Last reply
              0
              • G GriffonRL

                Hello, I am currently porting a webbrowser application from C++ to C#/.NET. I already struggled with the beforenavigate2 bug everybody was talking about and I can't wait for the .NET SP3. My current problem is when trying to traverse the DOM tree after a documentcomplete event. It works properly for non framed document but not for framed pages. Everytime a documentcomplete event is fired I always get the same document (the top level one). It should mean that I am always getting the same document, but I must be missing something because I don't know how to get a specific frame document. Here is the C# piece of code: private void documentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ AxSHDocVw.AxWebBrowser Frame; IHTMLDocument3 Doc; IHTMLDOMChildrenCollection Tags; IHTMLElement Tag; int NumTags; Console.WriteLine("URL: "+e.uRL); // Good frame URL try{ Frame=(AxSHDocVw.AxWebBrowser)sender; // Is it really the frame ? if(Frame!=null){ Doc=(IHTMLDocument3)Frame.Document; // Top level document ??? if(Doc!=null){ Tags=(IHTMLDOMChildrenCollection)Doc.childNodes; if(Tags!=null){ NumTags=Tags.length; for(int i=0;i Another question is: what is e.pDisp ? How to cast it ? It tried to cast it into an AxSHDocVw.AxWebBrowser and I got an error. Regards, R. L.

                A Offline
                A Offline
                Andrew Connell
                wrote on last edited by
                #7

                GriffonRL- Have you had success in trapping the navigation events in the browser? -AC

                G 1 Reply Last reply
                0
                • A Andrew Connell

                  GriffonRL- Have you had success in trapping the navigation events in the browser? -AC

                  G Offline
                  G Offline
                  GriffonRL
                  wrote on last edited by
                  #8

                  Hi, At least for DocumentComplete() it works. I also applied the "patch" to get BeforeNavigate2 events (until we get .NET SP3 :(). Everything else seems to work like in VC++/COM so far. But who knows ? I am starting with .NET and it took me 1 day to learn C# and the .NET basics. But the marshalling system was not clear and I spent 2 days on problems. Regards, R. L.

                  S 1 Reply Last reply
                  0
                  • G GriffonRL

                    Hi, At least for DocumentComplete() it works. I also applied the "patch" to get BeforeNavigate2 events (until we get .NET SP3 :(). Everything else seems to work like in VC++/COM so far. But who knows ? I am starting with .NET and it took me 1 day to learn C# and the .NET basics. But the marshalling system was not clear and I spent 2 days on problems. Regards, R. L.

                    S Offline
                    S Offline
                    Stephane Rodriguez
                    wrote on last edited by
                    #9

                    Unfortunately, there is no .NET SP3 coming this fall. .NET 1.1 is in beta, and this issue is not among the things that have been fixed (see gotdotnet.com for further details).


                    She's so dirty, she threw a boomerang and it wouldn't even come back.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups