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

Please help me get the screen coordinates of the rectangle of the status icon of this TTreeNode in the TreeView (I mean the icons specified in the TTreeView.StateImages property).

There is a function TTreeView.GetHitTestInfoAt(X, Y: integer): : THitTests , but this is not quite what I am looking for; it says whether the given coordinates match the label or the icon or status icon of the element, but I need to know which part of the icon was clicked.

(The reason is because I want to implement TreeView nodes with two flags for each element, and I use StateImages to simulate flags (one state is a marked element, another state is an uncontrolled element) As I understand it, to find out which of these flags clicked, I need to compare the coordinates of the cursor with the coordinates of the status icon. How can I get them?)

+7
delphi treeview
source share
1 answer

You can send a tvm_GetItemRect control a message that tells you the client’s coordinates in the bounding box of the element. Use this and what you know about the relative positions of the text labels and icons to determine where the mouse clicked in the icon.

Instead of GetHitTestInfoAt you can instead send the message tvm_HitTest , as it will give you information about the tests and handle the item immediately; a descriptor is what tvm_GetItemRect requires.

You do not need screen coordinates, since all the coordinates that have been used so far are client coordinates, but you can call ClientToScreen if you really need screen coordinates.

+6
source share

All Articles