DoReaderMode (comctl32)
Last changed: anonymous

.
Summary
Enters the control in 'ReaderMode' a mouse scrolling mode that allows you to scroll in any direction by moving the mouse pointer. Callbacks are used to inform the control of the offset it should scroll. The Control is responsible for updating the scroll position. The function must be passed the READERMODEINFO structure. This function has no public header and must be referenced as ordinal 383, as per MSDN documentation.

C# Signature:

[DllImport("comctl32.dll", SetLastError=true)]
static extern TODO DoReaderMode(TODO);

VB Signature:

     <DllImport("Comctl32.dll", EntryPoint:="#383", _
         CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Sub DoReaderMode(ByRef prmi As READERMODEINFO)

    End Sub

User-Defined Types:

READERMODEINFO

RECT

MSG

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

<DllImport("Comctl32.dll", EntryPoint:="#383", _
         CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Sub DoReaderMode(ByRef prmi As READERMODEINFO)

    End Sub

    <StructLayout(LayoutKind.Sequential)>
    Private Structure READERMODEINFO
        Dim cbSize As UInt32
        Dim hwnd As IntPtr
        Dim fFlags As UInt32
        Dim prc As IntPtr
        Dim pfnScroll As ReaderScrollCallbackDelegate
        Dim fFlags2 As TranslateDispatchCallbackDelegate
        Dim lParam As IntPtr
    End Structure

    Private Sub SetReaderMode()

        Dim SetReaderModeInfo As READERMODEINFO

        Dim rect As New RECT(Me.Width / 2 - 20, Me.Height / 2 - 20, Me.Width / 2 + 20, Me.Height / 2 + 20)

        Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rect))
        Marshal.StructureToPtr(rect, pnt, True)

        SetReaderModeInfo = New READERMODEINFO
        SetReaderModeInfo.hwnd = Me.Handle
        SetReaderModeInfo.fFlags = 1
        SetReaderModeInfo.prc = pnt
        SetReaderModeInfo.pfnScroll = New ReaderScrollCallbackDelegate(AddressOf ReaderScrollCallback)
        SetReaderModeInfo.fFlags2 = New TranslateDispatchCallbackDelegate(AddressOf TranslateDispatchCallback)
        SetReaderModeInfo.lParam = IntPtr.Zero
        SetReaderModeInfo.cbSize = Marshal.SizeOf(SetReaderModeInfo)

        DoReaderMode(SetReaderModeInfo)

        Marshal.FreeHGlobal(pnt)

    End Sub

    Private Delegate Function ReaderScrollCallbackDelegate(ByRef prmi As READERMODEINFO, dx As Integer, dy As Integer) As Boolean

    Private Delegate Function TranslateDispatchCallbackDelegate(ByRef lpmsg As MSG) As Boolean

    Private Function TranslateDispatchCallback(ByRef lpmsg As MSG) As Boolean
        Return False
    End Function

    Dim CallCount As Integer = 0
    Private Function ReaderScrollCallback(ByRef prmi As READERMODEINFO, dx As Int32, dy As Int32) As Boolean
        HScrollPos += (dx)
        VScrollPos += (dy)
        CallCount += 1
        If CallCount > 5 Then
        Invalidate()
        CallCount = 0
        End If
        Return True
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
    End Function

    Private Const SB_HORZ As Integer = &H0
    Private Const SB_VERT As Integer = &H1

    ''' <summary>
    ''' Gets and Sets the Horizontal Scroll position of the control.
    ''' </summary>
    Public Property HScrollPos() As Integer
        Get
        Return GetScrollPos(Me.Handle, SB_HORZ)
        End Get
        Set(ByVal value As Integer)
        SetScrollPos(Me.Handle, SB_HORZ, value, True)
        End Set
    End Property

    ''' <summary>
    ''' Gets and Sets the Vertical Scroll position of the control.
    ''' </summary>
    Public Property VScrollPos() As Integer
        Get
        Return GetScrollPos(Me.Handle, SB_VERT)
        End Get
        Set(ByVal value As Integer)
        SetScrollPos(Me.Handle, SB_VERT, value, True)
        End Set
    End Property

Documentation