我正在使用以下代码单击一个按钮以显示另一个要单击的表单:

Dim hwnd As Integer = FindWindow(vbNullString, "Virtual CDRom Control Panel")
Dim x As Integer = FindWindowEx(hwnd, 0, vbNullString, "Driver Control ...")

SendMessage(x, BM_CLICK, 0&, 0&)
Thread.Sleep(200)
hwnd = FindWindow(vbNullString, "Virtual CD-ROM Driver Control")
Debug.Print(hwnd)

问题是当它到达

SendMessage(x, BM_CLICK, 0&, 0&)

单击按钮,它会在那里停止代码,直到我退出弹出的框。我希望能够继续而不必退出框,因为下一行

hwnd = FindWindow(vbNullString, "Virtual CD-ROM Driver Control")

找到弹出窗口,然后单击该框中的按钮。

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

大卫

已解决
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
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 Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr

Dim hwnd As IntPtr = FindWindow(vbNullString, "Virtual CDRom Control Panel")
Dim x As IntPtr = FindWindowEx(hwnd, 0, vbNullString, "Driver Control ...")

PostMessage(x, BM_CLICK, 0&, 0&)
Thread.Sleep(200)
hwnd = FindWindow(vbNullString, "Virtual CD-ROM Driver Control")
Debug.Print(hwnd)

最佳答案

尝试将 SendMessage 更改为 PostMessage

另请注意,所有 HWND 必须声明为 IntPtrwParamlParamSendMessagePostMessage 也是 IntPtr
这将使您的代码与 x64 环境兼容。

关于VB.net SendMessage等待问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5168671/

10-12 04:34