Source: Browser Helper Objects: the browser the way you want it Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnwebgen/html/BHO. asp I. Introduction Sometimes, you may need a customized browser. In this case, you can freely add some novel but nonstandard features to a browser. As a result, you finally have a new but nonstandard browser. Web browser controls are only browser analysis engines. This means that there are still a number of work related to user interfaces Waiting For You To Do-add an address bar, toolbar, history, status bar, Channel Bar and favorites. In this way, to generate a custom browser, you can program two types-one is like Microsoft converting a web browser control into a fully functional browser such as Internet Explorer; one is to add some new functions based on the existing ones. How nice is there a direct way to customize existing Internet Explorer? BHO (Browser Helper Objects) is used to achieve this purpose.Ii. software customization Previously, the behavior of customizing a software was mainly achieved through subclass. In this way, you can change the appearance and behavior of a window. Although subclass is regarded as a somewhat violent method-the victim does not know what happened-it is still the only choice for a long time. With the advent of Microsoft Win32 API, it is increasingly difficult to subclass processes. Of course, if you are brave-Pointers never scare you, and most importantly, if you have been between system hooks, you may think this problem is too simple. But this is not always the case. The problem is that each process runs in its own address space, and it is slightly incorrect to break the process boundary. On the other hand, you may need to better manage customization. More often, customization may be implemented by the program itself. In the latter case, the installed software only needs to query another component module at the specified disk location, then load and set the initial values, and finally let them freely follow the established design work. This is exactly what the Internet Explorer browser and Its BHO need to implement. 3. What is BHO? From a certain point of view, Internet Explorer is no different from common Win32 programs. With BHO, you can write a COM object in the process, which is loaded every time it is started. Such an object will run in the same context as the browser, and can perform any action on available windows and modules. For example, a BHO can detect typical events, such as Goback, goforward, and documentcomplete. In addition, BHO can access the menu and toolbar of the browser and make modifications, you can also generate a new window to display additional information about the current webpage, and install hooks to monitor messages and actions. In short, BHO's work is like a spy that we break into the browser territory (note that this is a legal job that Microsoft allows ). Before learning more about BHO, I need to elaborate on some points. First, the BHO object depends on the browser's main window. In fact, this means that once a browser window is generated, a new BHO object instance will be generated. The lifecycle of any BHO object is the same as that of the browser instance. Second, BHO only exists in Internet Explorer 4.0 and later versions. If you are using Microsoft Windows? 98, Windows 2000, Windows 95, or Windows NT version 4.0, the Active Desktop shell 4.71 is also run, and BHO is also supported by Windows Resource Manager. BHO is a COM in-process service registered in the Registry with a single click. At startup, Internet Explorer queries the key and preloads all objects under the key. The Internet Explorer browser initializes this object and requires certain interface functions. If this interface is found, Internet Explorer uses the provided method to pass the iunknown pointer to the BHO object. The browser may find a series of CLSID in the Registry and create a process instance for each clsid. The result is that these objects are loaded into the context of the browser and run as if they were local components. However, due to the com feature of Internet Explorer, it may not be very helpful even if it is installed into its process space (your ambitious implementations. In other words, BHO can indeed do many potentially useful things, such as subclass to form a window or install local hooks on the thread, but it is indeed far away from the core activities of the browser. BHO needs to establish a private com-based communication channel to hook browser events or automated browsers. Therefore, this BHO should implement an interface called iobjectwithsite. In fact, Internet Explorer can pass its iunknown interface through the iobjectwithsite interface. BHO, in turn, can store this interface and further query more specialized interfaces, such as iwebbrowser2, idispatch, and iconnectionpointcontainer. |