Date: 02-16-2022
Return to Index
created by gbSnippets
'This version does not detect keyboard arrow scrolling
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Resource Manifest, 1, "test.xml"
%IDC_ListViewL = 500 : %IDC_ListViewR = 501
Global hDlg,hLeft,hRight As Dword, OrigProc As Long
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,230,200,%WS_OverlappedWindow, 0 To hDlg
CreateListViews
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Static ScrollInWork As Long
Select Case Cb.Msg
Case %WM_Notify
Select Case Cb.NmCode
Case %LVN_EndScroll
If Cb.WParam = %IDC_ListViewL Then
If ScrollInWork = 0 Then
ScrollInWork = 1
SetTopIndex(hRight, ListView_GetTopIndex(hLeft))
End If
ScrollInWork = 0
ElseIf Cb.WParam = %IDC_ListViewR Then
If ScrollInWork = 0 Then
ScrollInWork = 1
SetTopIndex(hLeft, ListView_GetTopIndex(hRight))
End If
ScrollInWork = 0
End If
End Select
End Select
End Function
Function SetTopIndex(hListview As Dword, index As Long) As Long
Local rc As RECT
SendMessage(hListview, %LVM_GetItemRect, 0, VarPtr(rc))
SendMessage(hListView, %LVM_Scroll, 0, (index - GetScrollPos(hListview, %SB_Vert)) * (rc.nBottom - rc.nTop))
End Function
Sub CreateListViews
Local i As Long
Control Add ListView, hDlg, %IDC_ListViewL, "", 10,10,100,180
Control Add ListView, hDlg, %IDC_ListViewR, "", 120,10,100,180
Control Handle hDlg, %IDC_ListViewL To hLeft
Control Handle hDlg, %IDC_ListViewR To hRight
ListView Insert Column hDlg, %IDC_ListViewL, 1, "Left", 80, 0
ListView Insert Column hDlg, %IDC_ListViewR, 1, "Right", 80, 0
For i = 1 To 100
ListView Insert Item hDlg, %IDC_ListViewL, 1, 0, Str$(i)
ListView Insert Item hDlg, %IDC_ListViewR, 1, 0, Str$(i)
Next i
End Sub
'gbs_01132
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm