Microsoft KB Archive/320940

= SAMPLE: PictureDownload.exe Enables Population of an ImageList with URLs =

Article ID: 320940

Article Last Modified on 5/11/2006

-

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:

Download PictureDownload.exe now

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:

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 &quot;References&quot; 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  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  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&quot;Cannot download picture: The URL specified is not valid, or is not an absolute URL. PictureDownload only accepts absolute URLs as arguments.&quot;, __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(&picDisp)); if (FAILED(hr)) { if (E_NOINTERFACE == hr) { Error(L&quot;Cannot download picture: URL does not specify a valid picture file. Please reference BMP or ICO files only.&quot;, __uuidof(IPictureDownload), E_FAIL); } else if (FACILITY_INTERNET == HRESULT_FACILITY(hr)) { Error(L&quot;Cannot download picture: Site cannot be reached, or resource does not exist.&quot;, __uuidof(IPictureDownload), E_FAIL); } else { Error(L&quot;Cannot download picture: Generic failure.&quot;, __uuidof(IPictureDownload), E_FAIL); }       goto cleanup; }   hr = picDisp->QueryInterface(IID_IDispatch, reinterpret_cast(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  tag of the ImageList. You must first include an  tag for your own component:   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(&quot;http://localhost/PictureDownloadProj/picture.bmp&quot;) myImageList.ListImages.Add 1, &quot;Pic1&quot;, pic set pic = PictureDownload.DownloadPicture(&quot;http://localhost/PictureDownloadProj/picture2.bmp&quot;) myImageList.ListImages.Add 2, &quot;Pic2&quot;, pic set pic = PictureDownload.DownloadPicture(&quot;http://localhost/PictureDownloadProj/picture3.bmp&quot;) myImageList.ListImages.Add 3, &quot;Pic3&quot;, pic From there, you can load nodes in your TreeView and associate images with the nodes: ' Initialize tree. Set node = TreeView1.Nodes.Add(,,&quot;KEY1&quot;, &quot;Test1&quot;) node.expanded=true node.Image=1

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

Set node = TreeView1.Nodes.Add(&quot;KEY1&quot;,4,&quot;KEY3&quot;, &quot;Test1-2&quot;) 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:

Internet Component Download

http://msdn.microsoft.com/library/default.asp?url=/workshop/delivery/download/overview/entry.asp

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.

