[AccessD] Access Lockdown

jwcolby jwcolby at colbyconsulting.com
Mon May 23 10:22:00 CDT 2011


Holy cow!  It would appear that you have done this stuff?

John W. Colby
www.ColbyConsulting.com

On 5/23/2011 10:57 AM, Jim Dettman wrote:
> <<What I want to know is how does he figure out the name of the objects?
> for example...>>
>
>
> One way is to enumerate all the child windows when something is running:
>
> Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
> _
>      ByVal lParam As Long) As Long
> Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As
> _
>      Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
>
> Declare Function GetWindowTextLength Lib "user32.dll" Alias
> "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
> Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA"
> (ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As
> Long
> Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal
> hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
>
> ' The following variables are shared between the main ChildWindows procedure
> ' and the auxiliary (private) ChildWindows_CBK routine
>
> ' An array of Long holding the handle of all child windows.
> Dim windows() As Long
> ' The number of elements in the array.
> Dim windowsCount As Long
>
>
>
>
> Sub getWindows()
>
>     Dim lnghwnd As Long
>
>     lnghwnd = CLng(Application.hWndAccessApp)
>
>     Debug.Print ChildWindows(lnghwnd)
>
> End Sub
>
>
> ' Return an array of Long holding the handles of all the child windows
> ' of a given window. If hWnd = 0 it returns all the top-level windows.
>
> Function ChildWindows(ByVal hWnd As Long)
>      windowsCount = 0
>      If hWnd Then
>          EnumChildWindows hWnd, AddressOf EnumWindows_CBK, 1
>      Else
>          EnumWindows AddressOf EnumWindows_CBK, 1
>      End If
>      ' Trim uninitialized elements and return to caller.
>      ReDim Preserve windows(windowsCount) As Long
>
> End Function
>
> ' The callback routine, common to both EnumWindows and EnumChildWindows.
>
> Private Function EnumWindows_CBK(ByVal hWnd As Long, ByVal lParam As Long)
> As _
>      Long
>
>      Dim slength As Long
>      Dim buffer As String
>      Dim retval As Variant
>      Dim classname As String
>
>      ' Make room in the array, if necessary.
>      If windowsCount = 0 Then
>          ReDim windows(100) As Long
>      ElseIf windowsCount>= UBound(windows) Then
>          ReDim Preserve windows(windowsCount + 100) As Long
>      End If
>      ' Store the new item.
>      windowsCount = windowsCount + 1
>      windows(windowsCount) = hWnd
>    slength = GetWindowTextLength(hWnd) + 1  ' get length of title bar text
>    buffer = Space(slength)  ' make room in the buffer
>    retval = GetWindowText(hWnd, buffer, slength)  ' get title bar text
>    Debug.Print "Window #"; windowsCount  ' display number of enumerated
> window
>    Debug.Print "Handle: "; hWnd
>    Debug.Print ; "Title:"; Left(buffer, slength - 1) ' display title bar text
> of enumerated window
>    classname = Space(255)
>    slength = GetClassName(hWnd, classname, 255)
>    classname = Left(classname, slength)  ' remove empty space
>    Debug.Print ; "Class: "; classname
>    Debug.Print
>
>      ' Return 1 to continue enumeration.
>      EnumWindows_CBK = 1
> End Function
>
>
> <<snip>>
>



More information about the AccessD mailing list