//没有检查是否可见 在TreeView1里边添加超过6个的节点<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ComCtrls, CommCtrl;<br><br>type<br> TForm1 = class(TForm)<br> TreeView1: TTreeView;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure ClickItem(hTree: THandle; hItem: HTREEITEM);<br>var<br> aRect: TRect;<br>begin<br> TreeView_GetItemRect(hTree, hItem, aRect, True);<br> SendMessage(hTree, WM_LBUTTONDOWN, 0, (aRect.Left+aRect.Right) div 2 + (aRect.Top+ aRect.Bottom)*$10000 div 2);<br> SendMessage(hTree, WM_LBUTTONUP, 0, (aRect.Left+aRect.Right) div 2 + (aRect.Top+ aRect.Bottom)*$10000 div 2);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> ClickItem(TreeView1.Handle, TreeView1.Items[1].ItemId);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> ClickItem(TreeView1.Handle, TreeView1.Items[5].ItemId);<br>end;<br><br>end.<br>