|
-
Aug 30th, 2001, 04:00 AM
#1
Thread Starter
New Member
Problem with GetScrollPos
Declare Function GetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
Hi, i'm using this API with W98 and it runs perfectly.
But when i try the same program with the same code in Windows 2000, the function GetScrollPos doesn´t run.
What's the problem, ?
Is there any API function that gives me the same funcionality? Why Microsoft want to **** developers?
I want to know if in w2000 are more changes in API functions,
Bye Bye , hasta luego !!!
-
Aug 30th, 2001, 09:56 AM
#2
Use GetScrollInfo API instead. Here is a little example with RichTextBox:
VB Code:
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 Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_DISABLENOSCROLL = &H8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
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 Const WM_VSCROLL = &H115
Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1
Private Sub Command1_Click()
Dim si As SCROLLINFO
Dim strMsg As String
Dim lngRet As Long
With si
.cbSize = Len(si)
.fMask = SIF_POS
lngRet = GetScrollInfo(RichTextBox1.hwnd, SB_VERT, si)
If lngRet <> 0 Then
strMsg = "Scrollbar information:" & vbCrLf
strMsg = strMsg & "Min: " & .nMin & vbCrLf
'the actual MAX value is nMax + nPage
strMsg = strMsg & "Max: " & .nMax + .nPage & vbCrLf
strMsg = strMsg & "Current Position: " & .nPos
Else
strMsg = "Error getting scrollbar position."
End If
End With
MsgBox strMsg
End Sub
Private Sub Command2_Click()
'you can scroll line by line
SendMessage RichTextBox1.hwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0
'or you can use SetScrollInfo API to set the absolute position of the scrollbar
End Sub
-
May 16th, 2007, 09:56 AM
#3
New Member
Re: Problem with GetScrollPos
Hi, can this code be modded sothat I can see the scroll position for any active window/the foeground window. Hope you can help.
Thanks
 Originally Posted by Serge
Use GetScrollInfo API instead. Here is a little example with RichTextBox:
VB Code:
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 Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_DISABLENOSCROLL = &H8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
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 Const WM_VSCROLL = &H115
Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1
Private Sub Command1_Click()
Dim si As SCROLLINFO
Dim strMsg As String
Dim lngRet As Long
With si
.cbSize = Len(si)
.fMask = SIF_POS
lngRet = GetScrollInfo(RichTextBox1.hwnd, SB_VERT, si)
If lngRet <> 0 Then
strMsg = "Scrollbar information:" & vbCrLf
strMsg = strMsg & "Min: " & .nMin & vbCrLf
'the actual MAX value is nMax + nPage
strMsg = strMsg & "Max: " & .nMax + .nPage & vbCrLf
strMsg = strMsg & "Current Position: " & .nPos
Else
strMsg = "Error getting scrollbar position."
End If
End With
MsgBox strMsg
End Sub
Private Sub Command2_Click()
'you can scroll line by line
SendMessage RichTextBox1.hwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0
'or you can use SetScrollInfo API to set the absolute position of the scrollbar
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|