William Benson (VBACreations.Com)
vbacreations at gmail.com
Sat Jun 8 13:30:46 CDT 2013
The vertical scroll bar takes up room in viewable area, without affecting the windowwidth of the form. This is making it hard for me to position controls on the form the way I want to. I have been trying to use code from Steve Lebans, to verify if a vertical scrollbar is present. I don't really understand the code but it is telling me "no". Essentially, I pass the form to the code, and it loops through all the children of the form's window. The number of child windows appears to be the same regardless whether the active form has scrollbars visible or not. So I don't think that the scroll bars I am seeing are child windows of the form itself, but more of the access window itself. Steve's code was written for Access 2000. Anyone see where I am going with this and have any advice? Option Compare Database Option Explicit 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 Declare Function apiGetScrollInfo _ Lib "user32" Alias "GetScrollInfo" (ByVal hWnd As Long, _ ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long Private Declare Function apiGetClassName Lib "user32" _ Alias "GetClassNameA" _ (ByVal hWnd As Long, _ ByVal lpClassname As String, _ ByVal nMaxCount As Long) _ As Long Private Declare Function apiGetWindowLong Lib "user32" _ Alias "GetWindowLongA" _ (ByVal hWnd As Long, _ ByVal nIndex As Long) _ As Long Private Declare Function apiGetWindow Lib "user32" _ Alias "GetWindow" _ (ByVal hWnd As Long, _ ByVal wCmd As Long) _ As Long Private Const GWL_STYLE = (-16) ' Window Style Flags Private Const WS_VISIBLE = &H10000000 Private Const WS_VSCROLL = &H200000 ' Scroll Bar Styles Private Const SBS_HORZ = &H0& Private Const SBS_VERT = &H1& Private Const SBS_SIZEBOX = &H8& ' Scroll Bar Constants Private Const SB_CTL = 2 Private Const SB_VERT = 1 ' Windows Message Constant Private Const WM_VSCROLL = &H115 Private Const WM_HSCROLL = &H114 ' GetWindow() Constants Private Const GW_HWNDNEXT = 2 Private Const GW_CHILD = 5 'Private Const GW_MAX = 5 Public Function fGetScrollBarPos(frm As Form) As Long ' Return ScrollBar Thumb position ' for the Vertical Scrollbar attached to the ' Form passed to this Function. Dim hWndSB As Long Dim lngret As Long Dim sInfo As SCROLLINFO ' Call function to get handle to ' ScrollBar control if it is visible hWndSB = fIsScrollBar(frm) If hWndSB = -1 Then fGetScrollBarPos = False Exit Function End If ' Get the window's ScrollBar position 'lngret = apiGetScrollInfo(hWndSB, SB_CTL, sInfo) lngret = apiGetScrollInfo(hWndSB, SB_VERT, sInfo) 'Debug.Print "nPos:" & sInfo.nPos & " nPage:" & sInfo.nPage & " nMax:" & sInfo.nMax 'MsgBox "getscrollinfo returned " & sInfo.nPos & " , " & sInfo.nTrackPos fGetScrollBarPos = sInfo.nPos + 1 End Function Private Function fIsScrollBar(frm As Form) As Long ' Get ScrollBar's hWnd Dim hWnd_VSB As Long Dim hWnd As Long Dim iCount As Long hWnd = frm.hWnd ' Let's get first Child Window of the FORM hWnd_VSB = apiGetWindow(hWnd, GW_CHILD) ' Let's walk through every sibling window of the Form Do ' Thanks to Terry Kreft for explaining ' why the apiGetParent acll is not required. ' Terry is in a Class by himself! :-) 'If apiGetParent(hWnd_VSB) <> hWnd Then Exit Do Debug.Print fGetClassName(hWnd_VSB) iCount = iCount + 1 If fGetClassName(hWnd_VSB) = "scrollBar" Then If apiGetWindowLong(hWnd_VSB, GWL_STYLE) And SBS_VERT Then fIsScrollBar = hWnd_VSB Exit Function End If End If ' Let's get the NEXT SIBLING Window hWnd_VSB = apiGetWindow(hWnd_VSB, GW_HWNDNEXT) ' Let's Start the process from the Top again ' Really just an error check Loop While hWnd_VSB <> 0 Debug.Print "Count of Child windows = " & iCount ' SORRY - NO Vertical ScrollBar control ' is currently visible for this Form fIsScrollBar = -1 End Function ' From Dev Ashish's Site ' The Access Web ' http://www.mvps.org/access/ '******* Code Start ********* Private Function fGetClassName(hWnd As Long) Dim strBuffer As String Dim lngLen As Long Const MAX_LEN = 255 strBuffer = Space$(MAX_LEN) lngLen = apiGetClassName(hWnd, strBuffer, MAX_LEN) If lngLen > 0 Then fGetClassName = Left$(strBuffer, lngLen) End Function '******* Code End *********