|
-
Jul 6th, 2002, 05:24 PM
#1
Thread Starter
New Member
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
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|