The TreeView component is a tree-like List component that is extremely widely used in the authoring of applications. Such as: Resource Manager, Internet Express (FlashGet), Foxmail, etc., in which Windows Resource Manager is a typical example.
In C + + builder, it is easy to use the TreeView component, as long as you invoke the Add or Addchild method of the TreeView component to easily add a new node to the TreeView. To place a tree structure of a specified disk or directory in the TreeView component, you can use the method of traversing the tree to add all directories (including subdirectories) and files under the specified disk or directory to the TreeView.
Next, let's use the actual example to load the C-disk tree into the TreeView.
First, run Borland C + + Builder 5.0, add two button components, an edit component, a TreeView component, and a animate component to the form Form1. The Caption property of the component Button1 is then changed to "Mount TreeView1", the Caption property of the component Button2 is changed to "clear", and the Text property of the component Edit1 is changed to "C:\" to set the root directory of the default directory--c disk to traverse. Component Animate1 is used to display animations when traversing directories, where its Commonavi property is set to "Avifindcomputer", and you can also set it to other animations to display an animation that looks for a computer.
Press F12 to open the Code editing window, in "TForm1 *form1;" Statement below, add the following statement to define the custom function Browdir:
void __fastcall Browdir (ttreenodes * nodes,ansistring pathname,ttreenode * Num);
The Browdir function is a custom function that implements a recursive call to traverse a directory. It has three parameters, the first parameter transmits a node of the TreeView component to add new nodes, the second parameter is the path to the specified directory, and the third parameter transmits a node to indicate that a new node is to be added to that node.