P
paolo.riba
Hi everybody!
Could anyone know how can I syncronize a
horizontal scrollbar with a listview?
Actually I can only syncronize the horizontal scrollbar with the
listview horizontal scrollbar, but items and subitems don't move.
The code is:
API declaration
' Scrollbar direction
' All these constents can be found in WinUser.h
'
Const SBS_HORZ = 0
Const SBS_VERT = 1
' Windows Messages
' All these constents can be found in WinUser.h
'
Const WM_VSCROLL = &H115
Const WM_HSCROLL = &H114
Const SB_THUMBPOSITION = 4
Public Enum eScrollAction
Jump = 0
Relitive = 1
End Enum
Public Enum eScrollDirection
Vertical = 0
Horizontal = 1
End Enum
' API Function: GetScrollPos
' Returns an integer of the position of the scrollbar
'
Private Declare Function GetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer) As Integer
' API Function: SetScrollPos
' Sets ONLY the scrollbar DOES NOT change the control object
'
Private Declare Function SetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByVal nPos As Integer, _
ByVal bRedraw As Boolean) As Integer
' API Function: PostMessageA
' Sends a message to a control (We are going to tell it to synch
' with the scrollbar)
'
Private Declare Function PostMessageA Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Boolean
--------------
On the Scroll event of the horizontal scroll bar:
scrollControl(ListView1.Handle, eScrollDirection.Horizontal,
eScrollAction.Jump, HSB.Value * 2)
----------------
Sub & Functrions:
Private Sub scrollControl(ByVal hWnd As IntPtr, ByVal Direction As
eScrollDirection, _
ByVal Action As eScrollAction, ByVal
Amount As Integer)
Dim position As Integer
' What direction are we going
If Direction = eScrollDirection.Horizontal Then
' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_HORZ) + Amount
Else
position = Amount
End If
' Make it so
If (SetScrollPos(hWnd, SBS_HORZ, position, True) <> -1)
Then
PostMessageA(hWnd, WM_HSCROLL, SB_THUMBPOSITION +
&H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() &
")")
End If
Else
' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_VERT) + Amount
Else
position = Amount
End If
' Make it so
If (SetScrollPos(hWnd, SBS_VERT, position, True) <> -1)
Then
PostMessageA(hWnd, WM_VSCROLL, SB_THUMBPOSITION +
&H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() &
")")
End If
End If
End Sub
Thanks a lot!!!!!!!!!!!!!!!!!
Could anyone know how can I syncronize a
horizontal scrollbar with a listview?
Actually I can only syncronize the horizontal scrollbar with the
listview horizontal scrollbar, but items and subitems don't move.
The code is:
API declaration
' Scrollbar direction
' All these constents can be found in WinUser.h
'
Const SBS_HORZ = 0
Const SBS_VERT = 1
' Windows Messages
' All these constents can be found in WinUser.h
'
Const WM_VSCROLL = &H115
Const WM_HSCROLL = &H114
Const SB_THUMBPOSITION = 4
Public Enum eScrollAction
Jump = 0
Relitive = 1
End Enum
Public Enum eScrollDirection
Vertical = 0
Horizontal = 1
End Enum
' API Function: GetScrollPos
' Returns an integer of the position of the scrollbar
'
Private Declare Function GetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer) As Integer
' API Function: SetScrollPos
' Sets ONLY the scrollbar DOES NOT change the control object
'
Private Declare Function SetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByVal nPos As Integer, _
ByVal bRedraw As Boolean) As Integer
' API Function: PostMessageA
' Sends a message to a control (We are going to tell it to synch
' with the scrollbar)
'
Private Declare Function PostMessageA Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Boolean
--------------
On the Scroll event of the horizontal scroll bar:
scrollControl(ListView1.Handle, eScrollDirection.Horizontal,
eScrollAction.Jump, HSB.Value * 2)
----------------
Sub & Functrions:
Private Sub scrollControl(ByVal hWnd As IntPtr, ByVal Direction As
eScrollDirection, _
ByVal Action As eScrollAction, ByVal
Amount As Integer)
Dim position As Integer
' What direction are we going
If Direction = eScrollDirection.Horizontal Then
' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_HORZ) + Amount
Else
position = Amount
End If
' Make it so
If (SetScrollPos(hWnd, SBS_HORZ, position, True) <> -1)
Then
PostMessageA(hWnd, WM_HSCROLL, SB_THUMBPOSITION +
&H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() &
")")
End If
Else
' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_VERT) + Amount
Else
position = Amount
End If
' Make it so
If (SetScrollPos(hWnd, SBS_VERT, position, True) <> -1)
Then
PostMessageA(hWnd, WM_VSCROLL, SB_THUMBPOSITION +
&H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() &
")")
End If
End If
End Sub
Thanks a lot!!!!!!!!!!!!!!!!!