Results 1 to 5 of 5

Thread: Active Accessibility

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    5

    Active Accessibility

    Hi does anybody have any expierence working with active accessibility in vb? What I want to do is use it to get the text from a list view/listbox from another application. I know this is possible except I'm having a hard time getting it to work. I've read through almost all the documentation here http://www.microsoft.com/enable/msaa/default.htm but I'm still confused on the exact way to get it. Can anybody help? Thanks

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    This is a thing I made a long time ago that copies the entries of one listbox into another listbox given only the handles to each one. It will show you how to grab items out of a listbox. I've never used a listview myself, but I'd be willing to bet the procedure is similar. I'm sure someone else will know though.
    VB Code:
    1. 'in a module
    2. Option Explicit
    3.  
    4. 'the last param was changed from "lParam As Any" to "ByVal lParam As Long", and StrPtr() will be used to give a pointer
    5. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    6. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    7. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    8.  
    9. Public Const LB_ADDSTRING As Long = &H180
    10. Public Const LB_RESETCONTENT As Long = &H184
    11. Public Const LB_SETSEL As Long = &H185
    12. Public Const LB_GETTEXT As Long = &H189
    13. Public Const LB_GETTEXTLEN As Long = &H18A
    14. Public Const LB_GETCOUNT As Long = &H18B
    15. Public Const GWL_STYLE As Long = -16
    16.  
    17. Public Sub CopyListBox(ByVal hWndSrcLB As Long, ByVal hWndDestLB As Long)
    18.    Dim lngItems As Long, lngLength As Long
    19.    Dim lngStyle As Long, i As Long
    20.    Dim strBuffer As String
    21.    'get total items in source listbox
    22.    lngItems = SendMessage(hWndSrcLB, LB_GETCOUNT, 0, 0)
    23.    'terminate sub if there's nothing to copy
    24.    If lngItems = 0 Then Exit Sub
    25.    'get the style of the source listbox
    26.    lngStyle = GetWindowLong(hWndSrcLB, GWL_STYLE)
    27.    'apply that style to the destination listbox
    28.    SetWindowLong hWndDestLB, GWL_STYLE, lngStyle
    29.    'clear the destination listbox
    30.    SendMessage hWndDestLB, LB_RESETCONTENT, 0, 0
    31.    'go through each item
    32.    For i = 0 To (lngItems - 1)
    33.       'note that although i is a long, a listbox will contain at max 32767 items (although memory constraints will reduce that based on the size of the items)
    34.       'get length of text of item i + 1 for null terminator
    35.       lngLength = SendMessage(hWndSrcLB, LB_GETTEXTLEN, i, 0) + 1
    36.       'create buffer
    37.       strBuffer = Space$(lngLength)
    38.       'get text of item i
    39.       lngLength = SendMessage(hWndSrcLB, LB_GETTEXT, i, StrPtr(strBuffer))
    40.       'remove null terminator
    41.       strBuffer = Left$(strBuffer, lngLength)
    42.       'place text from source into destination
    43.       SendMessage hWndDestLB, LB_ADDSTRING, 0, StrPtr(strBuffer)
    44.    Next i
    45. End Sub
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    5
    Thanks for the reply but I forgot to mention that its not a regular listbox its the kind with headers on it and therefore you cannot do it that way.... I wish it were that easy, but does anybody have any examples of active acessibility in vb? Doesnt even have to be about getting the text from a listbox(I already got VBInsp)..Thanks alot

    Bryan

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Well you said listboxes and listviews, I didn't know you meant the same thing. I couldn't tell that from what you said.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    5
    Oh sorry for the confusion

Posting Permissions

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



Click Here to Expand Forum to Full Width