Someone please show me how to Create drag images for mulitple listview selected items
Hi Guys,
I've got the following code that creates a darg image when dragging a single listview item. But how can I select multiple items and create multiple drag images. Please help.
this is my module:
Code:
Option Explicit
' ==== Private members ====
Private m_lIL As Long
Private m_lTimer As Long
' ==== API declarations ====
Private Declare Function ImageList_BeginDrag Lib "comctl32" ( _
ByVal himlTrack As Long, _
ByVal iTrack As Long, _
ByVal dxHotspot As Long, _
ByVal dyHotspot As Long) As Long
Private Declare Sub ImageList_EndDrag Lib "comctl32" ()
Private Declare Function ImageList_DragEnter Lib "comctl32" ( _
ByVal hwndLock As Long, _
ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function ImageList_DragLeave Lib "comctl32" ( _
ByVal hwndLock As Long) As Long
Private Declare Function ImageList_DragMove Lib "comctl32" ( _
ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function ImageList_Destroy Lib "comctl32" ( _
ByVal himl As Long) As Long
Private Declare Function ImageList_GetImageCount Lib "comctl32" ( _
ByVal himl As Long) As Long
Private Type POINTL
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTL) As Long
Private Declare Function WindowFromPoint Lib "user32" ( _
ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const LVNI_SELECTED = &H2
Const LVNI_DROPHILITED = &H8
Const LVM_CREATEDRAGIMAGE = &H1000& + 33
Const LVM_GETNEXTITEM = &H1000& + 12
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" ( _
ByVal hwnd As Long, _
lpRect As RECT) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
'
' DragComplete
'
' Removes the drag image
'
Public Sub DragComplete()
' Stop the timer
KillTimer 0, m_lTimer
' End the image dragging
ImageList_EndDrag
' Destroy the ImageList
ImageList_Destroy m_lIL
End Sub
Private Sub pvTimerDragMove( _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
Dim tPoint As POINTL
' Get the cursor position
GetCursorPos tPoint
' Move the image to the new cursor position
ImageList_DragMove tPoint.x, tPoint.y
End Sub
'
' ListView_StartDrag
'
' Starts the image dragging
'
' Parameters:
' hWndListView - Window handle of the ListView that
' contains the item to drag
' X, Y - Hot spot coordinates in the image
'
Public Sub ListView_StartDrag( _
ByVal hWndListView As Long, _
Optional ByVal x As Long = 20, _
Optional ByVal y As Long = 20)
Dim tPoint As POINTL
Dim lItem As Long
' Get the selected item
lItem = SendMessage(hWndListView, LVM_GETNEXTITEM, -1, ByVal LVNI_SELECTED)
' Get a ImageList with
' the drag image
m_lIL = SendMessage(hWndListView, LVM_CREATEDRAGIMAGE, lItem, tPoint)
' Start the image dragging
ImageList_BeginDrag m_lIL, 0, x, y
ImageList_DragEnter 0, 0, 0
' Start the timer
m_lTimer = SetTimer(0, 0, 1, AddressOf pvTimerDragMove)
End Sub
this is the code in my form so far:
Code:
Private Sub lvwUnallocated_OLECompleteDrag(Effect As Long)
Call DragComplete
End Sub
Private Sub lvwUnallocated_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
Call ListView_StartDrag(lvwUnallocated.hwnd)
End Sub