2011-03-02 49 views
0

我使用下面的代碼獲取列表視圖項嘗試到畢業什麼在ListView上的另一個窗口:vb.net從sendmessagestring

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) 

但i的值總是爲。

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

任何幫助將是巨大的! :O)

大衛

回答

0

我的建議是逐步執行代碼,並準確地找到,你沒有得到的值。 IE瀏覽器 - hwnd設置是否正確?如果沒有,使用Spy ++來驗證窗口Classname和Windowname。

我知道FindWindow函數的文檔: http://msdn.microsoft.com/en-us/library/ms633499(v=vs.85).aspx

說,離開類名空將返回所有比賽用適當的windowname,但我掙扎着看到這種行爲(我必須明確地給它的類名,然後它工作得很好)。