Determine Which Scrollbars are Visible

Sometimes, it’s useful to know whether a control is displaying vertical scrollbars, horizontal scrollbars, both horizontal and vertical, or no scrollbars at all. For instance, when determining the amount of room inside a control, you might have to take into account the space taken up by the scrollbars. This function, written in VB5, returns an enumerated constant representing the scrollbar state of the given control:

 Private Declare Function GetWindowLong Lib "user32" Alias _	"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex _	As Long) As Long'GetWindowLong ConstantsPrivate Const GWL_STYLE = (-16)Private Const WS_HSCROLL = &H100000Private Const WS_VSCROLL = &H200000'Used by VisibleScrollBars functionEnum Enum_VisibleScrollBars	vs_none = 0	vs_vertical = 1	vs_horizontal = 2	vs_both = 4End EnumPublic Function VisibleScrollBars(ControlName As Control) _	As Enum_VisibleScrollBars	'	' Returns an enumerated type constant depicting the 	' type(s) of scrollbars visible on the passed control.	'	Dim MyStyle As Long	MyStyle = GetWindowLong(ControlName.hWnd, GWL_STYLE)	'Use a bitwise comparison	If (MyStyle And (WS_VSCROLL Or WS_HSCROLL)) = _		(WS_VSCROLL Or WS_HSCROLL) Then		'Both are visible		Let VisibleScrollBars = vs_both	ElseIf (MyStyle And WS_VSCROLL) = WS_VSCROLL Then		'Only Vertical is visible		Let VisibleScrollBars = vs_vertical	ElseIf (MyStyle And WS_HSCROLL) = WS_HSCROLL Then		'Only Horizontal is visible		Let VisibleScrollBars = vs_horizontal	Else		'No scrollbars are visible		Let VisibleScrollBars = vs_none	End IfEnd Function

Hard-coding a scrollbar with a predetermined width or height is not a good idea because these might vary depending on the user’s display settings (accessibility options, desktop themes, and so on). Call GetSystemMetrics to always ensure the proper value for this metric.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may