0

我正在使用以下代码尝试在另一个窗口的列表视图中对内容进行分级:

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)

但我总是得到的价值是0

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

任何帮助都会很棒!:o)

大卫

4

1 回答 1

0

我的建议是单步执行代码并找到您没有获得价值的确切位置。IE - hwnd 是否设置正确?如果不是,请使用 Spy++ 验证窗口类名和窗口名。

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

表示将类名保留为 null 将返回具有适当窗口名的所有匹配项,但我很难看到这种行为(我必须明确地给它类名,然后效果很好)。

于 2011-03-02T17:03:54.013 回答