I can enumerate the treeview items within a window in another process. I'd like to be able to programmatically initiate a drag-drop operation on nodes in the treeview, dragging the item into a window that I control. Ultimately, I just want to access the DataObject of each treeview item.
Is it possible to use PostMessage, or some other method, to initiate and complete the drag-drop sequence? Can it be done without taking ownership of the mouse (i.e without interruption to the user's mouse position)?
Is it possible to complete the same task, even if the treeview item is in a collapsed treeview folder (without expanding the folder)?
There is no
IDataObjectin the TreeView itself.It is the responsibility of the TreeView's owning application to detect when the user is trying to drag a TreeView node (the TreeView notifies the application via
TNV_BEGINDRAG), at which time the app can then create a suitableIDataObjectand pass it to theDoDragDrop()function to start an OLE drag operation, which can pass data across process boundaries.There are no window messages you can send to the TreeView (or the app) to retrieve an
IDataObjectfor a tree node, or to start a drag operation directly. About the only thing you can do on your end is to either:simulate mouse input over the TreeView itself, so it thinks the user is dragging a node normally.
simulate
TVN_BEGINDRAGmanually. This requires usingVirtualAllocEx()andWriteProcessMemory()to allocate and fill a suitableNMTREEVIEWstructure inside of the memory address space of the TreeView's owning process, and then sendTVN_BEGINDRAGto the TreeView's parent window, pointing it to thatNMTREEVIEWstruct. Which means first using things likeTVM_HITTESTandTVM_GETITEMto retrieve some information thatTVN_BEGINDRAGneeds to report to the app (most notably, the tree nodes'sHTREEITEMhandle andLPARAMvalue).This would trick the owning app into thinking the user is trying to drag a tree node around and act accordingly. But, it is still going through the motions of starting a real OLE drag operation, so the user will have to then move the mouse over your app window and release the mouse button (or you will have to simulate mouse input to do it programming) so the
IDataObjectis dropped onto your window normally.