-
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.
-
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
-
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
-
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
-
Thank you.
It work, but when I click on the scrollbar it don't change, So how I maked it change and scroll ?
-
You need to send the SBM_SETRANGE or SBM_SETRANGEREDRAW message.