Results 1 to 6 of 6

Thread: Scrollbars on form

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Location
    israel
    Posts
    4
    Hello

    I put Scrollbars on form by adding to his style the flags: WS_VSCROLL, WS_HSCROLL.

    1. Is any body know how can I get those scrollbars HWND?
    2. How can I catch if Scroll accured ?
    3. How can I change the Min, Max, Step of those scrollbars ?

    Thank you very much for helping.

  2. #2
    Guest
    To show them:
    Code:
    Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
    
    Private Sub Command1_Click()
        ShowScrollBar hwnd, 3, True
    End Sub

  3. #3
    Guest
    To check if they were scrolled, simply subclass your window and catch the WM_HSCROLL and WM_VSCROLL messages.
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    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
    Const GWL_WNDPROC = (-4)
    Const WM_HSCROLL = &H114
    Const WM_VSCROLL = &H115
    
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
        If wMsg = WM_HSCROLL Then 'Horizontal was scrolled
        If wMsg = WM_VSCROLL Then 'Vertical was scrolled
      
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
        
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub

  4. #4
    Guest
    Sorry, I forgot the rest of the code. Add this to a Form
    Code:
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Location
    israel
    Posts
    4

    Wink

    Thank you.

    It work, but when I click on the scrollbar it don't change, So how I maked it change and scroll ?

  6. #6
    Guest
    You need to send the SBM_SETRANGE or SBM_SETRANGEREDRAW message.

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