Can anyone tell me where i am going wrong.
I am trying to do a drag drop between a listview and a tree view.
at the moment I am just setting up the initial begin drap my code as follows...
'------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_CAPTURELISTVIEW_LVN_BEGINDRAG ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
ByVal lpNMV As NM_LISTVIEW Ptr _ ' pointer to NM_LISTVIEW
) As Long
Dim pt As PolyPoint
Dim uRect As Rect
GetCursorPos Pt
xhDragList = ListView_CreateDragImage( hwnd_scrncapt_CaptureListview, @lpNMV.iItem , @lpNMV.ptAction )
ListView_GetItemRect hwnd_scrncapt_CaptureListview, @lpNMV.iSubItem, uRect, %false
ImageList_BeginDrag hwnd_scrncapt_CaptureListview,0, @lpNMV.ptAction.x - uRect.nLeft , @lpNMV.ptAction.Y - uRect.nTop
ImageList_DragEnter hwnd_scrncapt_CaptureListview, @lpNMV.ptAction.x, @lpNMV.ptAction.Y
SetCapture hwnd_scrncapt_CaptureListview
ShowCursor %FALSE
xhDragItem = @lpNMV.iItem
End Function
'
'
''------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_CAPTURELISTVIEW_WM_MOUSEMOVE ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
MouseFlags As Long, _ ' virtual keys that are pressed
xPos As Long, _ ' x-coordinate of cursor
yPos As Long _ ' y-coordinate of cursor
) As Long
Local uPoint As POINTAPI
Local uTV_HIT_INFO As lV_HITTESTINFO
'If dragging, move the drag cursor...
if xhDragList <> %NULL then
'See where we are...
uPoint.x =xPos 'these are relative to <hWnd>
uPoint.y =yPos
'Convert to tree co-ordinates...
MapWindowPoints hwnd_scrncapt, hwnd_scrncapt_CaptureListview, ByVal VarPtr(uPoint), 1
' 'Load the hit test structure...
uTV_HIT_INFO.pt.x = uPoint.x 'these are relative to <hwnd_scrncapt_CaptureListview>
uTV_HIT_INFO.pt.y = uPoint.y
ListView_HitTest hwnd_scrncapt_CaptureListview, uTV_HIT_INFO
ImageList_DragLeave hwnd_scrncapt_CaptureListview
ImageList_DragEnter hwnd_scrncapt_CaptureListview, uPoint.x, uPoint.y
End If
End Function
I have never done drag and drop with Treeviews/Listviews so I don't have any prebuilt code that I can share. Maybe another user has something they can share?
When implimenting dragging of items, the following API's may be needed in the mousemove event:
ImageList_Copy (with the %ILCF_MOVE flag)
ImageList_DragMove
ImageList_DragEnter
To create the Drag Icon the following API's may be needed:
Imagelist_GetDragImage
ImageList_AddMasked
ImageList_Copy
A lot depends upon whether you use a unique drag icon or want to copy the actual item itself and turn it into an icon.
I have written a complete drag/drop engine for both the listview and treeview, but the code is very complex and I can't post a simple solution here.
The best way to figure it out, is to read very carefully each of the ImageList_ functions associated with drag icons in the API docs so you fully understand how they are used.
The first thing you have to understand is that there are differences between dragging an icon (or item) within a control or between controls.
If you want to drag items between controls, then you don't use the listviews mouse move event, but you have to track the mouse movement within the parent Dialogs window (or dialog) procedure. The code gets tricky because you may have to do a lot of conversion of coordinates between the forms client area and the controls client area (if you send any messages to the controls which require coordinates).
Also, you must set the mouse capture for which ever window is tracking the mouse movement. If the parent dialog is tracking the mouse (drag between controls), then set the capture to it (SetCapture API function).
You must have access to the window (or dialog) procedure of whatever window is doing the tracking. If you drag within the control, then it must be subclassed. You must process the following messages (or events) for the window that does the tracking of the mouse movement for dragging:
WM_CaptureChanged
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_MOUSEMOVE
WM_TIMER (if you impliment auto scrolling when dragging within the control)
This is very tricky to code, so I would suggest creating a simple test application with just a few controls on it. Read the API docs carefully for each of the ImageList_ functions associated with drag icons and test them out in your application. The docs are pretty clear about the functions use, but you won't appreciate how they work until you actually use them. It is a matter of trial and error until you grasp how the functions work.
The code I have is over 600 lines of code which is part of a proprietary software so I can't post it.
I have implimented drag and drop for the list and treeview between controls, within the control and between forms (dialogs) and with autoscrolling (when within control). The code for just the listview for what you want could end up being a 100 lines or more of code by time you are done.
Another thing to note, if you create a drag icon from the listview item itself, make sure you turn off Font Smoothing or the icon will not be created properly. The ImageList APIs have a problem with font smoothing.
Sorry I couldn't be of more help.
Thanks Guys,
Il have to do some reading. ..
one thing im unsure on, is how i can control all the messages .
i try using custom control, but I cant get seem to process %DL_BEGINDRAG
it keeps using the firefly callback.
How can i take control of all the messages.
Paul.
ok managed to get something up and running
so thought i would post it, in case anyone else needs an ff example.
I have yet to use images for a drag mouse but this at lease does most of what i need. I might post something improved once I add more. and maybe even something do to with the image list.