Site Map Contact Us Home
E-mail Newsletter
Subscribe to get informed about
Clever Components news.

Your Name:
Your Email:
Previous Newsletters

Products Articles Downloads Order Support
Customer Portal      

Sample with Clever VCL Downloader

Return to contents

This tutorial explains how to add an entry into the standard context menus in Microsoft Internet Explorer that initiates the URL downloading process from the browsed web page.

Often developers, making applications for browsing and viewing web-documents, want to extend the functionality of their program. The user interface will be more friendly and convenient if you add the ability to access your downloader program from different places when it is necessary, for instance, from the Internet Explorer context menu.

To extend the functionality of the standard context menu you need basic knowledge of the Windows Registry and the Windows Shell Extension API. The main idea is to link a new menu item to the URL, which contains an executable script.

Let us look at the implementation of the downloader program by using the TclMultiDownloader component from the Internet Components - Clever Internet Suite library. To allow the scripting host access to the component's functions we must create a simple local com-server application. The following steps help you create such an application:

  • Create a new Delphi project.
  • Add to the project the type library of the local server to be, which exports only one simple function, AddURL.
    This function has one parameter, URL which will be downloaded. Type Library for VCL Sample.
  • Implement the interface from the type library which was created earlier.

To implement our interface, let us write the following code:

   Tcl_download_url = class(TAutoObject, Icl_download_url)
      procedure AddURL(const AURL: WideString); safecall;
   TAutoObjectFactory.Create(ComServer, Tcl_download_url, CLASS_cl_download_url, ciMultiInstance);

Next, add a new form to our project that allows us to visualize the downloading process. Also we place the ListBox component for displaying the URL list and next, place and setup the TclMultiDownloader component.

After that, we can write the body of the AddURL function:

procedure Tcl_download_url.AddURL(const AURL: WideString);
   Item: TclInternetItem;
   Item := Form1.clMultiDownLoader.DownLoadList.Add();
   Item.URL := AURL;
   Form1.ListBox.Items.Add(Item.URL + ' - ' + Item.LocalFile);

In this case, to make things easier, we assume the form is created automatically and we can use it via the global variable, Form1.

Now the com-server is ready and its interface is accessible for the scripting host. Next, we should create an HTML document with executable script and link it to the explorer context menu. In the easiest case the script can look like this:

<script language="VBScript">
   Set cl_popup = CreateObject("explorerpopup.cl_download_url")
   Set links = external.menuArguments.document.links
   For i = 0 to links.length - 1
      cl_popup.AddURL links(i).href

The instance of our com-server is created inside this script and then, it performs a loop through all links within the currently browsed document. While walking, each link is added to our facility to download.

To link the script to the context menu, we should add new records into the HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt registry key:

Key: Download &All using Clever Downloader
Default value: file://c:\samples\cl_download_all.htm
DWORD value contexts: 000000f3

You can learn more about setup of the Microsoft Internet Explorer context menu from the MSDN Library and Microsoft online-resource - MSDN.

After accomplishing all these steps, we will have flexible and convenient facility to operate remote resources. Your application will be used only it is really necessary.

Finally we want to note that you should register the ActiveX server in your system in order that our test example should work properly. To do that you can just run it as a usual EXE application only once.

The full version of this example can be downloaded here.

Clever Components Support Team.
Please feel free to Contact Us
We are always glad to help you.

    Copyright © 2000-2021