dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Disabling smooth scroll in a RichTextBox (RTB)?

  1. #1
    Join Date
    Oct 2006
    Posts
    6

    Question Disabling smooth scroll in a RichTextBox (RTB)?

    I've search everywhere and tried a bunch of things, but I can't find a way to disable smooth scroll in my rich text box. I'm using the RTB with coloured text, so I can't use the standard TextBox control. Everything's working okay except for the smooth scrolling effect in my RTB.

    I've attached some sample code to show you what I mean. Maybe the RTB will scroll normally for you, I don't know. My mouse is set to scroll 3 lines at a time in the control panel, and it works great for the rest of the comp. But in my program if I slam my mouse wheel up/down a bunch of times really fast, I have to wait a few seconds for the window to scroll and catch up.

    This smooth scroll crap in the RTB really sucks. Any way to disable it to get normal fast line-scrolling back?
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2006
    Posts
    145

    Re: Disabling smooth scroll in a RichTextBox (RTB)?

    what you'll have to do is override the default mouse scroll. So, you subclass the RTB, look for the WM_MOUSEWHEEL messages and send a EM_LINESCROLL message instead.

    In module:
    Code:
    Option Explicit
    
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Private 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
    
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
        Any, source As Any, ByVal bytes As Long)
    
    Private Const GWL_WNDPROC = (-4)
    Private Const WM_MOUSEWHEEL = &H20A
    Private Const EM_LINESCROLL = &HB6
    
    Private lPrevProc As Long
    
    Public Sub SubClass(ByVal lhWnd As Long)
        lPrevProc = SetWindowLong(lhWnd, GWL_WNDPROC, AddressOf WndProc)
    End Sub
    
    Private Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim intDir As Integer
        
        If Msg = WM_MOUSEWHEEL Then
            CopyMemory intDir, ByVal VarPtr(wParam) + 2, 2
            intDir = -Sgn(intDir) * 3
            WndProc = CallWindowProc(lPrevProc, hWnd, EM_LINESCROLL, 0&, intDir)
        Else
            WndProc = CallWindowProc(lPrevProc, hWnd, Msg, wParam, lParam)
        End If
    End Function
    
    Public Sub UnSubClass(ByVal lhWnd As Long)
        SetWindowLong lhWnd, GWL_WNDPROC, lPrevProc
    End Sub
    Attached Files Attached Files

  3. #3
    Join Date
    Oct 2006
    Posts
    6

    Re: Disabling smooth scroll in a RichTextBox (RTB)?

    Quote Originally Posted by bushmobile
    what you'll have to do is override the default mouse scroll. So, you subclass the RTB, look for the WM_MOUSEWHEEL messages and send a EM_LINESCROLL message instead.
    Right on.. Thank you very much.. Just the code I was looking for. I thought I was going to be stuck with the slow pixel scrolling. It was even getting slower and slower as more text got added, but this should help greatly.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)