WM_MOUSEWHEEL event is not working correctly in WinProc for Visual Basic 6.0

Hi

I am trying to use the mousewheel to move the vertical scrollbar for a PictureBox that resides within another PictureBox .   This code sort of works but the wrong scrollbar gets updated (the horizontal one) the mousewheel should move only the vertical one. I am not an expert on low level windows API and messages so please be gentle :)


Thanks

'==============================================================================
'      METHOD: WndProc
' DESCRIPTION:
'==============================================================================
Private Function WndProc(ByVal hOwner As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim nOldPos As Long, n As Long
   
    Select Case wMsg
        Case WM_VSCROLL, WM_HSCROLL
            ' A SCROLLBAR MESSAGE IS RECEIVED. RETRIEVE AND PROCESS THE INFORMATION.
            ' KEEP TRACK OF THE OLD POSITION AS WE WILL USE THIS LATER TO CALCULATE
            ' OUR NEW POSITION
            Call GetScrollInfo(hOwner, wMsg - WM_HSCROLL, s)
            nOldPos = s.nPos
           
            Select Case GetLoWord(wParam)
                Case SB_LINEDOWN
                    'THE SCROLLBAR DOWN BUTTON IS PRESSED
                    s.nPos = s.nPos + s.nPage \ 10
                Case SB_LINEUP
                    'THE SCROLLBAR UP BUTTON IS PRESSED
                    s.nPos = s.nPos - s.nPage \ 10
                Case SB_PAGEDOWN
                    ' HORIZONTAL SCROLLBAR TO THE RIGHT OF THE SLIDER IS CLICKED
                    ' VERTICAL SCROLLBAR BELOW THE SLIDER IS CLICKED
                    s.nPos = s.nPos + s.nPage
                Case SB_PAGEUP
                    ' HORIZONTAL SCROLLBAR TO THE LEFT OF THE SLIDER IS CLICKED
                    ' VERTICAL SCROLLBAR ABOVE THE SLIDER IS CLICKED
                    s.nPos = s.nPos - s.nPage
                Case SB_THUMBTRACK
                    ' HORIZONTAL SLIDER IS BEING DRAGGED OR CLICKED
                    ' VERTICAL SLIDER IS BEING DRAGGED OR CLICKED
                    s.nPos = GetHiWord(wParam)
                Case SB_ENDSCROLL
                    ' A SCROLLING OPERATION JUST ENDED.
                    If (s.nPos = 0) Then
                        ' THE SCROLL IS POSITIONED ALL THE WAY TO THE TOP OR LEFT POSITION.
                        ' WE MAY NEED TO HIDE THE HORIZONTAL OR VERTICAL SCROLLBAR SLIDER
                        ' IF IT IS NO LONGER REQUIRED.
                        Call AdjustScrollInfo(hOwner)
                        Exit Function
                    End If
            End Select
                       
            'UPDATES THE SCROLLBAR PROPERTIES, FORCING IT TO BE REDRAWN
            Call SetScrollInfo(hOwner, wMsg - WM_HSCROLL, s, True)
            ' READ THE UPDATED SCROLLBAR INFORMATION
            Call GetScrollInfo(hOwner, wMsg - WM_HSCROLL, s)
           
            If (wMsg = WM_VSCROLL) Then
                ' SCROLL OUR WINDOW VERTICALLY
                Call ScrollWindowByNum(hOwner, 0, nOldPos - s.nPos, 0, 0)
            Else
                ' SCROLL OUR WINDOW HORIZONTALLY
                Call ScrollWindowByNum(hOwner, nOldPos - s.nPos, 0, 0, 0)
            End If
           
'============================================================================
' NEW CODE  ADDED -- DOESNT WORK
'
'      Case WM_MOUSEWHEEL
'          
'          Call GetScrollInfo(hOwner, wMsg - WM_MOUSEWHEEL, s)
'          nOldPos = s.nPos
'        
'          If (wParam \ 65536) < 0 Then
'              s.nPos = s.nPos + s.nPage / 50
'          Else
'              s.nPos = s.nPos - s.nPage / 50
'          End If
'          
'          Call SetScrollInfo(hOwner, wMsg - WM_MOUSEWHEEL, s, True)
'          Call GetScrollInfo(hOwner, wMsg - WM_MOUSEWHEEL, s)
'          Call ScrollWindowByNum(hOwner, 0, nOldPos - s.nPos, 0, 0)
'        
'
' NEW CODE  ADDED -- DOESNT WORK
'============================================================================
           
           
           
           
        Case WM_DESTROY
            Call RemoveProp(hOwner, "SB_POS")
            Call RemoveProp(hOwner, "ORIGIN_WIDTH")
            Call RemoveProp(hOwner, "ORIGIN_HEIGHT")
            Call SetWindowLong(hOwner, GWL_WNDPROC, GetProp(hOwner, "OLDPROC"))
       Case Else
    End Select
   
    WndProc = CallWindowProc(GetProp(hOwner, "OLDPROC"), hOwner, wMsg, wParam, lParam)
End Function
const71Asked:
Who is Participating?
 
InteqamCommented:
well, i think i provided what is needed, unless const71 indecates something else
0
 
InteqamCommented:
ScrollLines = (WheelPoints \ WHEEL_DELTA) * WheelScrollLines

Where WHEEL_DELTA is defined in the Platform SDK as 120 and WheelScrollLines is the value returned by the SPI_GETWHEELSCROLLLINES system settings parameter (with a default of 3.

By default, the class automatically scrolls the bar by this number of lines in the vertical direction whenever the mouse wheel is used. One line is assumed to be one SmallChange increment. However, you can customise this behaviour by responding to the MouseWheeel event. This event provides the scroll bar which will be changed and the amount by which it will be scrolled. Both are passed by reference so you can change them. So if you want the mouse wheel to scroll horizontally, you can change the eBar parameter; if you want the scroll amount to be different, or no scroll to occur, then change the lDelta amount.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.