Mouse scroll button to control volume in Visual Basic 6.0 and C++ ?

I have managed to figure out how to control the volume in Visual Basic and I have one working example for the main volume control in C++, however what I want to know is how do you use the scroll button on a mouse to control the volume like they have done in winamp ??

I am looking for working examples in visual basic and C++ as well as tutorials or resources that explain how to do it.

Thank you for the time and effort.
LVL 23
Shane Russell2nd Line Desktop SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rushtoshankarSr Manager Software DevelopmentCommented:

      if you are developing your application in MFC then you can do this in the following manner..
just override the main window's
PreTranslateMessage(MSG* pMsg)  or OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)

in PreTranslateMessage(MSG* pMsg) function you can do as follows
fwKeys = LOWORD(wParam);    // key flags

zDelta = (short) HIWORD(wParam);    // wheel rotation

xPos = (short) LOWORD(lParam);    // horizontal position of pointer

yPos = (short) HIWORD(lParam);    // vertical position of pointer

Value of the low-order word of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: Value
 Set if the CTRL key is down.
 Set if the left mouse button is down.
 Set if the middle mouse button is down.
 Set if the right mouse button is down.
 Set if the SHIFT key is down.

The value of the high-order word of wParam. Indicates the distance that the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.

Value of the low-order word of lParam. Specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen.

Value of the high-order word of lParam. Specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen.

and in OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)  function same as above function...

nFlags = fwKeys

zDelta = zDelta

xPos, yPos take this from pt
Shane Russell2nd Line Desktop SupportAuthor Commented:
Any chance you or someone else can give me an example in Visual Basic 6.0 and show me where to put the code, like in a module, etc. Thank you for that example. Also what exactly is MFC ? Thank you for the time, effort and help !
Ok, you need a windows message hook in vb in order to do this.

1. Create a new standard EXE project
2. On Form1, put a label on it, call Label1
3. Copy and paste the code below:
' =========== Form1 starts ===============
Option Explicit

Private Sub Form_Load()
    ' initialise window message hook
    NextProcs = SetWindowLong(Me.hwnd, GWL_WNDPROC, _
                                    AddressOf WindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ' de-hook
    Call SetWindowLong(Me.hwnd, GWL_WNDPROC, NextProcs)

End Sub
' =========== Form1 ends ===============

4. Create a new module, call Module1
5. Copy and past the code below:

' =========== Module1 starts ===============
Option Explicit

        X As Long
        Y As Long
End Type

    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type

Private Const WM_GETMINMAXINFO = &H24
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_VSCROLL = &H115

Public NextProcs As Long
Public Const GWL_WNDPROC = -4
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) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal wndrpcPrev As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, lParam As Any) As Long

' MouseKeys
' 8 = ctrl key pressing while doing mouse scroll
' 4 = shift key pressing
' 0 = others
Public Sub GoMouseWheel(ByVal MouseKeys As Long, ByVal Rotation As Long, _
                            ByVal Xpos As Long, ByVal Ypos As Long)

    If Rotation > 0 Then
        'scroll up
        'scroll down
    End If

End Sub

' used to hook windows messages
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
                            ByVal wParam As Long, ByVal lParam As Long) As Long

    On Error Resume Next
    Select Case uMsg
        Case WM_MOUSEWHEEL
        'MouseKeys --> wp And 65535
        ' Rotation --> wp / 65536
        ' Xpos --> lp And 65535
        ' Ypos --> lp / 65536
        'MyForm.MouseWheel MousKeys, Rotation, Xpos, Ypos
            Form1.Label1.Caption = "Key: " & CStr(CLng(wParam And 65535)) & _
                                    ", Rotation: " & CStr(CLng(wParam / 65536)) & _
                                    ", xPos: " & CStr(CLng(lParam And 65535)) & _
                                    ", yPos: " & CStr(CLng(lParam / 65536))
            GoMouseWheel CLng(wParam And 65535), CLng(wParam / 65536), _
              CLng(lParam And 65535), CLng(lParam / 65536)
    End Select
    ' put back to the windows stuff
    WindowProc = CallWindowProc(NextProcs, hwnd, uMsg, wParam, ByVal lParam)
End Function
' =========== Module1 ends ===============

That should give you what you want.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shane Russell2nd Line Desktop SupportAuthor Commented:
Thanks for both of them answers ! Is there anyway to speedy up how fast or slow the scroll button moves a slider control lin visual basic like they do in winamp to control the volume ? because at the minute I can make it move but it takes a lot of scrolling to move it up or down in terms of moving the slider.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.