请教如何返回ListView垂直滚动条的移动值

蜂歌 2017-10-09 12:06:06
以下代码可返回ListView水平滚动条的移动值,如要同时返回垂直滚动条的移动值,应如何改下
代码如下:
Const LVM_FIRST = &H1000
Const LVM_GETTOPINDEX = (LVM_FIRST + 39)
Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
Const WM_HSCROLL = &H114
Const WM_VSCROLL = &H115
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long

Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
Private Const SB_HOBZ = 15
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SIF_POS = &H4
Private SELECTEDCOLUMN As Integer

Private Function LiGus() As Long
'----------------------------------------------------------------------
'功能:获得水平滚动条的滚动距离
'调用方法:LiGus
'----------------------------------------------------------------------
Dim scrInfo As SCROLLINFO
scrInfo.cbSize = LenB(scrInfo)
scrInfo.fMask = SIF_POS
GetScrollInfo ListView1.hwnd, SB_HORZ, scrInfo
LiGus = scrInfo.nPos * SB_HOBZ
End Function
...全文
1101 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
蜂歌 2017-10-12
  • 打赏
  • 举报
回复
谢谢
赵4老师 2017-10-11
  • 打赏
  • 举报
回复
如果是我,就用Timer,每隔比如1秒,读取滚动条当前位置。
赵4老师 2017-10-10
  • 打赏
  • 举报
回复
Scroll Box Position and Scrolling Range The position of the scroll box is represented as an integer; it is relative to the left or upper end of the scroll bar, depending on whether the scroll bar is horizontal or vertical. The position must be within the minimum and maximum values of the scrolling range. For example, in a scroll bar with a range of 0 through 100, position 50 is in the middle, with the remaining positions distributed equally along the scroll bar. The initial range depends on the scroll bar. Standard scroll bars have an initial range of 0 through 100; scroll bar controls have an empty range (both minimum and maximum values are zero), unless you supply an explicit range when the control is created. You can change the range at any time. You can use the SetScrollInfo function to set the range values, and the GetScrollInfo function to retrieve the current range values. An application typically adjusts the scroll range to convenient integers, making it easy to translate the scroll box position into a value corresponding to the data object to be scrolled. For example, if an application must display 260 lines of a text file in a window that can show only 16 lines at a time, the vertical scroll bar range can be set to 1 through 244. If the scroll box is at position 1, the first line will be at the top of the window. If the scroll box is at position 244, the last line (line 260) will be at the bottom of the window. If an application attempts to specify a position value that is less than the minimum or more than the maximum, the minimum or maximum scrolling range value is used instead. You can set a page size for a scroll bar. The page size represents the number of data units that can fit in the client area of the owner window given its current size. For example, if the client area can hold 16 lines of text, an application would set the page size to 16. The system uses the page size, along with the scrolling range and length of the scroll shaft, to set the size of the scroll box. Whenever a window containing a scroll bar is resized, an application should call the SetScrollInfo function to set the page size. An application can retrieve the current page size by calling the sending GetScrollInfo function. To establish a useful relationship between the scroll bar range and the data object, an application must adjust the range whenever the size of the data object changes. As the user moves the scroll box in a scroll bar, the scroll bar reports the scroll box position as an integer in the scrolling range. If the position is the minimum value, the scroll box is at the top of a vertical scroll bar or at the left end of a horizontal scroll bar. If the position is the maximum value, the scroll box is at the bottom of a vertical scroll bar or at right end of a horizontal scroll bar. The maximum value that a scroll bar can report (that is, the maximum scrolling position) depends on the page size. If the scroll bar has a page size greater than one, the maximum scrolling position is less than the maximum range value. You can use the following formula to calculate the maximum scrolling position: MaxScrollPos = MaxRangeValue - (PageSize - 1) An application must move the scroll box in a scroll bar. Although the user makes a request for scrolling in a scroll bar, the scroll bar does not automatically update the scroll box position. Instead, it passes the request to the parent window, which must scroll the data and update the scroll box position. An application uses the SetScrollInfo function to update the scroll box position; otherwise, it uses the SetScrollPos function. Because it controls the scroll box movement, the application can move the scroll box in increments that work best for the data being scrolled.
蜂歌 2017-10-10
  • 打赏
  • 举报
回复
研究了半天没看懂,谢谢!
赵4老师 2017-10-09
  • 打赏
  • 举报
回复
Const LVM_FIRST = &H1000
Const LVM_GETTOPINDEX = (LVM_FIRST + 39)
Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
Const WM_HSCROLL = &H114
Const WM_VSCROLL = &H115
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long

Private Type SCROLLINFO
  cbSize As Long
  fMask As Long
  nMin As Long
  nMax As Long
  nPage As Long
  nPos As Long
  nTrackPos As Long
End Type
Private Const SB_HOBZ = 15
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SIF_POS = &H4
Private SELECTEDCOLUMN As Integer

Private Function LiGus() As Long
  '----------------------------------------------------------------------
  '功能:获得ListView水平滚动条的滚动距离
  '调用方法:LiGus
  '----------------------------------------------------------------------
  Dim scrInfo As SCROLLINFO
  scrInfo.cbSize = LenB(scrInfo)
  scrInfo.fMask = SIF_POS
  GetScrollInfo ListView1.hwnd, SB_HORZ, scrInfo
  LiGus = scrInfo.nPos * SB_HOBZ
End Function

Private Function LiGvs() As Long
  '----------------------------------------------------------------------
  '功能:获得ListView垂直滚动条的滚动距离
  '调用方法:LiGvs
  '----------------------------------------------------------------------
  Dim scrInfo As SCROLLINFO
  scrInfo.cbSize = LenB(scrInfo)
  scrInfo.fMask = SIF_POS
  GetScrollInfo ListView1.hwnd, SB_VERT, scrInfo
  LiGvs = scrInfo.nPos * SB_HOBZ
End Function
蜂歌 2017-10-09
  • 打赏
  • 举报
回复
谢谢,如要获取滚动条结束事件,要如何改下,要不要用个Timer不断的刷新滚动条的位置

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧