[AccessD] Detecting if a vertical scrollbar is present

William Benson (VBACreations.Com) vbacreations at gmail.com
Sat Jun 8 12:21:19 CDT 2013


I am positioning controls based on the form's windowwidth value, trying to
establish how wide a control should be based on contents, right-flush based
on its required width and the form's windowwidth property. I am finding that
the vertical scrollbar does appears or does not appear according to
necessity, but this does not affect the windowwidth property.

I either need a way to detect if the vertical scrollbar is present and
adjust for its width, or I need a different property to use for usable width
of a form (can't find such a property).

Any help out there? I have tried the function I am posting below but it is
not telling me there is a vertical scrollbar.

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const GWL_HWNDPARENT = (-8)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

Function GetScrollStatus(frm As Form) As Long

'frm.Hwnd
    Dim wndStyle As Long
    
    ' Retrieve the window style of the control.
    wndStyle = GetWindowLong(frm.hwnd, GWL_STYLE)

    ' Test if the horizontal scroll bar style is present
    ' in the window style, indicating that a horizontal
    ' scroll bar is visible.
    If (wndStyle And WS_HSCROLL) <> 0 Then
        GetScrollStatus = 1 'A horizontal scroll bar is visible."
    End If
  
    ' Test if the vertical scroll bar style is present
    ' in the window style, indicating that a vertical
    ' scroll bar is visible.
    If (wndStyle And WS_VSCROLL) <> 0 Then  'FALSE EVEN WHEN FRM HAS A
VERTICAL SCROLLBAR SHOWING
        GetScrollStatus = GetScrollStatus + 2
    End If
End Function 



More information about the AccessD mailing list