vb.net 从 sendmessagestring 获取列表视图项目

发布于 2024-10-19 23:26:32 字数 1139 浏览 1 评论 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)

大卫

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2024-10-26 23:26:32

我的建议是逐步浏览代码并找到您没有获得值的确切位置。 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文