Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit
Kev Peel http://www.powerbasic.com/support/pbforums/showthread.php?t=23950&highlight=%25LVN_BEGINDRAG
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "commctrl.inc"
#Resource "gbsnippets.pbr"
%IDC_ListView = 500
Global hDlg,hListView,hList As Dword
Global StartItem,EndItem As Long
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,300,300,%WS_OverlappedWindow, 0 To hDlg
CreateListview
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long, NMLV As NMListView Ptr, LVHT As LVHitTestInfo
Static DragInWork As Long
Select Case Cb.Msg
Case %WM_InitDialog
Case %WM_Command
Case %WM_SetCursor
If Cb.WParam <> hListView Then Exit Function
Select Case Hi(Word, Cb.LParam) 'monitors lbuttondown, mousemose, lbuttonup
Case %WM_LButtonUp
If DragInWork Then
GetCursorPos LVHT.pt
ScreenToClient hListView, LVHT.pt
Control Send hDlg, %IDC_ListView, %LVM_SubItemHitTest, 0, VarPtr(LVHT)
EndItem = LVHT.iItem
ReArrangeList
DragInWork = 0
End If
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
Case %LVN_BeginDrag
SetCapture hListView
NMLV = Cb.LParam
DragInWork = 1
StartItem = @NMLV.iItem
End Select
End Select
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ListView, w-20,h-20
End Select
End Function
Sub RearrangeList
? Str$(StartItem) + " moves to " + Str$(EndItem)
End Sub
Sub CreateListView
'create control
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,175,75, %WS_TabStop Or %LVS_ShowSelAlways Or %LVS_SingleSel Or %WS_Border Or %LVS_AutoArrange Or %LVS_NoColumnHeader 'Or %LVS_Icon , %WS_Ex_ClientEdge
Control Handle hDlg, %IDC_ListView To hListView
'create LARGE imagelist w,h,depth,size
ImageList New Icon 32,32,32,3 To hList
ImageList Add Icon hList, "add"
ImageList Add Icon hList, "data"
ImageList Add Icon hList, "grid"
ImageList Add Icon hList, "home"
ImageList Add Icon hList, "paint"
ImageList Add Icon hList, "plane"
'attach imagelist
ListView Set ImageList hDlg, %IDC_ListView, hList, %lvsil_normal
'columns hdlg, id&, col, "test", width, format
ListView Insert Column hDlg, %IDC_ListView, 1, "test1", 75, 0
'rows hdlg, id&, row, image, "text"
ListView Insert Item hDlg, %IDC_ListView, 1, 1, "000" 'row 1, col1
ListView Insert Item hDlg, %IDC_ListView, 2, 2, "111" 'row 2, col1
ListView Insert Item hDlg, %IDC_ListView, 3, 3, "222" 'row 1, col1
ListView Insert Item hDlg, %IDC_ListView, 4, 4, "333" 'row 2, col1
ListView Insert Item hDlg, %IDC_ListView, 5, 5, "444" 'row 1, col1
ListView Insert Item hDlg, %IDC_ListView, 6, 6, "555" 'row 2, col1
ListView Insert Item hDlg, %IDC_ListView, 7, 7, "666" 'row 1, col1
ListView Set StyleXX hDlg, 100, %LVS_Ex_GridLines Or %LVS_Ex_FullRowSelect
End Sub
'gbs_00793
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm