SAMPLE: PictureDownload.exe Enables Population of an ImageList with URLs (320940)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5 SP2

This article was previously published under Q320940

SUMMARY

The PictureDownload.exe sample demonstrates how you can restore to your Web pages the ImageList functionality that is lost after you apply the Security Update Q313675.

The sample in this article applies to Internet Explorer that runs on Microsoft Windows 98, Microsoft Windows NT 4.0 SP6a and later, Microsoft Windows 2000 SP3 and later, and Microsoft Windows XP.

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
Release Date: June 26, 2002

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The PictureDownload.exe file contains the following files:
File nameSize
_PictureDownloadProj.h11 KB
_PictureDownloadProj.tlb3 KB
_PictureDownloadProj.idl2 KB
dlldata.c1 KB
picture.bmp406 bytes
picture2.bmp406 bytes
picture3.bmp406 bytes
PictureDownload.cpp2 KB
PictureDownload.h4 KB
PictureDownload.htm2 KB
PictureDownloadProj.aps4 KB
PictureDownloadProj.cpp1 KB
PictureDownloadProj.ncb2 KB
PictureDownloadProj.rc3 KB
PictureDownloadProj.rgs1 KB
PictureDownloadProj.sln2 KB
PictureDownloadProj.suo9 KB
PictureDownloadProj.vcproj4 KB
PictureDownloadProjps.def1 KB
PictureDownloadProjPS.vcproj4 KB
Readme.txt4 KB
Resource.h1 KB
stdafx.cpp1 KB
stdafx.h2 KB
PictureDownloadVC6/dlldata.c1 KB
PictureDownloadVC6/dlldatax.c2 KB
PictureDownloadVC6/dlldata.h1 KB
PictureDownloadVC6/pictured.bmp407 KB
PictureDownloadVC6/PictureDownload.cpp3 KB
PictureDownloadVC6/PictureDownload.h4 KB
PictureDownloadVC6/PictureDownload.htm2 KB
PictureDownloadVC6/PictureDownload.rgs1 KB
PictureDownloadVC6/PictureDownloadVC6.aps5 KB
PictureDownloadVC6/PictureDownloadVC6.cpp4 KB
PictureDownloadVC6/PictureDownloadVC6.def1 KB
PictureDownloadVC6/PictureDownloadVC6.dsp14 KB
PictureDownloadVC6/PictureDownloadVC6.dsw1 KB
PictureDownloadVC6/PictureDownloadVC6.h8 KB
PictureDownloadVC6/PictureDownloadVC6.idl1 KB
PictureDownloadVC6/PictureDownloadVC6.plg4 KB
PictureDownloadVC6/PictureDownloadVC6.rc4 KB
PictureDownloadVC6/PictureDownloadVC6.tlb2 KB
PictureDownloadVC6/PictureDownloadVC6_i.c2 KB
PictureDownloadVC6/PictureDownloadVC6_p.c2 KB
PictureDownloadVC6/PictureDownloadVC6ps.def1 KB
PictureDownloadVC6/PictureDownloadVC6ps.mk1 KB
PictureDownloadVC6/resource.h1 KB
PictureDownloadVC6/StdAfx.cpp1 KB
PictureDownloadVC6/StdAfx.h1 KB

NOTE: The main directory of the uncompressed sample is a Microsoft Visual C++ .NET project. The subdirectory PictureDownloadVC6 contains the same code, except in a Visual C++ 6.0 project. Security Update Q313675 disables a feature that is known as Inline Data in Internet Explorer. You can use the Inline Data feature to allow base64-encoded binary data to be assigned to an ActiveX control. However, you may have already written Web pages that use the TreeView control and the ImageList control as described in the Microsoft Knowledge Base article Q184975 that is listed in the "References" section of this article.

In this sample, the images of the ImageList control are loaded by encoding all of the images in base64. Then you can assign the later string to the DATA attribute of the <OBJECT> tag of the ImageList. This is the feature that Security Update Q313675 disables. However, you can easily develop a small ActiveX control that fetches .bmp images and then returns the IDispatch pointer from the IPictureDisp image, which is the COM/OLE interface that ImageList requires to add an image. This workaround has two advantages:

  • Much of your existing Dynamic Hypertext Markup Language (DHTML) code that uses the TreeView control can be preserved. You can easily add some additional lines to load the ImageList. You can also insert an <OBJECT> tag for the PictureDownload ActiveX control.
  • You can load your images if you use URL references. This feature is missing from the ImageList control.

PictureDownload.dll

PictureDownload.dll defines a simple ActiveX control with a single external method, DownloadPicture, which takes a URL reference to an image and returns an IDispatch. You can do this if you use the COM function OleLoadPicturePath as shown in the following sample:
STDMETHODIMP CPictureDownload::DownloadPicture(BSTR url, IDispatch **pictureRet) {
	HRESULT hr = S_OK;
	IPictureDisp *picDisp = NULL;

	// Verify that this is a valid absolute URL.
	// !TODO: Allow consumers to specify virtual and relative paths also. 
	*pictureRet = NULL;
	if (S_FALSE == IsValidURL(NULL, url, 0)) {
		Error(L"Cannot download picture: The URL specified is not valid, or is not an absolute URL. PictureDownload only accepts absolute URLs as arguments.", __uuidof(IPictureDownload), E_FAIL);
		// S_FALSE will not throw a script error.
		hr = E_FAIL;
		goto cleanup;
	}

	hr = ::OleLoadPicturePath(url, NULL, 0, 0, IID_IPictureDisp, reinterpret_cast<void **>(&picDisp));
	if (FAILED(hr)) { 
		if (E_NOINTERFACE == hr) {
			Error(L"Cannot download picture: URL does not specify a valid picture file. Please reference BMP or ICO files only.", __uuidof(IPictureDownload), E_FAIL);
		} else if (FACILITY_INTERNET == HRESULT_FACILITY(hr)) {
			Error(L"Cannot download picture: Site cannot be reached, or resource does not exist.", __uuidof(IPictureDownload), E_FAIL);
		} else {
			Error(L"Cannot download picture: Generic failure.", __uuidof(IPictureDownload), E_FAIL);
		}
		goto cleanup;
	}
	hr = picDisp->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(pictureRet));

cleanup:
	if (NULL != picDisp) {
		picDisp->Release();
	}
	return hr;
}
				

PictureDownload.htm

After you compile the component, you must instrument your HTML file to load the ImageList from the PictureDownload component instead of from the DATA attribute of the <OBJECT> tag of the ImageList. You must first include an <OBJECT> tag for your own component:
<OBJECT ID="PictureDownload" CLASSID="CLSID:A6A7F245-14DF-4050-82E2-C9FD65AC4DD7" style="display:none;">
</OBJECT>
				
You must use the following code to download the images files from PictureDownload, one at a time, and then add the images files to the ImageList:
	' Load up images.	
	set pic = PictureDownload.DownloadPicture("http://localhost/PictureDownloadProj/picture.bmp")
	myImageList.ListImages.Add 1, "Pic1", pic
	set pic = PictureDownload.DownloadPicture("http://localhost/PictureDownloadProj/picture2.bmp")
	myImageList.ListImages.Add 2, "Pic2", pic
	set pic = PictureDownload.DownloadPicture("http://localhost/PictureDownloadProj/picture3.bmp")
	myImageList.ListImages.Add 3, "Pic3", pic
				
From there, you can load nodes in your TreeView and associate images with the nodes:
	' Initialize tree.
	Set node = TreeView1.Nodes.Add(,,"KEY1", "Test1")
	node.expanded=true
	node.Image=1

	Set node = TreeView1.Nodes.Add("KEY1",4,"KEY2", "Test1-1")
	node.expanded=true
	node.Image=2

	Set node = TreeView1.Nodes.Add("KEY1",4,"KEY3", "Test1-2")
	node.expanded=true
	node.Image=3
				

Deploy PictureDownload

To deploy the PictureDownload method, you must create a cabinet (.cab) file for the Internet Component download. If you use the Microsoft Visual C++ .NET project, you can use the Cabinet Project type under Setup and Deployment Project.

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
To use the .cab file on your Web page, visit the following Microsoft Web site: NOTE: The DownloadPicture method accepts absolute URL inputs only. If an error occurs you must verify that the URL passed to the function is a valid URL.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

317599 ActiveX Inline Data Streaming Functionality Is Disabled After You Install the Q313675 Security Patch

313675 MS01-058: File Vulnerability Patch for Internet Explorer 5.5 and Internet Explorer 6

184975 BUG: Setting TreeView1.ImageList Causes Err in Internet Explorer

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbdownload kbfile kbinfo KB320940