Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dst As Any, Src As Any, ByVal cBytes As Long)
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
'For Auto Mode:
Private Const LB_INSERTSTRING = &H181
Private Const LB_DELETESTRING = &H182
Private Const LB_ERR = (-1)
Private Const LB_GETITEMDATA = &H199
Private Const LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
Private Const LB_SETITEMDATA = &H19A
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
'Private variables:
Private m_hWndLB As Long, m_hWndLBParent As Long
Private m_DragListMsg As Long
Private m_LastIdx As Long
Private m_OldMousePointer As Long, m_OldMouseIcon As IPictureDisp
'Properties:
Public DrawInsertIcon As Boolean
Attribute DrawInsertIcon.VB_VarDescription = "Gibt an, ob das Icon, das den Einfⁿgepunkt markiert, gezeichnet werden soll."
Public AutoScroll As Boolean
Attribute AutoScroll.VB_VarDescription = "Legt fest, ob die ListBox beim ""Draggen"" automatisch scrollen soll."
'Sets the cursor to MouseIcon (or to vbArrow if is Nothing)
' if the Mouse is over the ListBox, and to vbNoDrop otherwise
Public AutoCursor As Boolean
'Exchanges the items and the ItemData automatically when finished
Public AutoItems As Boolean
'Events:
'Cancel can be set to True to cancel the Drag&Drop
Event BeginDrag(ByVal nItemIndex As Long, ByRef Cancel As Boolean)
Attribute BeginDrag.VB_Description = "Wird ausgel÷st, wenn der Benutzer Drag&Drop beginnt."
'Change the MousePointer, if needed + draw a user defined insert icon in this event
' This event is raised very often during Drag&Drop, even if the list item hasn't changed,
' so change the Cursor only if needed, not every time when the event is raised
Event Dragging(ByVal nItemDragging As Long, ByVal nTargetItem As Long, ByRef ChangeCursor As dlChangeCursor, ByVal PixelX As Long, ByVal PixelY As Long)
Attribute Dragging.VB_Description = "Wird wΣhrend des Drag&Drop in regelmΣ▀igen AbstΣnden ausgel÷st."
Event CancelDrag()
Attribute CancelDrag.VB_Description = "Wird ausgel÷st wenn das Drag&Drop abgebrochen wird."
'IMPORTANT: You'll have to put code to exchange the list items
' into this event if AutoItems = False !
Event Dropped(ByVal nOldIdx As Long, ByVal nTargetIdx As Long)
Attribute Dropped.VB_Description = "Wird ausgel÷st, wenn das Drag&Drop erfolgreich beendet wird."
'Constants for the cursor:
Enum dlChangeCursor
NoChange = 0
DL_MOVECURSOR = 3
DL_COPYCURSOR = 2
DL_STOPCURSOR = 1
End Enum
Public Sub ClearInsertIcon()
Attribute ClearInsertIcon.VB_Description = """L÷scht"" das Icon, das den Einfⁿgepunkt markiert."
If m_hWndLBParent <> 0 And m_hWndLB <> 0 Then
'Clear icon:
DrawInsert m_hWndLBParent, m_hWndLB, -1
End If
End Sub
Public Property Get hWndListBox() As Long
Attribute hWndListBox.VB_Description = "Legt das Handle der ListBox fest, die in eine DragListBox umgewandelt werden soll, fest.\r\nKann nur einmal gesetzt werden !"
hWndListBox = m_hWndLB
End Property
Public Property Let hWndListBox(ByVal NewVal As Long)
Static NotFirstTime As Boolean
'Can only be set once, because MakeDragListBox()
' cannot be "undone". So you could encounter
' problems with the messages if you did allow
' setting this property multiple times
If NotFirstTime Then
Err.Raise vbObjectError + 100, "DragList", "hWndListBox can only be set one time !"
End If
If IsWindow(NewVal) Then 'Valid window ?
m_hWndLB = NewVal
If Not pCreate Then Err.Raise vbObjectError + 101, "DragList", "ListBox couldn't be changed into a DragListBox !"
NotFirstTime = True
Else
Err.Raise 380
End If
End Property
Public Property Get LastDraggedItemIndex() As Long
Attribute LastDraggedItemIndex.VB_Description = "Gibt den ListIndex des zuletzt gezogenen Listenpunkts zurⁿck."
LastDraggedItemIndex = m_LastIdx
End Property
Public Property Get MouseIcon() As IPictureDisp
Set MouseIcon = m_OldMouseIcon
End Property
Public Property Set MouseIcon(NewMI As IPictureDisp)
If Not (m_OldMouseIcon Is NewMI) Then
Set m_OldMouseIcon = NewMI
Set Screen.MouseIcon = NewMI
End If
End Property
Private Function pCreate() As Boolean
pCreate = False
'Create DragList
If (MakeDragList(m_hWndLB) = 0) Then Exit Function