?
Solved

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

Posted on 2006-05-17
3
Medium Priority
?
2,089 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:const71
  • 2
2 Comments
 
LVL 7

Expert Comment

by:Inteqam
ID: 16707201
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
 
LVL 7

Accepted Solution

by:
Inteqam earned 1500 total points
ID: 16876740
well, i think i provided what is needed, unless const71 indecates something else
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question