Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

SAMPLE: TreeViewWrapper.exe Provides Another Option to ImageList and Inline Data in Internet Explorer


View products that this article applies to.

This article was previously published under Q320868

↑ Back to the top


Summary

The TreeViewWrapper.exe sample provides another option to using inline data with the ImageList control, a feature that is turned off in Q313675 Security Patch, by encapsulating both the TreeView control and the ImageList control inside a Visual Basic 6.0 ActiveX control (or UserControl object). A public method on the UserControl permits images to be fetched as a batch from an XML file that is located on the Web server. This wrapper also allows population of the TreeView from Microsoft JScript. The population of the TreeView is a nontrivial operation with a TreeView that is not encapsulated because JScript does not support optional arguments.

↑ Back to the top


More information

The following file is available for download from the Microsoft Download Center:
Release Date: September 9, 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 TreeViewWrapper.exe file contains the following files:

Collapse this tableExpand this table
File nameSize
Images.xml1 KB
picture.bmp406 bytes
picture2.bmp406 bytes
picture3.bmp406 bytes
TreeViewWrapper.CAB16 KB
TreeViewWrapper.exp2 KB
TreeViewWrapper.HTM2 KB
TreeViewWrapper.lib3 KB
TreeViewWrapper.ocx32 KB
TreeViewWrapper.PDM4 KB
TreeViewWrapper.vbp1 KB
TreeViewWrapper.vbw1 KB
TreeViewWrapperCtl.ctl7 KB


Q313675 Security Patch turns off a feature in Internet Explorer known as Inline Data, which permits base64-encoded binary data to be assigned to an ActiveX control. However, you may have written Web pages that use the TreeView control and the ImageList control as directed by the following article:
BUG: Setting TreeView1.ImageList Causes Err in Internet Explorer
184975� BUG: Setting TreeView1.ImageList Causes Err in Internet Explorer

In the sample, you can load the images of the ImageList control if you encode all images in base64, and then assign the string after that to the DATA attribute of the OBJECT tag of the ImageList. This procedure is the feature that is turned off by Q313675 Security Patch.

You can develop a control that encapsulates both the TreeView control and the ImageList control, and then loads the ImageList from an XML-based list of Uniform Resource Locator (URL) image references. The object requires that any script that is written against the raw TreeView control must be rewritten, but the required functionality of the TreeView is preserved, while the object also adheres to the new provisions that are introduced by the security patch.

Populate the ImageList from a List of URLs

While the DATA attribute permits the ImageList to be used in a Web page, the technique is cumbersome. You can populate the control if you use URL references instead of the base64-encoded image data. TreeViewWrapperProj.exe gives this capability. The LoadImages public method takes a reference to a simple XML document of the following format:
<Images>
	<Image Name="ImgH" Url="http://localhost/TreeViewWrapper/picture.bmp" />
	<Image Name="ImgG" Url="http://localhost/TreeViewWrapper/picture2.bmp" />
	<Image Name="ImgI" Url="http://localhost/TreeViewWrapper/picture3.bmp" />
</Images>
				
LoadImages iterates through these nodes, grabs each of the URLs, and then uses the built-in AsyncRead method of the UserControl to download each of the URLs one-by-one from the Web. The UserControl_AsyncReadComplete event handler responds to each completed download by adding the images to your encapsulated ImageList control. The UserControl_AsyncReadComplete event handler uses the Name attribute in the XML file as the image key:
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
    On Error GoTo ErrHandler
    
    ImageList1.ListImages.Add ImageList1.ListImages.Count + 1, _
           AsyncProp.PropertyName, AsyncProp.Value
    Exit Sub

    ' Report errors during dev. There is little end users can do with
    ' a failure here.
ErrHandler:
    Debug.Assert "AsyncReadComplete: Could not add image " & _
           AsyncProp.PropertyName & "; error is " & Err.Description
End Sub
				
Notice that, although the method that is used to download images in LoadImages is called AsyncRead, you use the AsyncReadOptions parameter to force synchronous image downloads:
        UserControl.AsyncRead imgUrl, vbAsyncTypePicture, imgName, _
           AsyncReadConstants.vbAsyncReadSynchronousDownload
				
You do this because the ImageList cannot be assigned to the TreeView until the TreeView has been populated with images. You can force a synchronous read, which is less cumbersome than if you use flags to test for the final AsyncReadComplete event.

Use TreeViewWrapper in a Web Page

After you build your control, you can host your control by using a simple object tag. Code in the onload event handler of the HTML file is used to load the ImageList from the XML file and to add nodes to the tree:
<HTML>
<HEAD>
	<TITLE>TreeViewWrapper.CAB</TITLE>

	<script language="jscript">

	function LoadTreeView()
	{
		tv1.LoadImages("http://localhost/TreeViewWrapper/images.xml");
		tv1.tvStyle = "TreelinesPictureText";
		tv1.AddNode("", 1, "Node1", "Top Node", "ImgH");
		tv1.AddNode("Node1", 4, "Node2", "Subnode 1", "ImgH");
		tv1.AddNode("Node1", 4, "Node3", "Subnode 2", "ImgI");
		tv1.AddNode("Node1", 4, "Node4", "Subnode 3", "ImgG");
	}			
						
	</script>
		
</HEAD>

<BODY onload="LoadTreeView();">
	<OBJECT ID="tv1"
             CLASSID="CLSID:6DFF1758-3C5B-4DAD-B6A9-E36654D17CBE"
             CODEBASE="TreeViewWrapper.CAB#version=1,0,0,2" VIEWASTEXT>
	</OBJECT>
</BODY>
</HTML>
				

Deploy TreeViewWrapper to Client Machines

The sample page that is included in this project works on a development computer or a computer where TreeViewWrapper.ocx is manually registered by using Regsrv32.exe. To deploy the sample page to arbitrary clients, you must use the Visual Basic Package and Deployment Wizard (PDW) to create a .cab file. You can then reference that .cab file in your CODEBASE attribute of the OBJECT tag. Note that you must modify both the Images.xml file and the tv1.LoadImages(...) method to point to the appropriate file path.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites: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

↑ Back to the top


Keywords: KB320868, kbinfo, kbfile, kbdownload

↑ Back to the top

Article Info
Article ID : 320868
Revision : 6
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 441