Click to See Complete Forum and Search --> : horizontal scroll position in a richtextbox


tatou
February 7th, 2000, 09:26 PM
i posted a similar question a few days ago about vertical scrolling...

i am creating a control that extends a richtextbox and autoformats all of its content. however, my formatting routine jumps the cursor back to the beginning. i now know how to store the currently scrolled vertical position, run my formatting routine, and jump back to its previously scrolled position - so that the user doesn't see any change - using the API.
(see http://codeguru.developer.com/bbs/wt/showpost.pl?Board=vb&Number=14499&page=0&view=collapsed&mode=threaded&sb=5)

is there a way to do this for the horizontal scroll position as well?

Chris Eastwood
February 8th, 2000, 03:38 AM
You can get all kinds of information from a scroll bar using the GetScrollInfo API (that goes for TextBoxes and RichTextBoxes).

Here's some sample code (put into a form ) :


option Explicit
'
private Const SB_CTL = 2
private Const SB_HORZ = 0
private Const SB_VERT = 1
'
private Declare Function GetScrollInfo Lib "user32" (byval hWnd as Long, byval n as Long, lpScrollInfo as SCROLLINFO) as Long
'
private Type SCROLLINFO
cbSize as Long
fMask as Long
nMin as Long
nMax as Long
nPage as Long
nPos as Long
nTrackPos as Long
End Type
'
private Const SIF_RANGE as Long = &H1
private Const SIF_PAGE as Long = &H2
private Const SIF_POS as Long = &H4
private Const SIF_DISABLENOSCROLL as Long = &H8
private Const SIF_TRACKPOS as Long = &H10
private Const SIF_ALL as Long = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
'
public Enum eScrollBar
sbHorizontal = 0
sbVertical = 1
End Enum
'
public Function GetScrollBarPos(byval lHwnd as Long, byval ScrollBar as eScrollBar) as Long
'
Dim lFlag as Long
Dim sbInfo as SCROLLINFO
Dim lRet as Long
'
sbInfo.cbSize = len(sbInfo)
sbInfo.fMask = SIF_POS
lFlag = ScrollBar
'
lRet = GetScrollInfo(lHwnd, lFlag, sbInfo)
'
If lRet > 0 then ' ok
GetScrollBarPos = sbInfo.nPos
End If
'
End Function




You can now get the position of either the Vertical or Horizontal scrollbar by simply calling the GetScrollBarPos routine on the HWND of the control.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb