Mouse Scroller


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Mouse Scroller

  1. #1
    Join Date
    Jun 2006
    Posts
    39

    Talking Mouse Scroller

    Hi EveryOne
    I want to Know How can I detect when the mouse middle((Scroller)) botton is scrolling Down or up or clicking.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45
    You can do it using a Hook, here is the code:
    Code:
    'Definitions
    Public 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
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Public Const GWL_WNDPROC = (-4)
    Private Const WM_MOUSEWHEEL = &H20A
    
    'Variables used
    Dim Last as Long
    Dim FormWnd as Long
    
    'Here is the hook
    FormWnd = FormName.hWnd
    Last = SetWindowLong(FormWnd, GWL_WNDPROC, AddressOf MouseWheelWndProc)
    
    'Here is the unhook
    Call SetWindowLong(FormWnd, GWL_WNDPROC, Last) 'You must unhook the hook before exiting or your program will crash!
    
    'Here is the function MouseWheelWndProc, it must be definied in a public modue
    Public Function MouseWheelWndProc (ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If iMsg = WM_MOUSEWHEEL And hWnd = FormWnd Then
       'Call a function in FormName
       'To see if the wheel is going up or down: Value = (lParam And &HFFFF&)
    End If
    
    MouseWheelWndProc = CallWindowProc(Last, hWnd, iMsg, wParam, lParam)
    End Function
    This code will hook one window if you want to hook more than one you will have to store the LastProcedure addresses of each form to use it with the CallWindowProc and to unhook at the end.
    I think you can find some samples on google.

  3. #3
    Join Date
    Jun 2006
    Posts
    39
    How Can I Call it?

  4. #4
    Join Date
    Jun 2006
    Posts
    39
    How Can I Call it for Controll?

  5. #5
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45
    You create a public sub for the control (I will work as an event you will call after checking the message).
    All you need is the hWnd of your control (if it's a usercontrol then write UserControl.hWnd)
    The code will work when the control will have focus and you'll scroll.

  6. #6
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45
    Go to: http://www.andreavb.com/tip060008.html
    Here is some information about how to do it.

  7. #7
    Join Date
    Jun 2006
    Posts
    39
    thanks for your help but I don`t know why, i can`t use it, If you could ,please just send a complectly example (with module,form,commandbotton)
    Thanks again

  8. #8
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45
    Here is the code
    Sorry but I havent much time so there is not lot of comments in it.
    Attached Files Attached Files

  9. #9
    Join Date
    Jun 2006
    Posts
    39
    Thanks For your help that was really cool great and usefull

Similar Threads

  1. Replies: 10
    Last Post: 09-26-2005, 09:43 PM
  2. Capturing Mouse Movements outside of screen resolution
    By Chris Eastwood in forum VB Classic
    Replies: 4
    Last Post: 03-28-2002, 02:26 PM
  3. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 4
    Last Post: 12-19-2000, 01:52 PM
  4. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 0
    Last Post: 12-19-2000, 12:13 PM
  5. Mouse Hook
    By Michael Culley in forum VB Classic
    Replies: 0
    Last Post: 12-10-2000, 08:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center