如何设置外部窗口的滚动条位置,包括垂直滚动条和水平滚动条,
之后根据滚动条位置,刷新窗口内容
14 个解决方案
#1
不好意思,不明白
外部窗口是什么意思~~
#2
是用一个窗口的滚动条控制另一个窗口显示的意思吗?
#3
直接通过句柄设置一个滚动条的位置。
不需要其他辅助的滚动条
不需要其他辅助的滚动条
#4
#5
用 SBM_SETSCROLLINFO
#6
SBM_SETSCROLLINFO以后,鼠标移到窗口中,滚动条又回到原来的位置了
然后怎么根据滚动条位置,刷新窗口内容
然后怎么根据滚动条位置,刷新窗口内容
#7
顶呀顶呀,救命啊,up~upupupupup~~~~~~~
#8
是不是手工操作的鼠标已经按下了?用 ReleaseCapture 释放。
#9
使用 Hscroll Vscroll
先设定好两个的 MAX 再用它们的 Change事件
先设定好两个的 MAX 再用它们的 Change事件
#10
不懂怎么用SBM_SETSCROLLINFO。。。
我试了如下代码,但是鼠标移到窗口中,滚动条又回到原来的位置了。。
我试了如下代码,但是鼠标移到窗口中,滚动条又回到原来的位置了。。
Option Explicit
'滚动条信息结构体
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Public Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
Public Const SIF_RANGE = &H1
Public Const SIF_PAGE = &H2
Public Const SIF_POS = &H4
Public Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS
Public Const SB_HORZ = 0
Public Const SB_VERT = 1
Public Const SB_CTL = 2
Public Const WM_HSCROLL = &H114
Public Const WM_VSCROLL = &H115
Public Const SBM_SETSCROLLINFO = 233
Public Const SB_LINEUP = 0
Public Const SB_LINEDOWN = 1
#11
Option Explicit
Private Sub Command1_Click()
Dim si As SCROLLINFO
si.cbSize = Len(si)
si.fMask = SIF_POS
GetScrollInfo &H2501FC, SB_VERT, si
si.nPos = 20
SetScrollInfo &H2501FC, SB_VERT, si, True
'SendMessage &H80250, WM_VSCROLL, SB_LINEUP, 0
'SendMessage &H80250, WM_VSCROLL, SB_LINEDOWN, 0
'SendMessage &H80250, SBM_SETSCROLLINFO, 0, si
End Sub
#12
马马虎虎自己解决了
Option Explicit
Private Sub Command1_Click()
Dim si As SCROLLINFO, ScrollPos As Long, Distance As Long, PageRoute As Long, LineRoute As Long, i As Long
Dim MyHwnd As Long
MyHwnd = &H5B026C
si.cbSize = Len(si)
si.fMask = SIF_ALL
GetScrollInfo MyHwnd, SB_VERT, si
ScrollPos = CLng(InputBox("请输入需要滚动到的位置!"))
If ScrollPos < si.nMin Or ScrollPos > si.nMax Then
MsgBox "超出滚动范围"
Exit Sub
End If
'si.nPos = 20
'SetScrollInfo &H5B026C, SB_VERT, si, True
Distance = ScrollPos - si.nPos
PageRoute = Abs(Distance \ si.nPage)
LineRoute = Abs(Distance Mod si.nPage)
Select Case Distance
Case Is > 0
For i = 1 To PageRoute
SendMessage MyHwnd, WM_VSCROLL, SB_PAGEDOWN, 0
Next i
For i = 1 To (LineRoute + PageRoute)
SendMessage MyHwnd, WM_VSCROLL, SB_LINEDOWN, 0
Next i
Case Is < 0
For i = 1 To PageRoute
SendMessage MyHwnd, WM_VSCROLL, SB_PAGEUP, 0
Next i
For i = 1 To (LineRoute + PageRoute)
SendMessage MyHwnd, WM_VSCROLL, SB_LINEUP, 0
Next i
End Select
GetScrollInfo MyHwnd, SB_VERT, si
MsgBox "期望值:" & ScrollPos & vbCrLf & "实际值:" & si.nPos
'SendMessage &H5B026C, WM_VSCROLL, SB_LINEUP, 0
'SendMessage &H80250, WM_VSCROLL, SB_LINEDOWN, 0
'SendMessage &H80250, SBM_SETSCROLLINFO, 0, si
End Sub
#13
看起来是目标程序没有响应滚动条的直接定位,并且自己保存了一个滚动位置用作显示刷新。
#14
滚动位置应该保存在显示框里吧?显示框显示哪一部分内容,滚动条跟着同步。
#1
不好意思,不明白
外部窗口是什么意思~~
#2
是用一个窗口的滚动条控制另一个窗口显示的意思吗?
#3
直接通过句柄设置一个滚动条的位置。
不需要其他辅助的滚动条
不需要其他辅助的滚动条
#4
#5
用 SBM_SETSCROLLINFO
#6
SBM_SETSCROLLINFO以后,鼠标移到窗口中,滚动条又回到原来的位置了
然后怎么根据滚动条位置,刷新窗口内容
然后怎么根据滚动条位置,刷新窗口内容
#7
顶呀顶呀,救命啊,up~upupupupup~~~~~~~
#8
是不是手工操作的鼠标已经按下了?用 ReleaseCapture 释放。
#9
使用 Hscroll Vscroll
先设定好两个的 MAX 再用它们的 Change事件
先设定好两个的 MAX 再用它们的 Change事件
#10
不懂怎么用SBM_SETSCROLLINFO。。。
我试了如下代码,但是鼠标移到窗口中,滚动条又回到原来的位置了。。
我试了如下代码,但是鼠标移到窗口中,滚动条又回到原来的位置了。。
Option Explicit
'滚动条信息结构体
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Public Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
Public Const SIF_RANGE = &H1
Public Const SIF_PAGE = &H2
Public Const SIF_POS = &H4
Public Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS
Public Const SB_HORZ = 0
Public Const SB_VERT = 1
Public Const SB_CTL = 2
Public Const WM_HSCROLL = &H114
Public Const WM_VSCROLL = &H115
Public Const SBM_SETSCROLLINFO = 233
Public Const SB_LINEUP = 0
Public Const SB_LINEDOWN = 1
#11
Option Explicit
Private Sub Command1_Click()
Dim si As SCROLLINFO
si.cbSize = Len(si)
si.fMask = SIF_POS
GetScrollInfo &H2501FC, SB_VERT, si
si.nPos = 20
SetScrollInfo &H2501FC, SB_VERT, si, True
'SendMessage &H80250, WM_VSCROLL, SB_LINEUP, 0
'SendMessage &H80250, WM_VSCROLL, SB_LINEDOWN, 0
'SendMessage &H80250, SBM_SETSCROLLINFO, 0, si
End Sub
#12
马马虎虎自己解决了
Option Explicit
Private Sub Command1_Click()
Dim si As SCROLLINFO, ScrollPos As Long, Distance As Long, PageRoute As Long, LineRoute As Long, i As Long
Dim MyHwnd As Long
MyHwnd = &H5B026C
si.cbSize = Len(si)
si.fMask = SIF_ALL
GetScrollInfo MyHwnd, SB_VERT, si
ScrollPos = CLng(InputBox("请输入需要滚动到的位置!"))
If ScrollPos < si.nMin Or ScrollPos > si.nMax Then
MsgBox "超出滚动范围"
Exit Sub
End If
'si.nPos = 20
'SetScrollInfo &H5B026C, SB_VERT, si, True
Distance = ScrollPos - si.nPos
PageRoute = Abs(Distance \ si.nPage)
LineRoute = Abs(Distance Mod si.nPage)
Select Case Distance
Case Is > 0
For i = 1 To PageRoute
SendMessage MyHwnd, WM_VSCROLL, SB_PAGEDOWN, 0
Next i
For i = 1 To (LineRoute + PageRoute)
SendMessage MyHwnd, WM_VSCROLL, SB_LINEDOWN, 0
Next i
Case Is < 0
For i = 1 To PageRoute
SendMessage MyHwnd, WM_VSCROLL, SB_PAGEUP, 0
Next i
For i = 1 To (LineRoute + PageRoute)
SendMessage MyHwnd, WM_VSCROLL, SB_LINEUP, 0
Next i
End Select
GetScrollInfo MyHwnd, SB_VERT, si
MsgBox "期望值:" & ScrollPos & vbCrLf & "实际值:" & si.nPos
'SendMessage &H5B026C, WM_VSCROLL, SB_LINEUP, 0
'SendMessage &H80250, WM_VSCROLL, SB_LINEDOWN, 0
'SendMessage &H80250, SBM_SETSCROLLINFO, 0, si
End Sub
#13
看起来是目标程序没有响应滚动条的直接定位,并且自己保存了一个滚动位置用作显示刷新。
#14
滚动位置应该保存在显示框里吧?显示框显示哪一部分内容,滚动条跟着同步。