Integrated browser control (UPDATE) in the application (Subject to Change without Notice)

zhaozj2021-02-12  149

Integrated browser controls in the application

Overview

What is a browser control?

The browser control is an ActiveX control that provides most of the browser features, release with Microsoft® Internet Explorer 4.0 (IE) or later. In fact, IE can think is a program for integrated browser controls.

Why use browser controls

How to provide users with rich content has always been the goal of programmers. Although a variety of interface libraries may make you dazzling, these are also a beautiful and programmer's nightmare - it is not an easy thing to customize each element on the interface, and sometimes it is more complicated. Technologies, such as the color of the scroll bar that appears in the custom program.

The emergence of browser controls makes all this simple. A simple application is to use browser controls to display rich content, just like Microsoft Outlook preview pane. You can make the art for you to make gorgeous effects, such as the gradient effect on the interface, animation GIF or Flash animation, and the top more need to write a small number of HTML code; advanced applications include displaying the entire or part of the user using the browser control Interface, such as Norton Antirse, and REAL Player use HTML to display interface, using a stacked style sheet unified interface style; use the DHTML object model to perform an interface-free web page analysis, or write a browser secondary object (BHO) from the definition browser.

I also have to talk about the possible problems of integrated browsers here, so as to consider the browser controls in the process. That is, if the browser or related module crashes, the entire program will crash. Although this is unlikely to happen, but because there are too many components / plugins loaded by the browser, there is no longer can't do it. This may also be the cause of BHO by default, the browser control will not load BHO. There are many resources that the browser occupies. This includes CPU resources and memory. At the same time, web pages may require additional resources, such as client XML parsing (9CBS ...), dynamic pictures, ActiveX controls (most of them are Flash controls). In fact, if you do not limit the URL browsing, then the common ads (usually dynamic pictures or Flash controls) on the website will greatly increase the resources occupied by the browser, especially the CPU resource. The script loaded in the browser control may cause the program to be unstable. Microsoft is recommended to disable scripts, but this will greatly reduce the practicality of the browser control, and make some advanced customizers, such as expanding DOM, become meaningless. The browser is not suitable for automated browsing. Although Microsoft puts the browser as the core of the operating system, we still see that its memory occupancy is constantly rising during the browser control constantly browsing the web. Because of this phenomenon, the use of the browser control is still as a static or man-controlled display.

getting Started

You need to create it before using the browser control. This can be done by inserting a Microsoft browser control in the dialog editor or creates a control using class ID CLSID_WEBBRowser. If you only use the control to display, then the first method is sufficient, if you need some advanced features, such as custom some features, then you need code to control the creation process of the control. Some types of libraries, such as MFCs, built-in support for browser controls (Chtmlxxxx and CDHTMLDIALOG classes), but they also make your custom browser's process while providing your access browser controls complex. In my opinion, their best use is to use examples and custom foundations for accessing browser controls.

One of the most important COM interfaces provided by the browser control is iWebBrowser2. It provides a browser's basic operational interface, and some methods of this interface, such as comparing common methods is NaviGate / NaviGate2, which makes the browser control open a target, such as a folder, a web, or a activity Documentation. You may need to effectively understand the features of the iWebBrowser2 interface to your app, you first need to have a basic understanding of the object model of both Internet Explorer and DHTML. Of course, fully explained that these models may occupy a large number of spaces, because each independent element type (, , , etc.) in the DHTML file has its own COM object class or interface. The best way to get a thorough understanding of these object model is to see some books and get a tool. Inside Dynamic HTML (Microsoft Press, 1997) is one of the best references to the DHTML object model. More technical information about the object model can be studied by studying the DHTML-related header file of the Internet Client SDK (especially mshtml.h, expdispid.h, mshtmhst.h, and mshtmdid.h). These files specify interfaces supported by various classes or objects. Unfortunately, the help documentation in the available Internet Client SDK has only a medium-level assistant, explains how to use the IWebBrowser2 interface, but there is no information about the relationship between too many objects and interfaces. Microsoft's related documents are rare, so explore the DHTML object to support those interfaces are an interesting thing. In the Microsoft Knowledge Base, you often see some DHTML objects support standard IconnectionPointContainer, IOLCOMMANDTARGET, or IOLCONTAINER interface. how is it...

Integrated browser controls using MFC

The MFC6 started support for browser controls, but advanced interfaces, such as IDochostuiHandler, to version 7.0. Writing a browser control application using the MFC is relatively simple, and users may only need a small number of code to create a program with most browser features. The disadvantage of using the MFC is a lot of bugs of these classes of MFC6, and if you want to customize some features, you need to understand the MFC's control creation process. The MFC has an MFCIE example demonstrated a simple browser program created using ChtmlView. Paul Dilascia demonstrates how to integrate ChtmlView in the dialog in MSDN Magazine, and to disable the right-click menu for browser controls.

Custom browser behavior

If you integrate browser controls in your application, you can refer to WebBrowser Customization this article. A MFC-based example can be found at http://www.beginthread.com/article/ehsan/advanced chtmlview hosting.

If you write Bho, then MSDN article Browser Helper Objects: The Browser The Way You Want IT (Dino Esposito) This article can be used to get started.

Heavy carries the default control site in the MFC

In order to implement some advanced browser host features, some interfaces are required to implement some interfaces on the same object of the control site. For example, iServiceProvider for querying the service interface provided by the host (INTMLITSECURITYMANAGER for HTML editor) and IINTERNETSECURITSECURITYMANAGER for custom IE security options and IDochostuiHandler for custom browsers and interfaces, IdochostuiHandler2 and IdochostShowui interface. Although in MFC7, CWnd :: CreateControlsite can override the creation of the control site, but in MFC6, this job is much more complicated. Microsoft Knowledge Base Article HOWTO: DISABLE THE DEFAULT POP-UP MENU for ChtmlView introduces one of the methods, but this method does not seem to be so elegant, to overwrite the default OLE container creator when starting, and the window cannot be created Other types of control sites. In fact, this is not necessary. The following MFC6 analyze the code void AFX_CDECL AfxEnableControlContainer (COccManager * pOccManager) {if (pOccManager == NULL) afxOccManager = _afxOccManager.GetData (); else afxOccManager = pOccManager;} As you can see only need to call AfxEnableControlContainer before the creation, transfer you As a parameter, the container creator is created, and then call the NULL as a parameter to reach the purpose of overwrite the default OLE container creator. This is called in ChtmlView :: Create you override. You must override this process because ChtmlView :: Create calls AFXENABLECONTROLCONTAINER (NULL). BOOL CHtmlView :: Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID, CCreateContext * pContext) {...... // assume control container has enabled AfxEnableControlContainer (); ...... FAQ

MFC6's ChtmlView's bug

When I wrote my online-page-based game, I tried to write my experience into an article (this article has been published in my column). As my first non-test use (other browsers are basically too simple, and there is such inconvenience or defects, so that I can't easily and stably use) MDI browser, I met the first problem Is to fix the BUG of the MFC (not talking about IE itself). Although the bug I have found and discovered is not too much, the amount of code used to solve these bugs is also very considerable. Most of the bugs found so far solved in the sample code in this article, although there are few spaces on these issues in the article.

Press CTRL N in the dialog of CDHTMLDialog to pop up IE

CDHTMLDialog captures DwebBrowseRevets events and forwards them to virtual functions, and does not capture dWebBrowseRevents2; so performs the default operation when pressing Ctrl N to trigger DWEBBROWSEREvents2 events - Open the new IE window. This may not be the behavior you expect. The solution is to write an EventSink yourself, you don't have to forward it to the virtual function. See Microsoft Knowledge Base Article 181845HOWTO: CREATE A SINK Interface In Mfc-Based COM ClientActiveX control Access document object model

Knowledge Base Article Q172763 INFO: Accessing The Object Model from Withnn ActiveX Control describes the solution for this problem. It can be seen that IoleClientSite is used to interact with IE this control container. You can use the IoleClientSite :: getContainer to get the Iolecontainer interface of the HTML document object where the web is located, then query other interfaces, such as IHTMLDocument2 to perform access to the DHTML object model.

Create and manipulate IE browser

You can use CocreateInstance to create a browser object, using the CLSID is CLSID_INTERNETEXPLORER. After the creation is successful, you can query other interfaces of the browser object, such as IWebBrowser2, IoleObject, and more.

Analyze web pages and automatic submission web forms

I often have problems, but the webpage is muting, it is not easy to write a general purpose. The general application is first to remove the article on the MSDN Chinese Station.

How do I call a function in Script in the web page?

The IHTMLDocument2 :: Scripts property represents all script objects in the HTML document. Use the IDispatch interface of the script object :: getidsofnames method can "find the functions and object members, using idispatch :: Invoke to access these members.

reference

INSIDE OLE, Second Edition, Kraig Brockschmidt (Microsoft Press) Understanding ActiveX and Ole, David Chappell (Microsoft Press) Inside COM, by Dale Rogerson (Microsoft Press)

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

New Post(0)