Extended Web Browser Control for .NET 1.01.1

xiaoxiao2021-03-06  43

Project Source, EXAMPLE, HTML HELP Documentation - 348 KB Download Control Source Only - 159 KB

QuickStart

Pretty Simple: Download The Project, Run It 'Adding The Reference ActiveX Controls' IF It Doesn't Compile from Reference Issues.

Introduction

The next version of the .NET framework features a comprehensive wrapper class for the Microsoft Web Browser control - a COM control that is used by IE and is embedded into Explorer This new control features everything people are at pains to produce using COM without fishing through. Newsgroups and tech articles.

Well, I Thought It Was About Time There Was An Equivalent Control for .NET 1.0 / .NET 1.1, SO I'VE PUT MY OPEN-SOURCE APRON ON ONCE MORE, TO Produce this control.

This Control Contains The Following Features That You Do Not Get (WITHOUT DOING IT YOURSELF) with The Standard AxWebBrowser Control:

Context menu Optionally opening all links in a new window Show the find dialog Show the print dialog Show the save-as dialog Show the print preview dialog Disabling accelerator keys such as CTRL N, CTRL F and Backspace Restrict images, Java, ActiveX Stop images, sounds, videos from displaying Disable JavaScript Disable downloading / running of ActiveX and Java controls Ability to turn a 3D border on or off Turn the scrollbars on or off Make all form controls XP themed Simplified and more feature-rich navigation methods (Navigate with More Options, Refresh With Different Refresh Options.) Documentation for the Events.

In some ways, it's actually more feature-rich than the .NET 2.0 control, although the .NET 2.0 control features a security model implementation and a few other properties that will hopefully be put into WebBrowserEx during its lifetime.How is it implemented?

I'm not going to bother going into detail about how it's been implemented -.. There is a wealth of information out there on the net that explains this already See the References section for links to the places I got the information from The control is a user control with the AxWebBrowser docked to full on it. I tried to derive from AxWebBrowser, but it did not like me adding properties in, so I gave up on that method. This meant that in the control, lots of properties and events HAD TO BE RE-Implement. this Was Pretty Boring to Do, But Has Actually Made For a More Concise Control Than Having a derived class with all its activex property drooping out.

IDOCHOSTUIHANDLER AND CONTEXT MENUS

The control implements IDocHostUIHandler (see the References for what this is) which handles the context menu and key restrictions. Unlike the .NET 2.0 control, I've left the control with just a ContextMenu property. You can set this to a blank ContextMenu, EG:

MyBrowser.ContextMenu = new contextmenu ();

If you don't want the default ie context menu. in The Version 2 Control, There IS An Additional Option Menu. If The The The IE Context Menu. If There's Enough Demand for this, I'll Add It in.

The legend of the iDispatch_invoke_handler

The control also implements IOleClientSite. As before, you can read what this is in the References. The most obscure and important part of the control is the IDispatch_Invoke_Handler (). I spent quite a while trying to work out how to implement IDispatch :: Invoke in order to restrict what IE was showing (such as images, ActiveX controls, Java). I found out that if you add a IDispatch_Invoke_Handler () method in your code with the COM dispatch identifier of -5512, this does the job for you. . A very obscure answer, but it works well The options enumeration then works with this to set the options you want available in your browser.I do not believe the .NET 2.0 control has these options available; hopefully someone at MS who has ties To .NET WILL Read This and Request That it's added in, as They're Quite Core Features for the control.

WebExecwb

The control features an easier to use ExecWB method which queries the interface before executing it, fixing the "Trying to revoke a drop target that has not been registered." And similar errors. The print, save-as etc. methods, use this wrapped . call You'll find, some of the CMDID constants do nothing Welcome to the world of COM interop -. I found out whilst making this control that some of the constants Microsoft has on the MSDN site have not worked for years, and they just have not bothered updating their documentation. Some of these constants may be useable by casting the CurrentDocument to an IOleCommandTarget, and calling its Exec method (see the Find method). This is basically all that the ExecWB method does anyway, as far as I'm aware.

Flags Designer

The control implements Thierry Bouquain's designer flag editor for setting the options flags in the designer. It currently has all of its COM imports, interfaces and the flag designer editor in the single file. This makes the source a bit bulkier, but nothing that regions don 't overcome. It also makes the control more self-contained in My View.xp Service Pack 2

In XP Service pack 2, Microsoft has updated the MSHTML part of the browser so that you get more options in your NewWindow event (it's called NewWindowEvent3). I added this originally, but then realized that it would break on most people's machines due to dependency Failures. You can add it Quite Easily to the control, if you want to know how your new window was created.

Adding the Reference ActiveX Controls

WHEN You Download The Project, You Might Find The Following References Missing:

AxInterop.shdocvw.dll interop.shdocvw.dll Microsoft.mshtml.dll

I have not included these as they are operating system dependent. I'm running XP SP2, whilst you might be running Windows 2000, XP SP1 etc., so my DLLs will break with your operating system, if I included them.

TO Add Microsoft.mshtml.dll is Straight Forward; Click on The Add Reference In The Project, And Add The Following:

Adding SHDocVw is slightly strange. As far as I know, you can not add it as reference, so you have to add it into your toolbox and add it to the control's form, then remove it (something to do with the AxImp tool and VS.NET, I'm not sure what). to do this, open up the WebBrowserEx control so it's in designer mode, and then go to your toolbox, click on Add / Remove items in the context menu, and select the following from The COM TAB:

Once that's added to your toolbox, add a temporary form to the WebBrowserEx project, drop it onto the form, and then remove it. This should add it to your references. Now, do a voodoo dance and compile, and hopefully all should be well .I haven't Tried Compiling WITHOUT VS.NET, Adding The References Should Be Straight Forward Enough Though, Using The Aximp Tool with shdocvw.dll.

DOM event handlingI've added support into the control for the MSHTML document events The events allow you to capture keydown, mouseclick etc. events in the document -. Events which are not available to the browser control itself as it is just a host for the Document Parser. The Implementation I've Added Is Fairly Experimental, And Can Be Switch On Using

EnablehtmlDocumentHandling Property. Setting this to True Will Mean ALL

HtmlDocument * events are fired, however I should stress that these events tend to swallow up your key and mouse events and seem to make the form key presses and link clicking go screwy. I did not have time to work out why this was, I 'Ll Probably Have a look at it on a rainy sunday.

And finally

THE Method and Property Names in The Control Don't Match Those of The .NET 2.0 Control. Some Are The Same, Some Aren't. I Can't Really See A Scenario Where You'D Upgrade from this To the New .NET 2.0 Control, But IF this Is A Big Problem with people, i can change it.. All the...

One Small Touch I've Added to The Control Is To include The documentation from msdn for all of the events what come from axwebbrowser.

That's all. I Hope the control comes in useful.

References

HTML editor using IE, where I got a lot of the COM declarations. Sample chapter about customizing the browser. Flags designer UI editor. Work around for ExecWB inadequacies. An OLE interface. Another OLE interface. Browser overview. IDispatch_Invoke_Handler magic. Bugs with OnBeforeNavigate2 (Plus Others) in .NET 1.0. WebBrowser Customization (for A C Audience). Skinnable Tabbed Browser with Advert Blocking, Using The IE Engine.about Smallguy78

C # (winforms ASP.NET), SQL Server programmer. I also maintain (very ocassionally) my anorak website, www.sloppycode.net, when i'm not djing, making house / techno, hl2 mapping or drinking in Bristol. Click Here to View Smallguy78's Online Profile.

转载请注明原文地址:https://www.9cbs.com/read-54629.html

New Post(0)