GetScrollBarInfo API don't work
Hi all,
Somebody has a running example of GetScrollBarInfo API ? With my code, I get no results and a dll error 87.
I'm trying to know if the scrollbars (in my case, the horizontal scrollbar) are showed in the main access window. I use GetScrollBarInfo. There are 2 days I'm, searching info about the function and the parameters, but they are hard to find. :afrog:
I can only find general descriptions of the API. :sick:
I found some constant values in the ApiViewer 2004. :duck:
Here is my API-calling code (in a form class-module):
'vede se la scroll bar orizzontale รจ visibile
Dim void As Integer
Dim SBInfo As WM_PSCROLLBARINFO
SBInfo.cbSize = Len(SBInfo)
void = WM_GetScrollBarInfo(Application.hWndAccessApp, OBJID_HSCROLL, SBInfo)
Debug.Print SBInfo.rgState(0)
After the API call:
- no error message is given. err.number is 0
- void is 0 (function not succeeded?)
- the err.LastDllError contains 87 (invalid parm?)
- all components of SBInfo are = to 0
Here are the declarations I'm using:
Type WM_Rect
Left As Long
Top As Long
Width As Long
Height As Long
End Type
'Declare Function WM_GetScrollBarInfo
'for function WM_GetScrollBarInfo, param IDObject can be:
Global Const OBJID_CLIENT As Long = &HFFFFFFFC 'the hwnd parm is a handle to a scroll bar control
Global Const OBJID_HSCROLL As Long = &HFFFFFFFA 'the horizontal scroll bar of the hwnd window
Global Const OBJID_VSCROLL As Long = &HFFFFFFFB 'the vertical scroll bar of the hwnd window
'for function WM_GetScrollBarInfo - type WM_PSCROLLBARINFO - rgState param
Global Const CCHILDREN_SCROLLBAR As Long = 5
'necessary to give a dimention to the rgState array in WM_PSCROLLBARINFO
'the 5 index of the array indicate:
'0 = The scrollbar itself
'1 = The top or right arrow button
'2 = The page up or page right region
'3 = The scroll box (thumb)
'4 = The page down or page left region
'5 = The bottom of left arrow button
'every indication can contains (can be combined?):
Private Const STATE_SYSTEM_INVISIBLE As Long = &H8000
Private Const STATE_SYSTEM_OFFSCREEN As Long = &H10000
Private Const STATE_SYSTEM_PRESSED As Long = &H8
Private Const STATE_SYSTEM_UNAVAILABLE As Long = &H1
'for function WM_GetScrollBarInfo, WM_PSCROLLBARINFO structure is:
Type WM_PSCROLLBARINFO
cbSize As Long
rcScrollBar As WM_Rect
dxyLineButton As Integer
xyTumbTop As Integer
xyTumbBottom As Integer
reserved As Integer
rgState(CCHILDREN_SCROLLBAR + 1) As Long
End Type
Declare Function WM_GetScrollBarInfo Lib "user32.dll" Alias "GetScrollBarInfo" (ByVal hwnd As Long, ByVal idObject As Long, ByRef psbi As WM_PSCROLLBARINFO) As Long
Some hint?
Re: GetScrollBarInfo API don't work
There are numerous comments on the net regarding that API and windows XP. Look at the bottom of this page. Is this being used in VB6? If so, your WM_PSCROLLBARINFO structure should be using Long not Integer.
Here is a simple test to see if a scrollbar exists in a window. This applies only if the scrollbar is part of a window. If the scrollbar is a separate control within the window, the code will not work:
Code:
Private Const GWL_STYLE = (-16)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" & _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Sub Command1_Click()
Dim wndStyle As Long
' Retrieve the window style of the control.
wndStyle = GetWindowLong(Application.hWndAccessApp, 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
MsgBox "A horizontal scroll bar is visible."
Else
MsgBox "A horizontal scroll bar is NOT 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
MsgBox "A vertical scroll bar is visible."
Else
MsgBox "A vertical scroll bar is NOT visible."
End If
End Sub
Assumption is that Application.hWndAccessApp is a valid window handle. It does not tell you if the scrollbar is hidden or not
Re: GetScrollBarInfo API don't work
I tryed your code, but wndStyle don't change when a scrollbar is visible or not.
This code works for you? I have XP Home 2002 SP3 and Access 2003 v.11.5614.5606. Could be a version specific bug?
If not:
Checking with winID (same as Spy++, but give you info about controls, too) I see that the handle of the scrollbar is the same as the Access Window Client Area (his type is an MDI Client Window), that differs from the handle of the Access Window. So, in both methods (getScrollBarInfo or getWindowLong-GWL_STYLE), could be I have to pass the handle of the Client Area itself?
Now the obvious question: how to have it? Any hint?
Re: GetScrollBarInfo API don't work
If the scrollbar's window is actually a MDI Client Window, you can get that hWnd easily enough and use it instead. Assuming Application.hWndAccessApp is the MDI client's parent.
Code:
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
' example of finding MDI client attached to parent:
hWndMDI = FindWindowEx(Application.hWndAccessApp, 0&, "MDIClient", vbNullString)
Re: GetScrollBarInfo API don't work
It works! Thanks to LaVolpe.
Adressing the MDIClientWindow of the main AccessClientArea (found through FindWindowEx) I got the right object.
Using the GetWindowLong method exposed by LaVolpe I see if the bars are visible or not.
Using the GetScrollBarInfo with the right object don't works.
Thanks all
Re: GetScrollBarInfo API don't work
Glad to help.
If this is resolved, please indicate so by using the "Thread Tools" menu near top of your 1st post above.