Browser Helper Object


Browser Helper Object
 
 
In order to attach to a running instance of Internet Explorer, you can use a "Browser Helper Object." A "Browser Helper Object"is a DLL that will attach itself to every new instance of Internet Explorer. You can use this feature to gain access to the object model of a particular running instance of Internet Explorer. You can also use this feature to get events from an instance of Internet Explorer.
IEBROWSERHELPER demonstrates how to create and register a Browser Helper Object in Delphi, and how to establish a two-way communication between IE and the Helper Object.Internet Explorer 5.0 problem
Only a single Browser Helper Object (BHO) registered will load with Internet Explorer 5.0, because of an internal buffer problem. Subsequent loads of other registered BHOs fail without apparent error.
Microsoft has confirmed this to be a bug. This problem was corrected in Microsoft Internet Explorer version 5.01.Depending on whether the operating system is Windows 95 and Windows 98 or Windows NT, the BHO that is loaded may be different. On Windows NT, the BHO with the lowest CLSID will be loaded. On Windows 95 and Windows 98, the BHO that was the first registered will be loaded.You can make the use of your BHO more safe, if you during registering of the BHO check for IE-version and give some kind of warning to the user, if IE 5.0 is found. 
 
Some ideas for use of Browser Helper Object:a. Programatically activate an Explorer Bar.
If you have created an explorer bar you perhaps want to be able to automatically display the Explorer Bar when the user starts a new instance of Internet Explorer. 
It is easily done with a Browser Helper Object. You only need to implement IObjectWithSite. Return S_OK in  method GetSite and add the following lines in method SetSite:

function TIEBrowserHelper.SetSite(const pUnkSite: IUnknown): HResult;
var
  vaClsID, vaEnabled, vaDummy: Olevariant;
begin
  vaCLSID := '{30D02401-6A81-11D0-8274-00C04FD5AE38}';
  vaEnabled := True;
  vaDummy := 0;
  (pUnkSite as IWebbrowser2).ShowBrowserBar(vaCLSID, vaEnabled, vaDummy);
  Result := S_OK;
end;


vaCLSID is the Class Identifier for the explorer bar you want to automatically display. The CLSID shown is for the standard Search Bar. 
If you create an application with a BHO to activate a vertical Explorer bar each time a new instance of Internet Explorer is created and another programmer do the same and both applications are installed on the same computer, one of you definetely have a problem, since IE only can display one vertical explorer bar.
Internet Explorer loads all BHO registered and in this case the last BHO loaded is having its explorer bar displayed. On Windows 95/98 the last BHO registered will be the last loaded, but on other versions of Windows is depending on the Class Identifiers. They are loaded in ascending order, so if your randomly created Clsid_YourBHO begins with something like "FFFF-..."you are a lucky programmer and almost certain that your BHO is loaded as the last one and your Explorer Bar activated.
b. Popup-killers
Browser helper object is an excellent place to avoid annoying popup-windows from ever being displayed. Here is a simple one-line popup-killer:

procedure DoBeforeNavigate2(const pDisp: IDispatch; 
   var URL: OleVariant; var Flags: OleVariant; var TargetFrameName: OleVariant; 
   var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool);
begin
 if IE.Toolbar=0 then IE.Quit;
end;

If the window about to be displayed does not have a toolbar then kill it! It is simple, but it works. The code could be extended to evaluate the size of the window, the title and url before deciding  to show or destroy it. 
C. Download Managers
Starting with IE 5.5 a new event OnFileDownload was added to DWebbrowserEvents2. It makes it even easier to let your BHO decide the action, when a user wants to start downloading of a file. The event is called just before showing the Download-dialog in IE. Returning Cancel=True will terminate the download-process and prevent the dialog from being showed. You can now let your  download-manager take over the downloading. (For some strange reasons OnFileDownload is called when a new instance of IE is started. You need to handle this, otherwise your application will freeze.)
In older versions of IE you will need to check for the file-extensions in OnBeforeNavigate. If it is "*.exe", "*.zip"etc. you can cancel the navigation and start your download-manager.
 
Enjoy!  
Download Browser Helper Object 1.01
Browser Helper Object v. 1.01  for Delphi 4/5
Links:Attachment to Internet Explorer using Helper Browser ObjectsControlling Internet Explorer 4 with Browser Helper ObjectsBrowser Helper Objects: The Browser the Way You Want itOnly One Browser Helper Object Will Load with Internet Explorer 5 HOWTO: Programmatically Activate an Explorer Bar

좋은 웹페이지 즐겨찾기