Notifications
Clear all

[Closed] Remember scroll position?? DotNet WebBrowser

I have setup a little max webBrowser in max using System.Windows.Forms.WebBrowser.
I am saving the width, height and pos info in an ini file so it opens to the same place, but wanted also to be able to set the scroll position. Is there a way to do this?

1 Reply

Hey floopyb, I’ve writen a custom class that set’s the vertical scroll. You can have a look at the GetScrollInfo and SetScrollInfo for more information, either way, I’ll post here the code for my custom class, maybe it can help you out as a starting point. Cheers.

Imports System.Runtime.InteropServices.Marshal
Public Class dnVScroll
    Private Const WM_VSCROLL = &H115
    Private Const SB_VERT = 1

    Private Const SIF_RANGE = &H1
    Private Const SIF_PAGE = &H2
    Private Const SIF_POS = &H4
    Private Const SIF_DISABLENOSCROLL = &H8
    Private Const SIF_TRACKPOS = &H10
    Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)

    Private Const SB_LINEUP = 0
    Private Const SB_LINEDOWN = 1
    Private Const SB_PAGEUP = 2
    Private Const SB_PAGEDOWN = 3
    Private Const SB_THUMBPOSITION = 4
    Private Const SB_THUMBTRACK = 5
    Private Const SB_TOP = 6
    Private Const SB_BOTTOM = 7
    Private Const SB_ENDSCROLL = 8

    Private Structure SCROLLINFO
        Dim cbSize As Long
        Dim fMask As Long
        Dim nMin As Long
        Dim nMax As Long
        Dim nPage As Long
        Dim nPos As Long
        Dim nTrackPos As Long
    End Structure

    Private Declare Function GetScrollInfo Lib "user32" _
      (ByVal hWnd As Long, _
       ByVal n As Long, _
    ByVal lpScrollInfo As SCROLLINFO) As Long

    Private Declare Function SetScrollInfo Lib "user32" _
      (ByVal hWnd As Long, _
       ByVal n As Long, _
    ByVal lpcScrollInfo As SCROLLINFO, _
       ByVal fRedraw As Long) As Long

    Private Declare Function GetScrollPos Lib "user32.dll" ( _
            ByVal hWnd As IntPtr, _
            ByVal nBar As Integer) As Integer

    Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" ( _
            ByVal hwnd As IntPtr, _
            ByVal wMsg As Integer, _
            ByVal wParam As Integer, _
            ByVal lParam As Integer) As Boolean

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
            ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Integer) As Boolean
    Public Function SetVScroll(ByVal hWnd As Long, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If e.Delta < 0 Then
            SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, 0)
        Else
            SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, 0)
        End If
    End Function
End Class

And here’s the link for my custom class – http://forums.cgsociety.org/attachment.php?attachmentid=142818

Maxscript example:

(
	dotnet.loadAssembly @"KClasses.dll" --Dont forget to put the correct path here
	
	local hForm = dotNetObject "MaxCustomControls.MaxForm"
	hForm.Size = dotNetObject "System.Drawing.Size" 290 290
	hForm.FormBorderStyle = (dotnetclass "System.Windows.Forms.FormBorderStyle").FixedToolWindow
	hForm.Text = ""
	hForm.ShowInTaskbar = False
	
	local lstview1 = dotNetObject "System.Windows.Forms.ListView"
	lstview1.backcolor=(dotnetclass "System.Drawing.Color").DarkCyan
	lstview1.location=dotNetObject "System.Drawing.Point" 10 10
	lstview1.name="lstview1"
	
	
	local lstview2 = dotNetObject "System.Windows.Forms.ListView"
	lstview2.location=dotNetObject "System.Drawing.Point" 150 10
	lstview2.name="lstview2"
	
	local lstview3 = dotNetObject "System.Windows.Forms.ListView"
	lstview3.location=dotNetObject "System.Drawing.Point" 10 150
	lstview3.name="lstview3"
	
	local lstview4 = dotNetObject "System.Windows.Forms.ListView"
	lstview4.location=dotNetObject "System.Drawing.Point" 150 150
	lstview4.name="lstview4"
		
	local vScroll=dotnetobject "KClasses.dnVScroll"

	hform.controls.add(lstview1)
	hform.controls.add(lstview2)
	hform.controls.add(lstview3)
	hform.controls.add(lstview4)
	
	
	
	seed(timestamp())
	for i=1 to 20 do
	(
		lstview1.items.add ((random 1 256) as string)
		lstview2.items.add ((random 1 256) as string)
		lstview3.items.add ((random 1 256) as string)
		lstview4.items.add ((random 1 256) as string)
	)
	
	fn lstview1_MouseWheel sender eb =
	(
		eb.handled=true
		vScroll.SetVScroll sender.handle eb
		vScroll.SetVScroll lstview2.handle eb
		vScroll.SetVScroll lstview3.handle eb
		vScroll.SetVScroll lstview4.handle eb
		
	)
	
	dotnet.addEventHandler lstview1 "MouseWheel" lstview1_MouseWheel	
	
	hForm.ShowModeless()
)