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. how to control web components in winform by embeding a browser(ie)

how to control web components in winform by embeding a browser(ie)

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 4 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.
  • N Offline
    N Offline
    nakey_yang
    wrote on last edited by
    #1

    :confused:in my windows application,i embeded a web browser,by this method we can show web component.But i want control this component such as draw to a new position.How can i do this.Help :)

    L H 3 Replies Last reply
    0
    • N nakey_yang

      :confused:in my windows application,i embeded a web browser,by this method we can show web component.But i want control this component such as draw to a new position.How can i do this.Help :)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think you can create a solution consist's of web service project and control project which reference the web service project and get's the information you need from it every period of time try it .... Mhmoud Rawas ------------ Software Eng.

      1 Reply Last reply
      0
      • N nakey_yang

        :confused:in my windows application,i embeded a web browser,by this method we can show web component.But i want control this component such as draw to a new position.How can i do this.Help :)

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        If you're hosting the IWebBrowser2 interface, you can use the MSHTML hosting interfaces like IDocHostUIHandler (see the PSDK for more details). This and several other hosting interfaces give you control over context menus, object placement and drawing, and much more functionality. To implement IDocHostUIHandler (which pretty much sets everything else up), you must either redefine the interface in .NET (making sure to use the right GUID...or another technique which I'll link to later) and implement that on your class. You can QI (or cast in .NET) the WebBrowser control (or an IHTMLDocument* interface) to ICustomDoc and call SetUIHandler, passing a reference to your implementation of IDocHostUIHandler (but that only lets you use UI customization methods), or implement IOleClientSite. The WebBrowser control will QI for this interface on the host (you) and make calls to the IDocHostUIHandler for all methods. You can read more about hosting the WebBrowser control and MSHTML by looking at http://msdn.microsoft.com/workshop/browser/prog_browser_node_entry.asp[^].

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        J 1 Reply Last reply
        0
        • N nakey_yang

          :confused:in my windows application,i embeded a web browser,by this method we can show web component.But i want control this component such as draw to a new position.How can i do this.Help :)

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Oh, about those other links: rather than manually defining all the interfaces, you can use a technique that described in this article: http://www.codeproject.com/csharp/advhost.asp[^] You create an IDL file (used in COM programming) to forward-define interfaces and compile that to a typelib (TLB). Then you use the tlbimp.exe utility in the .NET SDK to create an interop assembly out of that. Now you're got your interfaces defined correctly and just have to implement them! A word of caution, though: all the methods return void. Some methods require that you return S_FALSE in COM, which is still a success code. Since the return type is void, you can't return anything and you can't use a COMException because that creates an error state. In these cases, you will have to define the interface yourself and for those methods make them return an int and add the PreserveSignature=true property statement to the MarshalAsAttribute that you must add to the method. Also, another helpful article here on CP is a book excerpt: http://www.codeproject.com/books/0764549146_8.asp[^] These are both pretty good, but I still recommend you read that link I gave you to MSDN. It's the best way to learn about hosting the WebBrowser control or MSHTML.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          J 1 Reply Last reply
          0
          • H Heath Stewart

            Oh, about those other links: rather than manually defining all the interfaces, you can use a technique that described in this article: http://www.codeproject.com/csharp/advhost.asp[^] You create an IDL file (used in COM programming) to forward-define interfaces and compile that to a typelib (TLB). Then you use the tlbimp.exe utility in the .NET SDK to create an interop assembly out of that. Now you're got your interfaces defined correctly and just have to implement them! A word of caution, though: all the methods return void. Some methods require that you return S_FALSE in COM, which is still a success code. Since the return type is void, you can't return anything and you can't use a COMException because that creates an error state. In these cases, you will have to define the interface yourself and for those methods make them return an int and add the PreserveSignature=true property statement to the MarshalAsAttribute that you must add to the method. Also, another helpful article here on CP is a book excerpt: http://www.codeproject.com/books/0764549146_8.asp[^] These are both pretty good, but I still recommend you read that link I gave you to MSDN. It's the best way to learn about hosting the WebBrowser control or MSHTML.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            Heath Stewart wrote: A word of caution, though: all the methods return void. Some methods require that you return S_FALSE in COM, which is still a success code. Since the return type is void, you can't return anything and you can't use a COMException because that creates an error state. Actually, I've successfully done this in the IDocHostUIHandler.TranslateAccelerator method. The way I know I was successful is that it no longer "ate" all keyboad messages that were sent to the WebBrowser control. But yes, it's better to re-define the interface.

            throw new System.Runtime.InteropServices.COMException("S_CANCEL - No custom handling",1);

            **"Have a heart that never hardens, a temper that never tires, a touch that never hurts." -- Charles Dickens

            FLUID UI Toolkit | FloodFill in C# & GDI+**

            1 Reply Last reply
            0
            • H Heath Stewart

              If you're hosting the IWebBrowser2 interface, you can use the MSHTML hosting interfaces like IDocHostUIHandler (see the PSDK for more details). This and several other hosting interfaces give you control over context menus, object placement and drawing, and much more functionality. To implement IDocHostUIHandler (which pretty much sets everything else up), you must either redefine the interface in .NET (making sure to use the right GUID...or another technique which I'll link to later) and implement that on your class. You can QI (or cast in .NET) the WebBrowser control (or an IHTMLDocument* interface) to ICustomDoc and call SetUIHandler, passing a reference to your implementation of IDocHostUIHandler (but that only lets you use UI customization methods), or implement IOleClientSite. The WebBrowser control will QI for this interface on the host (you) and make calls to the IDocHostUIHandler for all methods. You can read more about hosting the WebBrowser control and MSHTML by looking at http://msdn.microsoft.com/workshop/browser/prog_browser_node_entry.asp[^].

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              J Offline
              J Offline
              J Dunlap
              wrote on last edited by
              #6

              Heath Stewart wrote: You can QI (or cast in .NET) the WebBrowser control (or an IHTMLDocument* interface) to ICustomDoc and call SetUIHandler, passing a reference to your implementation of IDocHostUIHandler (but that only lets you use UI customization methods) Just to give a quick example:

              ICustomDoc cDoc = (ICustomDoc)webBrowser.Document;
              cDoc.SetUIHandler((IDocHostUIHandler)this);

              There's something I'd like to warn people about with the WebBrowser control. I replaced the default context menu for the WebBrowser, but whenever my context menu closed (after an item was clicked), the next item on the default context menu was executed, even though it never appeared. I was just about at my wit's end when I realized that the context menu must be sending something back to the window it was shown on behalf of - the WebBrowser control - and it was executing the default menu's commands. Changing the window passed into the context menu to the form instead of the WebBrowser solved the problem.

              **"It is appallingly obvious that our technology exceeds our humanity." -- Albert Einstein

              FLUID UI Toolkit | FloodFill in C# & GDI+**

              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