.net - WPF WebBrowser: How I do access progress and new window events -


i'm building wpf app uses webbrowser control.
i'm struggling on couple of points:

  1. how current progress of download control. winforms webbrowser control raises progresschange events - how can replicate feature wpf variant?

  2. how capture links trying open in new window. again winforms webbrowser had newwindow event. use stop ie being started , open link in same window. possible wpf variant?

having found information wanted thought i'd update question interested.

at bottom of http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser(v=vs.90).aspx there comment entitled "getting native iwebbrowser2".

this shows how required interface , seems works well.

edit: adding content of link here comments @ msdn keep disappearing on me..

there functionality of native web browser control our managed wrapper not yet expose. following code snippet shows how iwebbrowser2 interface wpf webbrowser control. allows access methods on object not publicly exposed in other ways control. note, however, code sample work in trusted code.

first, see iwebbrowser2 documentation here: http://msdn.microsoft.com/en-us/library/aa752127.aspx ...

to compile code, add com reference system32\shdocvw.dll or ieframe.dll (whichever have, depending on version of ie).

[comimport, interfacetype(cominterfacetype.interfaceisiunknown)] [guid("6d5140c1-7436-11ce-8034-00aa006009fa")] internal interface iserviceprovider {     [return: marshalas(unmanagedtype.iunknown)]     object queryservice(ref guid guidservice, ref guid riid); }  static readonly guid sid_swebbrowserapp =        new guid("0002df05-0000-0000-c000-000000000046");  // ...  iserviceprovider serviceprovider = (iserviceprovider)mywebbrowser.document; guid serviceguid = sid_swebbrowserapp;  guid iid = typeof(shdocvw.iwebbrowser2).guid;  shdocvw.iwebbrowser2 mywebbrowser2 =    (shdocvw.iwebbrowser2) serviceprovider.queryservice(ref serviceguid, ref iid); 

and mywebbrowser2 ready interaction.

you can handle native web browser's events (http://msdn.microsoft.com/en-us/library/aa768309(vs.85).aspx) through generated managed wrappers, this:

shdocvw.dwebbrowserevents_event wbevents = (shdocvw.dwebbrowserevents_event)mywebbrowser2; wbevents.newwindow += new shdocvw.dwebbrowserevents_newwindoweventhandler(onwebbrowsernewwindow);  void onwebbrowsernewwindow(string url, int flags, string targetframename, ref object postdata, string headers, ref bool processed) {     // set processed cancel opening of new window. } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -