Results 1 to 6 of 6

Thread: [VB6] - controlling a VB6 standard scrollbar

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    [VB6] - controlling a VB6 standard scrollbar

    i have these code for get the scrollbar value property:
    Code:
    Option Explicit
    
    Private PrevWin2 As Long
    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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function SetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal code As Long, ByVal nPos As Long, ByVal fRedraw As Boolean) As Long
    Private Declare Function GetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
    
    Const SB_HORZ = 0
    Const SB_VERT = 1
    Const SB_BOTH = 3
    Private Const GWL_WNDPROC = (-4)
    Public lngWndPicture1 As Long
    Public lngWndVerticalScrollBar As Long
    Public lngWndHorizontalScrollBar As Long
    Public lngWndUserControl As Long
    
    Private Function Proc2(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim s As Long
        s = GetScrollPos(lngWndVerticalScrollBar, 1)
        Debug.Print s
        Proc2 = CallWindowProc(PrevWin2, hwnd, Msg, wParam, lParam)
    End Function
    
    Public Sub Hook2(Handle As Long)
        'If PrevWin2 = 0 Then
            PrevWin2 = SetWindowLong(Handle, GWL_WNDPROC, AddressOf Proc2)
        'End If
    End Sub
    
    Public Sub Unhook2(Handle As Long)
        'If PrevWin2 Then
            Call SetWindowLong(Handle, GWL_WNDPROC, PrevWin2)
            'PrevWin2 = 0
       ' End If
    End Sub
    and heres how i hook it:
    Code:
    If Ambient.UserMode = False Then
            tmrIDEScrollClick.Enabled = True
            lngWndVerticalScrollBar = ScrollingVertical.hwnd
            Hook2 UserControl.ParentControls(0).hwnd
        End If
    how the debug value is always zero?
    (i just need set and get the property Value on VB6 standard scrollbars)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - controlling a VB6 standard scrollbar

    My guess is that UserControl.ParentControls(0) is not a scrollbar
    What does the following return
    Code:
    Debug.Print TypeName(UserControl.ParentControls(0))
    Also, you are not using the right constants in your call. You'll want to use SB_CTL (Const SB_CTL = 2), not 1. Review the MSDN documentation here
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - controlling a VB6 standard scrollbar

    Quote Originally Posted by LaVolpe View Post
    My guess is that UserControl.ParentControls(0) is not a scrollbar
    What does the following return
    Code:
    Debug.Print TypeName(UserControl.ParentControls(0))
    Also, you are not using the right constants in your call. You'll want to use SB_CTL (Const SB_CTL = 2), not 1. Review the MSDN documentation here
    isn't a scrollbar, that why i use a long variable
    Code:
    Public lngWndVerticalScrollBar As Long
    but these api functions work with standar vb6 scrollbars?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - controlling a VB6 standard scrollbar

    thanks now works. but i need ask anotherthing:
    what scale mode i recive the results (because i recive a very big number)?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - controlling a VB6 standard scrollbar

    ok... now i'm trying changing the scroll Value property, but i see 1 error(not error message):
    Code:
     GetScrollInfo lngWndVerticalScrollBar, 2, SI
            If SI.nPos + 10 > SI.nMax Then
                SetScrollPos lngWndVerticalScrollBar, 2, SI.nPos
            Else
                SetScrollPos lngWndVerticalScrollBar, 2, SI.nPos + 10
            End If
    what i see is that put it on position zero and don't scroll(don't call the change scroll event)
    what can you advice me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - controlling a VB6 standard scrollbar

    i found my problem:
    Code:
    SI.cbSize = Len(SI)
            SI.fMask = SIF_ALL
            FlatSB_GetScrollInfo lngWndVerticalScrollBar, SB_CTL, SI
            If SI.nPos - ScrollValue < SI.nMin Then
                SI.nPos = SI.nMin
            Else
                SI.nPos = SI.nPos - ScrollValue
            End If
            FlatSB_SetScrollInfo lngWndVerticalScrollBar, SB_CTL, SI, True
    now the pos button is moved normaly. but why the scrollbar change event isn't called?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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