两个Listview滚动条同步
在一个窗体上有两个listview,我想让这两个listview实现同步滚动,就是一个滚动条滚动时,另一个也同步滚动,哪位大虾指点一下?? 问题点数:20、回复次数:11Top
1 楼subzero(赘姆烂壳)回复于 2006-03-09 16:49:14 得分 1
sendmessage应该有相应的消息Top
2 楼zqsntws(轻松)回复于 2006-03-09 17:26:28 得分 0
能否给个例子或是链接,不胜感激Top
3 楼zqsntws(轻松)回复于 2006-03-13 11:10:51 得分 0
还得自己顶Top
4 楼kmlxk(xiaoKKKK)回复于 2006-03-13 12:58:42 得分 2
使用API
Private Const LVN_BEGINSCROLL = (LVN_FIRST - 80)
Private Const LVN_ENDSCROLL = (LVN_FIRST - 81)
Private Const LVM_SCROLL = (LVM_FIRST + 20)
Top
5 楼zqsntws(轻松)回复于 2006-03-14 15:37:15 得分 0
kmlxk,能否给个例子,帮人帮到底吧,先谢谢了:)Top
6 楼AnnaBear(淡淡)回复于 2006-03-14 16:13:24 得分 1
不会
和楼主共同学习下...:)Top
7 楼zqsntws(轻松)回复于 2006-03-15 13:57:58 得分 0
我实现了另一个listview的滚动条同步滚动,但是其内容却不跟着横向滚动,这个怎么处理?Top
8 楼zqsntws(轻松)回复于 2006-03-15 15:40:51 得分 0
SendMessage ListView2.hWnd, WM_HSCROLL, i, ByVal 0&,直不知道i的范围是多少,就是滚进去的内容占多少个字符Top
9 楼kmlxk(xiaoKKKK)回复于 2006-03-15 17:20:45 得分 0
http://www.eggheadcafe.com/ng/microsoft.public.vb.controls/post252092.aspTop
10 楼kmlxk(xiaoKKKK)回复于 2006-03-15 17:22:17 得分 16
Visual Basic Subclassing Routines
WM_VSCROLL: Subclassing Listview Scrollbar Messages
Posted: Tuesday August 29, 2000
Updated: Tuesday January 03, 2006
Applies to: VB5, VB6
Developed with: VB6, Windows NT4
OS restrictions: None
Author: VBnet - Randy Birch
http://www.eggheadcafe.com/ng/microsoft.public.vb.controls/post252092.aspTop
11 楼kmlxk(xiaoKKKK)回复于 2006-04-07 20:11:50 得分 0
'==================窗体代码 Form1.frm=========================
'添加两个ListView。ListView1、ListView2
Option Explicit
Private Sub Form_Load()
Dim Index As Long
ListView1.ColumnHeaders.Add , , "Column 1"
ListView1.LabelEdit = lvwManual
ListView1.View = lvwReport
ListView2.ColumnHeaders.Add , , "Column 1"
ListView2.LabelEdit = lvwManual
ListView2.View = lvwReport
For Index = 1 To 50
ListView1.ListItems.Add , , "Item " & CStr(Index)
ListView2.ListItems.Add , , "Item " & CStr(Index)
Next
ListViewSubClass ListView1.hwnd
ListViewSubClass ListView2.hwnd
End Sub
'===================模块代码 Module1.mod======================
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private lpfnOldWinProcLV As Long 'old WindowProc address for ListView
Private Const GWL_WNDPROC As Long = (-4)
Private Const WM_VSCROLL As Long = &H115
Private Const WM_DESTROY As Long = &H2
Private Const SB_THUMBPOSITION As Long = 4
Private Const SB_THUMBTRACK As Long = 5
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_SCROLL As Long = (LVM_FIRST + 20)
Public Function ListViewSubClass(hwnd As Long) As Boolean
'This function enables subclassing
ListViewSubClass = True
'Get the address for the previous window procedure
lpfnOldWinProcLV = GetWindowLong(hwnd, GWL_WNDPROC)
If lpfnOldWinProcLV = 0 Then
ListViewSubClass = False
Exit Function
End If
'The return value of SetWindowLong is the address of the previous procedure,
'so if it's not what we just got above, something went wrong.
If SetWindowLong(hwnd, GWL_WNDPROC, AddressOf ListViewWndProc) <> lpfnOldWinProcLV Then
ListViewSubClass = False
End If
End Function
Public Function ListViewUnSubClass(hwnd As Long) As Boolean
'Restore default window procedure
If SetWindowLong(hwnd, GWL_WNDPROC, lpfnOldWinProcLV) = 0 Then
ListViewUnSubClass = False
Else
ListViewUnSubClass = True
lpfnOldWinProcLV = 0
End If
End Function
Private Function ListViewWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static bIgnore As Boolean
ListViewWndProc = CallWindowProc(lpfnOldWinProcLV, hwnd, uMsg, wParam, lParam)
If bIgnore Then
Exit Function
End If
'Determine the message that was received
Select Case uMsg
Case WM_VSCROLL
bIgnore = True
Select Case hwnd
Case Form1.ListView1.hwnd
If LoWord(wParam) = SB_THUMBTRACK Then
'拖动滚动条时并没有使另一个ListView发生滚动
'增加了相应的处理
'The high-order word specifies the current position of the scroll box if the low-order word is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, this word is not used.
'The low-order word specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values.
'SB_THUMBPOSITION
'The user has dragged the scroll box (thumb) and released the mouse button. The high-order word indicates the position of the scroll box at the end of the drag operation.
'SB_THUMBTRACK
'The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The high-order word indicates the position that the scroll box has been dragged to.
Call SendMessage(Form1.ListView2.hwnd, LVM_SCROLL, 0, -65535) '先向上回滚到顶部
Call SendMessage(Form1.ListView2.hwnd, LVM_SCROLL, 0, HiWord(wParam) * 13)
'滚动到指定位置,13这个常数是试验出来的,在不同的系统或ListView每列高度不同时可能要修改
End If
'Send the message to ListView2
Call SendMessage(Form1.ListView2.hwnd, uMsg, wParam, lParam)
Case Form1.ListView2.hwnd
'Send the message to ListView1
If LoWord(wParam) = SB_THUMBTRACK Then
Call SendMessage(Form1.ListView1.hwnd, LVM_SCROLL, 0, -65535) '向上回滚
Call SendMessage(Form1.ListView1.hwnd, LVM_SCROLL, 0, HiWord(wParam) * 13) '滚动到
End If
Call SendMessage(Form1.ListView1.hwnd, uMsg, wParam, lParam)
End Select
bIgnore = False
Case WM_DESTROY
Call CallWindowProc(lpfnOldWinProcLV, hwnd, uMsg, wParam, lParam)
Call ListViewUnSubClass(hwnd)
ListViewWndProc = CallWindowProc(lpfnOldWinProcLV, hwnd, uMsg, wParam, lParam)
End Select
End Function
Public Function LoWord(num As Long) As Integer
LoWord = num Mod &H10000
End Function
Public Function HiWord(num As Long) As Integer
HiWord = (num And &HFFFF0000) / &H10000
End Function
Top




