vb.net getting listview items from sendmessagestring

1.8k views Asked by At

I am using the following code to try to grad whats in the listview on another window:

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
Private Function SendMessageString(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByRef lParam As String) As IntPtr
End Function
Public Const LB_GETCOUNT = &H18B
Public Const LB_GETTEXT = &H189
Public Const LB_GETTEXTLEN = &H18A

hwnd = FindWindow(vbNullString, "Virtual CDRom Control Panel")
x = FindWindowEx(hwnd, 0, vbNullString, "List1")

Dim listCount As String = SendMessage(x, LB_GETCOUNT, CLng(0), CLng(0))
Dim textLen As String = SendMessage(x, LB_GETTEXTLEN, 30, CLng(0))
Dim itemText As String = New String(" ", textLen)
Dim theText As String = SendMessageString(x, LB_GETTEXT, 30, itemText)

MessageBox.Show(theText)

But the value i always get is 0.

http://img153.imageshack.us/img153/8892/vcdprog.jpg

Any help would be great! :o)

David

1

There are 1 answers

0
Rob P. On

My suggestion would be to step through the code and find where exactly you aren't getting a value. IE - does hwnd get set correctly? If not, use Spy++ to verify the window Classname and the Windowname.

I know the documentation for FindWindow: http://msdn.microsoft.com/en-us/library/ms633499(v=vs.85).aspx

says that leaving the classname null will return all matches with the appropriate windowname, but I struggled to see that behavior (I had to explicitly give it the classname and then it worked great).