Get text from ListView in another app
I think that it works different with a ListView than it does a ListBox for some reason. When Program A tries to get the text from a ListView in Program B, Program B crashes. Someone explained to me that Program A is trying to write to the memory of Program be or vice versa (something like that anyway), which apparently is a big no no.
The code I'm using is as follows:
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Type LVITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As String
cchTextMax As Long
iImage As Long
lParam As Long
End Type
Private Const BM_CLICK = &HF5&
Private Const WM_SETTEXT = &HC
Private Const LVM_FIRST = &H1000
Private Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)
Private Const LVM_GETITEM = (LVM_FIRST + 5)
Private Const LVM_GETSTRINGWIDTH = (LVM_FIRST + 17)
Private Const LVM_GETCOLUMN = (LVM_FIRST + 25)
Private Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
Dim Lv As LVITEM
Dim MyText As String
Dim MySize As Long
Private Sub Command1_Click()
test123 = FindWindowEx(0, 0, vbNullString, "Test123")
frame1 = FindWindowEx(test123, 0, "ThunderFrame", vbNullString)
frame2 = FindWindowEx(frame1, 0, "ThunderFrame", vbNullString)
button = FindWindowEx(frame2, 0, "ThunderCommandButton", vbNullString)
LView = FindWindowEx(frame2, 0, "ListView20WndClass", vbNullString)
NumBuddies = SendMessage(LView, LVM_GETITEMCOUNT, 0, 0)
'Lv.mask = LVIF_TEXT
'Lv.iItem = 1
Lv.cchTextMax = Len(MyText)
Lv.pszText = MyText
MySize = SendMessage(LView, LVM_GETITEMTEXT, ByVal 1, ByVal Lv)
Text1.Text = test123
Text2.Text = frame1
Text3.Text = frame2
Text4.Text = button
Text5.Text = LView
Text6.Text = NumBuddies
Text7.Text = MySize
Text8.Text = MyText
End Sub
I don't quite understand the LVITEM thing, so maybe that's where I'm going wrong.
I've again uploaded the example programs to show what I am trying to achieve. You'll see that when Program A tries to get the text from a ListView in Program B, Program B crashes :confused:
I've read here that it is not possible to do it this way, but instead you have to use some other way whuch I is competly beyond me. Surely it should be possible and not too much omplicated as getting text from a ListBox¿
It may not be as complicated as it seems and might be me just missing something simple, but I'm new to all this so I'm not sure where I'm going wrong :(
Any help would be much appreciated.
Thanks :)
Re: Get text from ListView in another app
I tried this function but it did not have any result. It only returned null strings .
Do you possibly know what went wrong ?
I got the window handle and the process id of an external program but it did
not return the contents of the listview item.
Re: Get text from ListView in another app
If it is an owner drawn ListView you will not be able to retrive its contents.
Re: Get text from ListView in another app
Quote:
Originally Posted by hax0r
If it is an owner drawn ListView you will not be able to retrive its contents.
yes it is an owner drawn listview. why can't i read its contents ?
is there another way to do this ?
Re: Get text from ListView in another app
Quote:
Originally Posted by alexandros
yes it is an owner drawn listview. why can't i read its contents ?
is there another way to do this ?
If it's owner drawn it's subclassed. It won't process the message you send I think.
Re: Get text from ListView in another app
Quote:
Originally Posted by manavo11
If it's owner drawn it's subclassed. It won't process the message you send I think.
Negative. If something is subclassed, you can still get contents by subclassing it yourself.
Re: Get text from ListView in another app
This is not necesarily true. Since the ListView is owner drawn, it is reposinble for painting its own contents. This totally *can* bypasses the 'ItemText' collection of the ListView. If the ListView is rendering a graphical representation of the text on screen and not exposing any events which can be used to retrieve the internal data, you are stuck. Once 'My List Item' is rendered graphically on screen, there is no real easy way to convert that graphical representation back to its constiuent text.
While its true you can subclass something via an external hook and trap its messages that doesn't really get you much when all you end up getting is WM_PAINTs.
Re: Get text from ListView in another app
I worked on something like this a ways back, and OpenProcess() failed everytime.
I tried the above function, and it fails at the OpenProcess() aswell
all the parameters are right, any ideas why it would be failing everytime?
Re: Get text from ListView in another app
You probably do not have access to open the process. Are you a local administrator?
Re: Get text from ListView in another app
I am yes.
And the Process show's as my User in task manager.
Re: Get text from ListView in another app
Peace All
Haxor's script workrd for me but I had to go everytime to the the task manager and find the process Id of the main Process. or by using spy++. Some one else in the same Forum offerd this script to
Quote:
Dim processID As Long
Dim proc As Long
'/// get the processID of the listview ...
GetWindowThreadProcessId(" handle to Listview here !!! " , processID)
'/// now you have the processID ...
proc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_QUERY_INFORMATION , False, processID)
But This Script doesnt return the right Process ID fro some unkown reasons, can anyone give a hint
Re: Get text from ListView in another app
how can i grab listview in yahoo room !
in to my own list in vb form!?
Re: Get text from ListView in another app
Anyone got a working example of this code in .NET 2005 as i cant seem to get mine to convert correctly?