|
-
Dec 30th, 2011, 11:56 PM
#1
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
-
Dec 31st, 2011, 12:57 AM
#2
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
-
Jan 2nd, 2012, 01:59 AM
#3
Re: WM_VSCROLL not picking up scroll wheel?
 Originally Posted by Edgemeal
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
-
Jan 2nd, 2012, 05:11 AM
#4
Re: WM_VSCROLL not picking up scroll wheel?
 Originally Posted by i00
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.
-
Jan 2nd, 2012, 05:46 AM
#5
Re: WM_VSCROLL not picking up scroll wheel?
 Originally Posted by Edgemeal
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
Last edited by i00; Jan 2nd, 2012 at 06:00 AM.
-
Jan 2nd, 2012, 06:01 AM
#6
Re: WM_VSCROLL not picking up scroll wheel?
 Originally Posted by i00
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
-
Jan 2nd, 2012, 07:28 AM
#7
Re: WM_VSCROLL not picking up scroll wheel?
 Originally Posted by i00
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
-
Jan 2nd, 2012, 05:19 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|