dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] What declaration for AccessibleObjectFromEvent?

Threaded View

  1. #1
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    [RESOLVED] What declaration for AccessibleObjectFromEvent?

    Does anyone know of a working declaration for the API "AccessibleObjectFromEvent"? Or a good .net equivelant?

    I've spent so much time getting the other main Accessible API to work on .NET, that I'm hoping to start with a good declare on this one.
    I've built a really good narrator, for totally blind people so that they can interface and use the computer in a substantial way. The innovation is a static mouse that controls category input, rather than free mouse movement, and the middle wheel selectes items of that category.
    But I need the last access API for events and voice feedback when the event occurs.


    I'm guessing it's something like this, according to what works for the other API:
    Code:
    Private Declare Function apiAccessibleObjectFromEvent Lib "oleacc" Alias "AccessibleObjectFromEvent" (ByVal hwnd As Int32, ByVal dwObjectID As Int32, ByVal dwChildID As Int32, ByRef ppacc As Global.Accessibility.IAccessible, ByRef pvarChild As Object) As Int32
    In case anyone is interested in the other API's, I've included a project zip file, with:
    AccessibleObjectFromWindow, AccessibleChildren, & AccessibleObjectFromPoint.
    This is loosely based upon microsoft AAccess example written in vb6, available as an online download. I've have not seen a .NET example online, so it might proove useful for someone.

    Code:
    Option Strict On
    Option Explicit On
    Module Accessibility
        Const CHILDID_SELF As Int32 = 0
        Const CHILDID_1 As Int32 = 1
        Const OBJID_CLIENT As Int32 = &HFFFFFFFC
        Const OBJID_CARET As Int32 = &HFFFFFFF8
        Const OBJID_CURSOR As Int32 = &HFFFFFFF7
        Const OBJID_MENU As Int32 = &HFFFFFFFD
        Const OBJID_NATIVEOM As Int32 = &HFFFFFFF0
        Const OBJID_SYSMENU As Int32 = &HFFFFFFFF
        Const OBJID_TITLEBAR As Int32 = &HFFFFFFFE
        Const OBJID_WINDOW As Int32 = 0
        Const OBJID_VSCROLL As Int32 = &HFFFFFFFB
        Const OBJID_HSCROLL As Int32 = &HFFFFFFFA
        Const OBJID_SIZEGRIP As Int32 = &HFFFFFFF9
        Const OBJID_ALERT As Int32 = &HFFFFFFF6
        Const OBJID_SOUND As Int32 = &HFFFFFFF5
        Public Structure POINTAPI
            Public x, y As Int32
        End Structure
        Public Structure RECT
            Public rLeft, rTop, rRight, rBottom As Int32
        End Structure
        Public Structure ACCOBJINFO
            Public Text, Value, DefaultAction, KeyShortcut, Description, Help As String
            Public State, Selection As Double
            Public Parent As Global.Accessibility.IAccessible
            Public Position As POINTAPI
            Public Size As Size
            Public ItemPosition As POINTAPI
            Public ItemSize As Size
        End Structure
        ' Private Declare Function apiAccessibleObjectFromEvent Lib "oleacc" Alias "AccessibleObjectFromEvent" (ByVal hwnd As Int32, ByVal dwObjectID As Int32, ByVal dwChildID As Int32, ByRef ppacc As Global.Accessibility.IAccessible, ByRef pvarChild As Object) As Int32
        Private Declare Function apiAccessibleObjectFromWindow Lib "oleacc" Alias "AccessibleObjectFromWindow" (ByVal Hwnd As Int32, ByVal dwId As Int32, ByRef riid As Guid, ByRef ppacc As Global.Accessibility.IAccessible) As Int32
        Private Declare Function apiAccessibleChildren Lib "oleacc" Alias "AccessibleChildren" (ByVal paccContainer As Global.Accessibility.IAccessible, ByVal iChildStart As Int32, ByVal cChildren As Int32, <System.Runtime.InteropServices.[Out]()> ByVal rgvarChildren() As Object, ByRef pcObtained As Int32) As UInteger
        Private Declare Function apiAccessibleObjectFromPoint Lib "oleacc" Alias "AccessibleObjectFromPoint" (ByVal pt As POINTAPI, ByRef ppacc As Global.Accessibility.IAccessible, ByRef pvarChild As Object) As Int32
        Private Declare Function apiGetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Boolean
        Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
        Private Declare Function apiGetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Int32) As Int32
        Public Declare Function apiFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
        Private IID_IAcce As Guid = New Guid("618736E0-3C3D-11CF-810C-00AA00389B71")
        Private IID_IDispatch As Guid = New Guid("00020424-0000-0000-C000-000000000046")
    
        Public Function GetObjectFromPoint(ByVal pt As POINTAPI) As ACCOBJINFO
            On Error Resume Next : GetObjectFromPoint = Nothing ' Not all the acc properties will work  with all the returned objects.
            Dim accObj As Global.Accessibility.IAccessible = Nothing
            Dim objChild As Object = Nothing
            Dim objInf As New ACCOBJINFO
            If pt.x = 0 AndAlso pt.y = 0 Then apiGetCursorPos(pt) ' Get the cursor position where the mouse was clicked.
            apiAccessibleObjectFromPoint(pt, accObj, objChild) ' Get the IAccessible interface of the object located under the cursor position.
            GetObjectFromPoint.Text = accObj.accName(objChild)
            GetObjectFromPoint.Value = accObj.accValue(objChild)
            GetObjectFromPoint.DefaultAction = accObj.accDefaultAction(objChild)
            GetObjectFromPoint.KeyShortcut = accObj.accKeyboardShortcut(objChild)
            GetObjectFromPoint.Description = accObj.accDescription(objChild)
            GetObjectFromPoint.Help = accObj.accHelp(objChild)
            GetObjectFromPoint.State = CDbl(accObj.accState(objChild))
            GetObjectFromPoint.Selection = CDbl(accObj.accSelection())
            GetObjectFromPoint.Parent = CType(accObj.accParent(), IAccessible)
            accObj.accLocation(GetObjectFromPoint.Position.x, GetObjectFromPoint.Position.y, 0, 0, 0)
            accObj.accLocation(0, 0, GetObjectFromPoint.Size.Width, GetObjectFromPoint.Size.Height, 0)
            accObj.accLocation(GetObjectFromPoint.ItemPosition.x, GetObjectFromPoint.ItemPosition.y, 0, 0, objChild)
            accObj.accLocation(0, 0, GetObjectFromPoint.ItemSize.Width, GetObjectFromPoint.ItemSize.Height, objChild)
            accObj = Nothing : objChild = Nothing
        End Function
    
        Public Function GetFormControls(ByVal hwnd As Int32) As ACCOBJINFO() 'This is loosely based upon microsoft AAccess example written in vb6, available as an online download.  No .NET version known though, except this one
            On Error Resume Next
            Dim numCtrls, numCtrlsRet As Int32
            Dim accObj As Global.Accessibility.IAccessible = Nothing
            Dim newAccObj As Global.Accessibility.IAccessible = Nothing
            Dim objChildren() As Global.Accessibility.IAccessible = Nothing
            Dim objControls() As Global.Accessibility.IAccessible = Nothing
            Dim objArray As ACCOBJINFO()
            Dim wText As String = GetWindowText(hwnd)
            If wText = "" Then Return Nothing
            apiAccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAcce, accObj) ' Get forms IAccessible interface
            numCtrls = accObj.accChildCount 'set count to children count
            ReDim objChildren(numCtrls - 1) 'Array length is the number of children parented by object
            apiAccessibleChildren(accObj, 0, numCtrls, objChildren, numCtrlsRet) ' Get all children
            For i As Int32 = 0 To numCtrlsRet - 1 ' Get main client object , since the previous call got all system info etc
                If objChildren(i).accName = wText Then
                    newAccObj = objChildren(i)
                    numCtrls = newAccObj.accChildCount
                End If 'Could get titlebar stuff here
                ' Dim left, top, width, height As Int32
                ' objChildren(i).accLocation(left, top, width, height)
                ' MessageBox.Show( left.ToString & " " & top.ToString & " " & width.ToString & " " & height.ToString)
                ' DrawRectangle(left, top, width, height)
            Next
            ReDim objControls(numCtrls - 1) 'Re dimension, so that we can actually get children controls of the forms IAccessible interface
            apiAccessibleChildren(newAccObj, 0, numCtrls, objControls, numCtrlsRet) 'Get controls
            ReDim objArray(numCtrlsRet - 1)
            For i As Int32 = 0 To numCtrlsRet - 1 'Gather properties of the returned IAccessible objects
                objArray(i).Text = objControls(i).accName
                objArray(i).Value = objControls(i).accValue
                objArray(i).DefaultAction = objControls(i).accDefaultAction
                objArray(i).KeyShortcut = objControls(i).accKeyboardShortcut
                objArray(i).Description = objControls(i).accDescription
                objArray(i).Help = objControls(i).accHelp
                objArray(i).State = CDbl(objControls(i).accState)
                objArray(i).Selection = CDbl(objControls(i).accSelection)
                objArray(i).Parent = CType(objControls(i).accParent, IAccessible)
                objControls(i).accLocation(objArray(i).Position.x, objArray(i).Position.y, 0, 0, 0)
                objControls(i).accLocation(0, 0, objArray(i).Size.Width, objArray(i).Size.Height, 0)
            Next
            accObj = Nothing : newAccObj = Nothing : objChildren = Nothing : objControls = Nothing
            Return objArray 'Return with an array of controls, containing property information of each control
        End Function
    
        Private Function GetWindowText(ByVal hwnd As Int32) As String
            On Error Resume Next
            Dim tLength, rValue As Int32 : GetWindowText = "" 'Initialize string for text name
            tLength = apiGetWindowTextLength(hwnd) + 4 'Get length
            GetWindowText = GetWindowText.PadLeft(tLength) '''''Pad with buffer
            rValue = apiGetWindowText(hwnd, GetWindowText, tLength) 'Get text
            GetWindowText = GetWindowText.Substring(0, rValue) 'Strip buffer
        End Function
    
    End Module
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)