Results 1 to 8 of 8

Thread: WM_VSCROLL not picking up scroll wheel?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    WM_VSCROLL not picking up scroll wheel?

    I am overriding the WndProc to capture the WM_VSCROLL of a textbox / RTB... However this does not seem to capture the scroll event if it happens from a scroll wheel of a mouse ... how can i pick this up?... i can't use the MouseWheel event because this occurs when the mouse is scroll wheel is actually turned and not after the content is actually scrolled.

    Thanks in advance,
    Kris

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: WM_VSCROLL not picking up scroll wheel?

    Like this...?
    Code:
    Private Const WM_MOUSEWHEEL As Int32 = &H20A
    
    ' Protected Overrides Sub...
    If m.Msg = WM_MOUSEWHEEL Then
        If (m.WParam.ToInt32) / 65536 > 0 Then ' wheel direction upward
           
        Else ' wheel direction downward
            
        End If
    End If

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: WM_VSCROLL not picking up scroll wheel?

    Quote Originally Posted by Edgemeal View Post
    Like this...?
    Code:
    Private Const WM_MOUSEWHEEL As Int32 = &H20A
    
    ' Protected Overrides Sub...
    If m.Msg = WM_MOUSEWHEEL Then
        If (m.WParam.ToInt32) / 65536 > 0 Then ' wheel direction upward
           
        Else ' wheel direction downward
            
        End If
    End If
    Can't use WM_MOUSEWHEEL either because this ALSO occurs when the mouse is scroll wheel is actually turned and not after the content is actually scrolled.

    Kris

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: WM_VSCROLL not picking up scroll wheel?

    Quote Originally Posted by i00 View Post
    Can't use WM_MOUSEWHEEL either because this ALSO occurs when the mouse is scroll wheel is actually turned and not after the content is actually scrolled.

    Kris
    OK, I only tried it using a form and just called MyBase.WndProc(m) before checking WM_MOUSEWHEEL...

    Code:
    Public Class Form1
    
        Private Const WM_MOUSEWHEEL As Int32 = &H20A
    
        Private Sub Form1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
            Debug.WriteLine("Form Wheel = " & e.Delta)
        End Sub
    
        Protected Overrides Sub WndProc(ByRef m As Message)
    	Dim delta As Integer
            MyBase.WndProc(m)
            If m.Msg = WM_MOUSEWHEEL Then
                delta = m.WParam.ToInt32 \ 65536
                Debug.WriteLine("WndProc Wheel =  " & delta)
            End If
        End Sub
    
    End Class
    Last edited by Edgemeal; Jan 2nd, 2012 at 05:23 AM.

  5. #5

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: WM_VSCROLL not picking up scroll wheel?

    Quote Originally Posted by Edgemeal View Post
    OK, I only tried it using a form and just called MyBase.WndProc(m) before checking WM_MOUSEWHEEL...

    Code:
    Public Class Form1
    
        Private Const WM_MOUSEWHEEL As Int32 = &H20A
    
        Private Sub Form1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
            Debug.WriteLine("Form Wheel = " & e.Delta)
        End Sub
    
        Protected Overrides Sub WndProc(ByRef m As Message)
    	Dim delta As Integer
            MyBase.WndProc(m)
            If m.Msg = WM_MOUSEWHEEL Then
                delta = m.WParam.ToInt32 \ 65536
                Debug.WriteLine("WndProc Wheel =  " & delta)
            End If
        End Sub
    
    End Class
    Did that before you posted ... still doesn't work... i think it may have something to do with the smooth scrolling animations?... either way i need this to work...

    Thanks
    Kris

  6. #6

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: WM_VSCROLL not picking up scroll wheel?

    Quote Originally Posted by i00 View Post
    Did that before you posted ... still doesn't work... i think it may have something to do with the smooth scrolling animations?... either way i need this to work...

    Thanks
    Kris
    JUST REALISED THAT THIS WORKS FOR A TEXTBOX ... I NEED SOMETHING THAT WORKS FOR A RICHTEXTBOX also (as stated in #1) so it looks like i will need a specific case for this... any other ideas???

    Thanks
    Kris

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: WM_VSCROLL not picking up scroll wheel?

    Quote Originally Posted by i00 View Post
    JUST REALISED THAT THIS WORKS FOR A TEXTBOX ... I NEED SOMETHING THAT WORKS FOR A RICHTEXTBOX also (as stated in #1) so it looks like i will need a specific case for this... any other ideas???

    Thanks
    Kris
    I'm not sure how you detect if smooth scrolling is still in effect exactly, possible workarounds,
    1) Override the wheel message and change it to a single line message so there is no smooth scrolling.

    2) Haven't tried this but maybe save the scrollbar position, and after processed start a timer and check the position to see if is still changing...

    Code:
    Public Class RTB
        inherits richtextbox
    
        Protected Overrides Sub WndProc(ByRef m As Message)
    
            If m.Msg = WM_MOUSEWHEEL Or m.Msg = WM_VSCROLL Then
               ' save vert scrollbar position            
               lastVertPos = GetScrollPos(RTB.Handle, SB_VERT) 
            End If
    
            MyBase.WndProc(m)
    
            If m.Msg = WM_MOUSEWHEEL Or m.Msg = WM_VSCROLL Then
    	    timer1.interval = 100ms
    	    timer1.start
            End If
        End Sub
    
     sub timer1.tick(...)
        if  lastVertPos = GetScrollPos(RTB.Handle, SB_VERT)  then
          timer1.stop
       else
          'RTB still scrolling..., save pos.
          lastVertPos = GetScrollPos(RTB.Handle, SB_VERT) 
       end if
     end sub
    
    End Class
    EDIT Detect RichTextBox Smooth Scroll
    Code:
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        Private Structure POINT
            Public x As Integer
            Public y As Integer
        End Structure
    
        Private Const WM_USER As Integer = &H400
        Private Const EM_GETSCROLLPOS As Integer = WM_USER + 221
        Private Const EM_SETSCROLLPOS As Integer = WM_USER + 222
    
        <DllImport("user32.dll", EntryPoint:="SendMessage", ExactSpelling:=False, CharSet:=CharSet.Auto, SetLastError:=True)> _
        Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, ByRef lParam As POINT) As Integer
        End Function
    
        Private scrollPos As New POINT
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Timer1.Interval = 50
        End Sub
    
        Private Sub RichTextBox1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseWheel
            SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, IntPtr.Zero, scrollPos)
            Timer1.Start()
        End Sub
    
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            Dim p As New POINT
            'get scrollbar pos.
            SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, IntPtr.Zero, p)
            ' compare scroll pos.
            If scrollPos.y = p.y Then
                Timer1.Stop()
                Debug.WriteLine("scrolling stopped.")
            Else
                ' save scrollbar pos.
                scrollPos.y = p.y
                Debug.WriteLine("smooth scrolling.")
            End If
        End Sub
    
    End Class
    Last edited by Edgemeal; Jan 2nd, 2012 at 08:23 AM. Reason: minor changes on idea

  8. #8

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: WM_VSCROLL not picking up scroll wheel?

    Hrm ... wish there was a better way ...

    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width