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)
但我总是得到的值是0。
http://img153.imageshack.us/img153/8892/vcdprog.jpg
任何帮助都会很棒! :o)
大卫
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的建议是逐步浏览代码并找到您没有获得值的确切位置。 IE - hwnd 设置正确吗?如果没有,请使用 Spy++ 验证窗口类名和窗口名。
我知道 FindWindow 的文档:
http://msdn.microsoft.com/en- us/library/ms633499(v=vs.85).aspx
表示将类名保留为空将返回与适当窗口名的所有匹配项,但我很难看到这种行为(我必须明确地给它类名并然后效果很好)。
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).