Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE "pierre_modified.exe"
#Dim All
%Unicode=1
#Include "Win32Api.inc"
#Include "CommCtrl.inc"
%Checkbox = 101
%ListviewLeft = 201
%ListviewRight = 202
Global hDlg As Dword
Global hListviewLeft As Dword
Global hListviewRight As Dword
Global pListviewProcOri As Dword
Global delta As Long
'______________________________________________________________________________
Sub LVM_SETTOPINDEX(hListview As Dword, index As Long)
Local ListviewItemRect As RECT
Local ScrollInf As SCROLLINFO
SendMessage(hListview, %LVM_GetItemRect, 0, VarPtr(ListviewItemRect))
ScrollInf.cbSize = SizeOf(SCROLLINFO)
ScrollInf.fMask = %SIF_Pos
GetScrollInfo(hListview, %SB_Vert, ScrollInf)
SendMessage(hListView, %LVM_Scroll, 0, _
(index - ScrollInf.nPos) * _
(ListviewItemRect.nBottom - ListviewItemRect.nTop))
End Sub
'______________________________________________________________________________
Function ListviewProc(ByVal hWnd As Dword, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_VScroll, %WM_KEYFIRST To %WM_KEYLAST, %WM_MouseWheel
If hWnd = hListviewLeft Then
If SendDlgItemMessage(hDlg, %Checkbox, %BM_GETCHECK, 0, 0) Then
Delta = GetScrollPos(hListViewLeft, %SB_Vert) - GetScrollPos(hListViewRight, %SB_Vert)
PostMessage(hDlg, %WM_APP, hListviewLeft, hListviewRight)
End If
End If
If hWnd = hListviewRight Then
If SendDlgItemMessage(hDlg, %Checkbox, %BM_GETCHECK, 0, 0) Then
Delta = GetScrollPos(hListViewRight, %SB_Vert) - GetScrollPos(hListViewLeft, %SB_Vert)
PostMessage(hDlg, %WM_APP, hListviewRight, hListviewLeft)
End If
End If
End Select
Function = CallWindowProc(pListviewProcOri, hWnd, Msg, wParam, lParam)
End Function
'______________________________________________________________________________
CallBack Function DlgProc() As Long
Select Case CbMsg
Case %WM_InitDialog
pListviewProcOri = SetWindowLong(hListviewLeft, %GWL_WNDPROC, CodePtr(ListviewProc))
SetWindowLong(hListviewRight, %GWL_WNDPROC, CodePtr(ListviewProc))
Case %WM_ContextMenu
Select Case GetDlgCtrlID (Cb.WParam)
Case %ListViewLeft
? "context on ListViewLeft"
Case %ListViewRight
? "context on ListViewRight"
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %ListViewLeft
Select Case Cb.NmCode
Case %NM_DblClk
? "double click on ListViewLeft"
End Select
Case %ListViewRight
Select Case Cb.NmCode
Case %NM_DblClk
? "double click on ListViewRight"
End Select
End Select
Case %WM_APP
LVM_SETTOPINDEX(CbLParam, GetScrollPos(CbWParam, %SB_Vert)-Delta)
Case %WM_Destroy
SetWindowLong(hListviewLeft, %GWL_WNDPROC, pListviewProcOri)
SetWindowLong(hListviewRight, %GWL_WNDPROC, pListviewProcOri)
End Select
End Function
'______________________________________________________________________________
Function PBMain() As Long
Local ListviewColumn As LV_COLUMN
Local ListviewItem As LV_ITEM
Local zBuffer As AsciiZ * 7
Local Looper As Long
Local ListviewCol As Long
Local ListviewRow As Long
Dialog New Pixels, %HWND_Desktop, "ListView syncro", , , 230, 230, _
%WS_Caption Or %WS_MinimizeBox Or %WS_SysMenu, 0 To hDlg
Control Add CheckBox, hDlg, %Checkbox, "Synchronized Scrolling", 50, 10, 170, 20
Control Set Check hDlg, %Checkbox, %TRUE
Control Add "SysListView32", hDlg, %ListviewLeft, "", 10, 40, 100, 180, _
%WS_Child Or %WS_Visible Or %WS_Border Or %WS_TabStop Or _
%LVS_Report Or %LVS_ShowSelAlways, %WS_Ex_Left Or %WS_Ex_RightScrollbar
Control Handle hDlg, %ListviewLeft To hListviewLeft
Control Add "SysListView32", hDlg, %ListviewRight, "", 120, 40, 100, 180, _
%WS_Child Or %WS_Visible Or %WS_Border Or %WS_TabStop Or _
%LVS_Report Or %LVS_ShowSelAlways, %WS_Ex_Left Or %WS_Ex_RightScrollbar
Control Handle hDlg, %ListviewRight To hListviewRight
ListviewColumn.mask = %LVCF_FMT Or %LVCF_TEXT Or %LVCF_SUBITEM
ListviewColumn.fmt = %LVCFMT_LEFT
ListviewColumn.pszText = VarPtr(zBuffer)
ListviewColumn.iOrder = ListviewCol
zBuffer = "Left"
SendMessage(hListviewLeft, %LVM_InsertColumn, ListviewCol, VarPtr(ListviewColumn))
SendMessage(hListviewLeft, %LVM_SetColumnWidth, ListviewCol, MakLng(80, 0))
zBuffer = "Right"
SendMessage(hListviewRight, %LVM_InsertColumn, ListviewCol, VarPtr(ListviewColumn))
SendMessage(hListviewRight, %LVM_SetColumnWidth, ListviewCol, MakLng(80, 0))
For ListviewRow = 1 To 100
zBuffer = Format$(ListviewRow)
ListviewItem.stateMask = %LVIS_FOCUSED
ListviewItem.pszText = VarPtr(zBuffer)
ListviewItem.iItem = ListviewRow
ListviewItem.iSubItem = ListviewCol
ListviewItem.lParam = ListviewRow
ListviewItem.mask = %LVIF_TEXT Or %LVIF_PARAM Or %LVIF_STATE
SendMessage(hListviewLeft, %LVM_InsertItem, 0, VarPtr(ListviewItem))
SendMessage(hListviewRight, %LVM_InsertItem, 0, VarPtr(ListviewItem))
Next
Dialog Show Modal hDlg Call DlgProc
End Function
'gbs_01128
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm