Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to detect if scrollbar is visible?

93 views
Skip to first unread message

Chris

unread,
Mar 14, 2003, 9:37:27 AM3/14/03
to
Hi,

I am using a 3rd party grid control that displays a
vertical scrollbar when the grid fills up. I need to know
if the vertical scrollbar is visible or not. I have been
told that I can use the API to do this, but I don't know
how. Anyone have an idea? Thanks!

Christopher Hughes

Tom Esh

unread,
Mar 14, 2003, 10:25:55 AM3/14/03
to

You can check the state of the WS_VSCROLL (or WS_HSCROLL) window style
bit with the Api.

Ex:
'api declarations - bas module...
Public Const GWL_STYLE = (-16)
Public Const WS_VSCROLL = &H200000
Public Const WS_HSCROLL = &H100000
Public Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

'usage - anywhere...
Dim Style As Long
Style = GetWindowLong(Grid1.hwnd, GWL_STYLE)
If (Style And WS_VSCROLL) Then
'...vert scrollbar is visible...
End If


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)

Chris

unread,
Mar 14, 2003, 12:38:34 PM3/14/03
to
Great, that's what I was looking for. Thanks!

Is there also a way I could disable the scrollbar
completely using API ?

Chris

Tom Esh

unread,
Mar 14, 2003, 1:26:44 PM3/14/03
to
On Fri, 14 Mar 2003 09:38:34 -0800, "Chris"
<Christopher_nospam@nospam_videog.demon.nl> wrote:
>Is there also a way I could disable the scrollbar
>completely using API ?

You can use EnableScrollBar or perhaps ShowScrollBar, whichever works
best. Not sure how the Grid control behaves in this regard, but the
control may re-set the state when the contents change or the window is
redrawn. (i.e. you may not be able to just set it once and expect it
to stay that way.)

'declares...
' Scroll Bar Constants
Public Const SB_HORZ = 0&
Public Const SB_VERT = 1&
Public Const SB_CTL = 2&
Public Const SB_BOTH = 3&

' EnableScrollBar() flags
Public Const ESB_ENABLE_BOTH = &H0
Public Const ESB_DISABLE_BOTH = &H3
Public Const ESB_DISABLE_LEFT = &H1
Public Const ESB_DISABLE_RIGHT = &H2
Public Const ESB_DISABLE_UP = &H1
Public Const ESB_DISABLE_DOWN = &H2
Public Declare Function EnableScrollBar Lib "user32" _
(ByVal hwnd As Long, ByVal wSBflags As Long, _
ByVal wArrows As Long) As Long
Public Declare Function ShowScrollBar Lib "user32" _
(ByVal hwnd As Long, ByVal wBar As Long, _
ByVal bShow As Long) As Long

'usage...
'disable vert scrollbar...
EnableScrollBar Grid1.hwnd, SB_VERT, ESB_DISABLE_BOTH

'...or hide it...
ShowScrollBar Grid1.hwnd, SB_VERT, 0

0 new messages