Introduction
One of our clients approached us with an idea to create a commercial toolbar for Internet Explorer. The idea was simple – it was necessary to implement a toolbar for Internet Explorer 7.0 containing the following elements:
- company logo;
- search field, allowing to send a search request to an arbitrary site and display the results in the browser;
- expand buttons, containing arbitrary number of links;
- drop-down lists displaying RSS-channels.
We started to work on this task and started with a choice of a platform. As it turned out, it is not a simple thing to make a toolbar for Internet Explorer with a declared functionality. It is necessary to deal with Com-components, interact with the browser and store cashed data somewhere. Fortunately, it appeared that it is possible to do everything on the .NET 2.0. platform, which simplified the task a lot.
The result of our work is given below – it is the IEToolbarEngine component, presenting high level interface for toolbars and its elements creation. Perhaps, this component will allow you to implement your own toolbars or you will find some useful data for the implementation of your own projects in the MS Visual Studio environment in the description of this device.
Usage
IEToolbarEngine
is inherited from BandObject
component, written by Pavel Zolnikov and described in the article “Extending Explorer with Band Objects using .NET and Windows Forms.” We modified it so it would be possible to build our toolbar in Internet Explorer. After that, we wrote a small library of classes enabling to add different elements into the toolbar.
If to speak generally, the toolbar presents itself UserControl
with the System.Windows.Forms.ToolStrip
component placed on it. At the loading of this control, the CreateToolbarItems
function is activated, which should be paid great attention, as the main initialization of a toolbar elements happen in it. You can bring changes into it for the creation of your own toolbar. Its fragment is given below.
internal void CreateToolbarItems ()
{
try
{
…
Assembly currentAssembly = Assembly.GetAssembly( this.GetType() );
Link link1 = new Link("Home page", "http://kbsoft-group.com/");
Link link2 = new Link("Clear Search History",
IEToolbarEngine.WrapInternalCommand(IEToolbarEngine.cmdClearHistory));
Image img = Image.FromStream( currentAssembly.GetManifestResourceStream(
"IEToolbarEngine.main.png") );
menu = new MainMenu( this, "Company", "Main",
new Link[] { link1, link2 }, img);
items.Add (menu);
…
}
}
A creation of one toolbar element is demonstrated here, this element contains a logo and a brief drop-down menu. An item is created with the help of the MainMenu
class. Two links and an image are added to it. The classes diagram displaying a simple architecture of toolbar elements is given below:
A created element will look like that:
Title text, tips, array of links (KeyValuePair<string, string>
class objects, where Key -- menu item text and value -- link for transfer with a click on it) and a link to the image received from the assembly resources are given to the MainMenu
class constructor.
Let us note, for those who are curious, that name of a resource embedded into the assembly is formed from the default namespace name, and from the resource name itself (hence, the line IEToolbarEngine.main.png
).
After a creation, it is necessary to add a new element into the collection of IEToolbarEngine
Items class.
Creation of several elements is demonstrated in the IEToolbarEngine
project attached to this article. Lets view them in consequence.
SearchBoxItem
new SearchBoxItem (this, "<clear>", "terms to serach!",
"http://www.google.ru/search?q={0}",
"Search here", "Search", "Click to search",new Size (160, 16),
FlatStyle.System, img);
The SearchBoxItem
class presents itself a search line with a button starting the search. The line can navigate to an arbitrary site supporting a search with parameters specified in GET request.
The following parameters are specified to the constructor: link to the IEToolbarEngine
class, a line which will be displayed in combobox for item of search history clearing, prompt line, search line, pop-up prompt line, text on search button, search field size, its style and a link to the image for search button. This element will look like that:
A few words about search line format. There is a q={0}
parameter in it. Here q
is parameter name, used in your search query, and {0}
will be automatically substituted to the line which a user enters into search line. If there is another parameter name in your search query, it should be staned instead of q
.
LinkListItem
LinkListItem(this, "Advantages", "Advantages",
new Link[] { link1, link2, link3, link4 }, img);
Simple list with links. Constructor parameters -- link to IEToolbarEngine
class, button text, tooltip text, massive of elements. The exterior is shown below:
RssTicker
RssTicker(this, "RSS", "RSS Channel",
"http://www.euro2008.uefa.com/rss/index.xml", 1440, img, "RSSChannel");
This element presents itself a list of links received from an RSS feed. For that, a link to RSS-feed and a period of channel update is given to a constructor. The string – a unique name of RSS-channel, which will be used for creation of a cash-file in the application folder in "Application Data\IEToolbar\Cache", should be transmitted the last.
The resulting element looks like that:
Installation Project
Also, the demo project contains an installation project IEToolbarInstallation
, generating a Setup.exe file, which allows you to install the toolbar to the user machine and delete it if necessary. It is created by the means of MS Visual Studio. The moments, connected with the implementation of an installation project which should be paid attention to, are given below.
There is a IEToolbarInstaller
class, derived from System.Configuration.Install.Installer
in the toolbar assembly (IEToolbar.dll, is created by the IEToolbarEngine project). In order to show the installer that this class method should be started in the process of the installation, it is marked by the RunInstallerAttribute
attribute. Install
and Uninstall
methods are overriden in it. Install
implements a registration of a build as COM-server. Uninstall
, correspondingly, cancels its registration.
RegisterAssembly
function of class RegistrationServices
is used for registration. It is necessary to note, that this assembly is not installed in GAC, that is why registration should be implemented with the AssemblyRegistrationFlags.SetCodeBase
key. For that, it is necessary for the assembly to be strongly named, otherwise, registration can go in a wrong way.
The installer is given a directive to search this class in the build at the installation and start its actions Install
and Uninstall
. For that, a new action is added into a "Custom Actions" section in the project, for which, IEToolbr.dll file of a build is selected in the "custom action source" field.
Basics for the IEToolbarEngine
class BandObject
contains Register
and Unregister
functions. Register
is started in the process of registration and executes adding of keys, necessary to embed the toolbar into Internet Explorer, into the windows register. Unregister
is started at the installation and deletes the information, connected with the toolbar, from the windows register.