PDA

Click to See Complete Forum and Search --> : Active Accessibility


Bryan2923
Aug 11th, 2001, 08:45 PM
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

Kaverin
Aug 12th, 2001, 03:22 AM
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.

'in a module
Option Explicit

'the last param was changed from "lParam As Any" to "ByVal lParam As Long", and StrPtr() will be used to give a pointer
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
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const LB_ADDSTRING As Long = &H180
Public Const LB_RESETCONTENT As Long = &H184
Public Const LB_SETSEL As Long = &H185
Public Const LB_GETTEXT As Long = &H189
Public Const LB_GETTEXTLEN As Long = &H18A
Public Const LB_GETCOUNT As Long = &H18B
Public Const GWL_STYLE As Long = -16

Public Sub CopyListBox(ByVal hWndSrcLB As Long, ByVal hWndDestLB As Long)
Dim lngItems As Long, lngLength As Long
Dim lngStyle As Long, i As Long
Dim strBuffer As String
'get total items in source listbox
lngItems = SendMessage(hWndSrcLB, LB_GETCOUNT, 0, 0)
'terminate sub if there's nothing to copy
If lngItems = 0 Then Exit Sub
'get the style of the source listbox
lngStyle = GetWindowLong(hWndSrcLB, GWL_STYLE)
'apply that style to the destination listbox
SetWindowLong hWndDestLB, GWL_STYLE, lngStyle
'clear the destination listbox
SendMessage hWndDestLB, LB_RESETCONTENT, 0, 0
'go through each item
For i = 0 To (lngItems - 1)
'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)
'get length of text of item i + 1 for null terminator
lngLength = SendMessage(hWndSrcLB, LB_GETTEXTLEN, i, 0) + 1
'create buffer
strBuffer = Space$(lngLength)
'get text of item i
lngLength = SendMessage(hWndSrcLB, LB_GETTEXT, i, StrPtr(strBuffer))
'remove null terminator
strBuffer = Left$(strBuffer, lngLength)
'place text from source into destination
SendMessage hWndDestLB, LB_ADDSTRING, 0, StrPtr(strBuffer)
Next i
End Sub

Bryan2923
Aug 12th, 2001, 02:03 PM
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

Kaverin
Aug 12th, 2001, 03:02 PM
Well you said listboxes and listviews, I didn't know you meant the same thing. I couldn't tell that from what you said.

Bryan2923
Aug 12th, 2001, 03:58 PM
Oh sorry for the confusion