Microsoft KB Archive/320868

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

Article ID: 320868

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 5.5 SP2
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q320868



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.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Download TreeViewWrapper.exe now

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:

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

http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q184975

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:      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 &quot;AsyncReadComplete: Could not add image &quot; & _ AsyncProp.PropertyName & &quot;; error is &quot; & 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:   TreeViewWrapper.CAB



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

  </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.

<div class="references_section">