Tree Control Drag-and-Drop Operations

OverviewSample

A tree control () sends a notification when the user starts to drag an item. The control sends a notification message when the user begins dragging an item with the left mouse button and a notification message when the user begins dragging with the right button. You can prevent a tree control from sending these notifications by giving the tree control the TVS_DISABLEDRAGDROP style.

You obtain an image to display during a drag operation by calling the member function. The tree control creates a dragging bitmap based on the label of the item being dragged. Then the tree control creates an image list, adds the bitmap to it, and returns a pointer to the object.

You must provide the code that actually drags the item. This typically involves using the dragging capabilities of the image list functions and processing the and (or ) messages sent after the drag operation has begun. For more information about the image list functions, see in the Class Library Reference and in the Platform SDK. For more information about dragging a tree control item, see , also in the Platform SDK.

If items in a tree control are to be the targets of a drag-and-drop operation, you need to know when the mouse cursor is on a target item. You can find out by calling the member function. You specify either a point and integer, or the address of a structure that contains the current coordinates of the mouse cursor. When the function returns, the integer or structure contains a flag indicating the location of the mouse cursor relative to the tree control. If the cursor is over an item in the tree control, the structure contains the handle of the item as well.

You can indicate that an item is the target of a drag-and-drop operation by calling the member function to set the state to the TVIS_DROPHILITED value. An item that has this state is drawn in the style used to indicate a drag-and-drop target.

See Also   Windows Common Controls and MFC Classes