Results 1 to 3 of 3

Thread: Problem with GetScrollPos

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    4

    Exclamation 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 !!!

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Use GetScrollInfo API instead. Here is a little example with RichTextBox:
    VB Code:
    1. Private Type SCROLLINFO
    2.     cbSize As Long
    3.     fMask As Long
    4.     nMin As Long
    5.     nMax As Long
    6.     nPage As Long
    7.     nPos As Long
    8.     nTrackPos As Long
    9. End Type
    10. Private Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
    11. Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
    12. Private Const SB_HORZ = 0
    13. Private Const SB_VERT = 1
    14. Private Const SIF_RANGE = &H1
    15. Private Const SIF_PAGE = &H2
    16. Private Const SIF_POS = &H4
    17. Private Const SIF_DISABLENOSCROLL = &H8
    18. Private Const SIF_TRACKPOS = &H10
    19. Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
    20.  
    21. 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
    22. Private Const WM_VSCROLL = &H115
    23. Private Const SB_LINEUP = 0
    24. Private Const SB_LINEDOWN = 1
    25.  
    26. Private Sub Command1_Click()
    27.     Dim si As SCROLLINFO
    28.     Dim strMsg As String
    29.     Dim lngRet As Long
    30.    
    31.     With si
    32.         .cbSize = Len(si)
    33.         .fMask = SIF_POS
    34.    
    35.         lngRet = GetScrollInfo(RichTextBox1.hwnd, SB_VERT, si)
    36.         If lngRet <> 0 Then
    37.             strMsg = "Scrollbar information:" & vbCrLf
    38.             strMsg = strMsg & "Min: " & .nMin & vbCrLf
    39.             'the actual MAX value is nMax + nPage
    40.             strMsg = strMsg & "Max: " & .nMax + .nPage & vbCrLf
    41.             strMsg = strMsg & "Current Position: " & .nPos
    42.         Else
    43.             strMsg = "Error getting scrollbar position."
    44.         End If
    45.     End With
    46.    
    47.     MsgBox strMsg
    48. End Sub
    49.  
    50. Private Sub Command2_Click()
    51.     'you can scroll line by line
    52.     SendMessage RichTextBox1.hwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0
    53.     'or you can use SetScrollInfo API to set the absolute position of the scrollbar
    54. End Sub

  3. #3
    New Member
    Join Date
    May 2007
    Posts
    5

    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


    Quote Originally Posted by Serge
    Use GetScrollInfo API instead. Here is a little example with RichTextBox:
    VB Code:
    1. Private Type SCROLLINFO
    2.     cbSize As Long
    3.     fMask As Long
    4.     nMin As Long
    5.     nMax As Long
    6.     nPage As Long
    7.     nPos As Long
    8.     nTrackPos As Long
    9. End Type
    10. Private Declare Function SetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Long
    11. Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
    12. Private Const SB_HORZ = 0
    13. Private Const SB_VERT = 1
    14. Private Const SIF_RANGE = &H1
    15. Private Const SIF_PAGE = &H2
    16. Private Const SIF_POS = &H4
    17. Private Const SIF_DISABLENOSCROLL = &H8
    18. Private Const SIF_TRACKPOS = &H10
    19. Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
    20.  
    21. 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
    22. Private Const WM_VSCROLL = &H115
    23. Private Const SB_LINEUP = 0
    24. Private Const SB_LINEDOWN = 1
    25.  
    26. Private Sub Command1_Click()
    27.     Dim si As SCROLLINFO
    28.     Dim strMsg As String
    29.     Dim lngRet As Long
    30.    
    31.     With si
    32.         .cbSize = Len(si)
    33.         .fMask = SIF_POS
    34.    
    35.         lngRet = GetScrollInfo(RichTextBox1.hwnd, SB_VERT, si)
    36.         If lngRet <> 0 Then
    37.             strMsg = "Scrollbar information:" & vbCrLf
    38.             strMsg = strMsg & "Min: " & .nMin & vbCrLf
    39.             'the actual MAX value is nMax + nPage
    40.             strMsg = strMsg & "Max: " & .nMax + .nPage & vbCrLf
    41.             strMsg = strMsg & "Current Position: " & .nPos
    42.         Else
    43.             strMsg = "Error getting scrollbar position."
    44.         End If
    45.     End With
    46.    
    47.     MsgBox strMsg
    48. End Sub
    49.  
    50. Private Sub Command2_Click()
    51.     'you can scroll line by line
    52.     SendMessage RichTextBox1.hwnd, WM_VSCROLL, SB_LINEDOWN, ByVal 0
    53.     'or you can use SetScrollInfo API to set the absolute position of the scrollbar
    54. 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
  •  



Click Here to Expand Forum to Full Width