Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi, TTreeView: how to get the screen coordinates of the given node and its icon?

Please help me to get the screen coordinates of the state icon rectangle of the given TTreeNode in a TreeView (I mean the icons specified in the TTreeView.StateImages property).

There is a TTreeView.GetHitTestInfoAt(X, Y: integer): : THitTests function, but that is not quite what I'm looking for; it says whether the given coordinates correspond to the label, or to the icon, or to the state icon of the item, but I need to know what part of the icon was clicked.

(The reason is that I want to implement the TreeView nodes with two checkboxes for each item, and I use StateImages to simulate the checkboxes (one state is a checked item, the other state is an unchecked item). As I understand, to know which one of the checkboxes is clicked I need to compare the cursor coordinates with the state icon coordinates. How can I get them?)

like image 793
livin-in-daylight Avatar asked Sep 01 '13 15:09

livin-in-daylight


1 Answers

You can send the control a tvm_GetItemRect message which will tell you the client coordinates of the item's bounding box. Use that and what you know of the relative positions of the label text and the icons to determine where the mouse was clicked in the icon.

Instead of GetHitTestInfoAt, you might prefer to send a tvm_HitTest message instead since it will give you the hit-test information and an item handle at once; a handle is what tvm_GetItemRect requires.

You don't need the screen coordinates since all the coordinates involved so far are client coordinates, but you can call ClientToScreen if you really want screen coordinates.

like image 168
Rob Kennedy Avatar answered Oct 20 '22 00:10

Rob Kennedy