tree controls are used to display data items with a certain level of structure is convenient, intuitive, widely used in various software, such as the disk directory in the resource manager with the tree control, we will often use in programming, but MFC provided in the CTreeCtrl class does not directly support the advanced features such as drag nodes, which makes us programmers have great limitations in programming, and also brings some inconvenience to software users. Let us solve this problem by ourselves and implement the drag of the nodes in the tree control.
We derive a class Cxtreectrl from the CTreeCtrl, which has the following characteristics:
⑴ the implementation of the basic drag.
⑵ handles unintentional drag.
⑶ can handle scrolling problems in the drag process.
The nodes are intelligently expanded during ⑷ drag.
Figure 1 is the running interface for the sample program.
(Figure 1)
OK, let's step through the above function.
Create a new dialog box project, edit the resource, add a tree control Idc_tree to the dialog box, and the property setting, as shown in Figure 2, adds a member variable m_wndtree to the control.
The type is changed to Cxtreectrl. Derives a class Cxtreectrl from the CTreeCtrl.
(Figure 2)