When using a Scrollbar or Trackbar, if you click on it to make it move the values do not change, only when using the mouse wheel or the thumb, where do you capture that event?
Hi Ivan,
For scrollbars you can set the LargeChange property to a value and then handle it via code like below (in this case, a vertical scrollbar):
Function FORM1_VSCROLL1_WM_VSCROLL ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
nScrollCode As Long, _ ' scroll bar value
nPosition As Long _ ' current scroll bar position
) As Long
'nScrollCode
'-----------------------------------------------
'SB_BOTTOM Scrolls To the lower Right.
'SB_ENDSCROLL Ends scroll.
'SB_LINEUP Scrolls Up by one unit.
'SB_LINEDOWN Scrolls Down by one unit.
'SB_PAGEUP Scrolls Up by the Width Of the window.
'SB_PAGEDOWN Scrolls Down by the Width Of the window.
'SB_LINELEFT Scrolls Left by one unit.
'SB_LINERIGHT Scrolls Right by one unit.
'SB_PAGELEFT Scrolls Left by the Width Of the window.
'SB_PAGERIGHT Scrolls Right by the Width Of the window.
'SB_THUMBPOSITION Scrolls To the absolute position. The current position is specified by the nPos parameter.
'SB_THUMBTRACK Drags scroll box To the specified position. The current position is specified by the nPos parameter.
'SB_TOP Scrolls To the upper Left.
Local ScrlInfo As SCROLLINFO
Local st As String
ScrlInfo.cbSize = SizeOf(ScrlInfo)
ScrlInfo.fMask = %SIF_ALL
GetScrollInfo hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo)
Select Case nScrollCode
Case %SB_LINEUP: Decr ScrlInfo.nPos
Case %SB_LINEDOWN: Incr ScrlInfo.nPos
Case %SB_THUMBPOSITION: ScrlInfo.nPos = nPosition
Case %SB_PAGEUP: ScrlInfo.nPos = ScrlInfo.nPos - ScrlInfo.nPage
Case %SB_PAGEDOWN: ScrlInfo.nPos = ScrlInfo.nPos + ScrlInfo.nPage
Case %SB_LINELEFT:
Case %SB_LINERIGHT:
Case %SB_PAGELEFT
Case %SB_PAGERIGHT
Case %SB_ENDSCROLL
End Select
SetScrollInfo hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo), %TRUE
End Function
TrackBar notification messages are also handled by the VSCROLL or HSCROLL handlers (depending on the orientation of your TrackBar). The messages to handle are:
Notification message Reason sent
TB_BOTTOM VK_END
TB_ENDTRACK WM_KEYUP (the user released a key that sent a relevant virtual-key code)
TB_LINEDOWN VK_RIGHT or VK_DOWN
TB_LINEUP VK_LEFT or VK_UP
TB_PAGEDOWN VK_NEXT (the user clicked the channel below or to the right of the slider)
TB_PAGEUP VK_PRIOR (the user clicked the channel above or to the left of the slider)
TB_THUMBPOSITION WM_LBUTTONUP following a TB_THUMBTRACK notification message
TB_THUMBTRACK Slider movement (the user dragged the slider)
TB_TOP VK_HOME
You will need to modify my first post to deal with TrackBar messages rather than ScrollBar messages. You should read up on the various TBM_ messages in your WinAPI help.
Yes, I was just reading about those messages.
Thanks for your help.
Well, after playing around with some code and reading some API documentation, I came up with this solution:
Function FORM1_SLIDER1_WM_HSCROLL ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
nScrollCode As Long, _ ' scroll bar value
nPosition As Long _ ' current scroll bar position
) As Long
Local tPos& ' This variable will hold the TRACKBAR position
tPos& = SendMessage(HWND_FORM1_SLIDER1, %TBM_GETPOS, 0, 0)
FF_ProgressBar_SetPosition HWND_FORM1_PROGRESSBAR1, tPos&
FF_Control_SetText(HWND_FORM1, Str$(tPos&))
End Function
In this example, the code will set a Progress Bar according to the position of the Track Bar, it will show the position on the title of the form and the Track Bar will respond to moving the thumb, clicking on the Track Bar, mouse wheel and keys (Home, End, Page Up, Page Down, arrows)
The minimum value for the track bar is 1 and the maximum 100, other properties such as "Tick frequency" and "Small change" can be adjusted as needed on the FireFly Workspace.