none
Detecting scrollable areas? RRS feed

  • Question

  • Hi,

    about some APIs I can get the hwnd of a foreign application. But is there a possibility to detect if this application has areas with scrollbars (for example internet explorer hast a menu, tabbar and an area with scrollbars)? If so, how can I get the rect of this area and how can I access this area (scrolling-event).

    Best regards
    Levis
    Wednesday, March 25, 2009 7:20 AM

Answers

  • Hi Levis1984,

    The visibility of a scroll bar is stored as a window style of the control. To retrieve the window style information from a control, you can call the GetWindowLong function.

    Please look this article:

    How To Detect If Scroll Bars Are Visible on a Control

    http://support.microsoft.com/kb/299686


    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" & _
       (ByVal hwnd As Long, ByVal nIndex As Long) As Long




    GetWindowLong Function
    http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx

    The GetWindowLong function retrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory.

    If you are retrieving a pointer or a handle, this function has been superseded by the GetWindowLongPtr function. (Pointers and handles are 32 bits on 32-bit Microsoft Windows and 64 bits on 64-bit Windows.) To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr.


    Furthermore, you could look this article to get more information about scroll event.


    ScrollBar.Scroll Event

     

    Occurs when the scroll box has been moved by either a mouse or keyboard action.

    The following code example uses the derived class VScrollBar. Event handlers for the Scroll and ValueChanged events are created. This code assumes that a Label and Button have been created on a form and that the button has an event handler for the Click event. When the button is clicked, the Value property of the scroll bar is adjusted in code. The label will display the current value of the Value property and the event that changed it. You will notice that when the scroll value is changed by the button's Click event, only the ValueChanged event is raised. In contrast, when the scroll bar is scrolled manually, the Scroll event is raised immediately after the ValueChanged event.

    Private Sub AddMyScrollEventHandlers()
        ' Create and initialize a VScrollBar.
        Dim vScrollBar1 As New VScrollBar()

        ' Add event handlers for the OnScroll and OnValueChanged events.
        AddHandler vScrollBar1.Scroll, AddressOf Me.vScrollBar1_Scroll
        AddHandler vScrollBar1.ValueChanged, AddressOf Me.vScrollBar1_ValueChanged
    End Sub   

    ' Create the ValueChanged event handler.
    Private Sub vScrollBar1_ValueChanged(sender As Object, e As EventArgs)
        ' Display the new value in the label.
        label1.Text = "vScrollBar Value:(OnValueChanged Event) " & _
            vScrollBar1.Value.ToString()
    End Sub   

    ' Create the Scroll event handler.
    Private Sub vScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)
        ' Display the new value in the label.
        label1.Text = "VScrollBar Value:(OnScroll Event) " & _
            e.NewValue.ToString()
    End Sub   

    Private Sub button1_Click(sender As Object, e As EventArgs)
        ' Add 40 to the Value property if it will not exceed the Maximum value.
        If vScrollBar1.Value + 40 < vScrollBar1.Maximum Then
            vScrollBar1.Value = vScrollBar1.Value + 40
        End If
    End Sub



    Best wishes
    Xingwei Hu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Xingwei Hu Tuesday, March 31, 2009 11:12 AM
    Monday, March 30, 2009 12:28 PM