我正在尝试从我的VB应用程序(VS 2008)运行外部应用程序。虽然,我可以点击这个外部可执行文件的主窗口上的按钮,我似乎无法收集"另存为"单击此外部可执行文件主窗口上的特定按钮时出现的窗口。
这是我到目前为止所做的:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'This part is tried and tested up to a point.
Dim p As Process
Dim matches() As Process = Process.GetProcessesByName("test1")
If matches.Length = 0 Then
p = Process.Start("C:\Users\test\Desktop\demo1\test1\test1.exe")
Thread.Sleep(100)
ShowWindow(p.MainWindowHandle, 2)
Else
p = matches(0)
ShowWindow(p.MainWindowHandle, 2)
End If
Dim hWndMsgBox, hWndButton As Long
hWndMsgBox = FindWindow("#32770", "Test1 Application")
Debug.Print(Hex(hWndMsgBox))
Dim ChildHandles() As IntPtr = GetChildWindows(hWndMsgBox)
For i As Integer = 0 To ChildHandles.Length - 1
'Debug.Print(System.Convert.ToString(ChildHandles(i).ToInt32, 16))
Debug.Print(Hex(ChildHandles(i).ToInt32)) 'At this point I am able to return the hex values of all child handles to the primary window.
Next
If hWndMsgBox Then hWndButton = FindWindowEx(hWndMsgBox, 0&, "Button", "Start Job")
If hWndButton Then SendMessage(hWndButton, BM_CLICK, 0&, 0&)
Thread.Sleep(100)
If hWndMsgBox Then hWndButton = FindWindowEx(hWndMsgBox, 0&, "Button", "Save Results")
If hWndButton Then SendMessage(hWndButton, BM_CLICK, 0&, 0&)
hWndMsgBox = FindWindowEx1(hWndMsgBox, 0&, "#32770", "Save As")
Debug.Print(hWndMsgBox) 'This results in 0. And this is where I am stuck. Using Spy++, I found that the actual "Save As" dialog box is sub-classed.
hWndButton = FindWindowEx(hWndMsgBox, 0&, "Button", "Cancel")
If hWndButton Then SendMessage(hWndButton, BM_CLICK, 0&, 0&)
End Sub
我尝试在以下链接的帮助下尽可能地进行调整: http://www.vbforums.com/showthread.php?567473-findwindowEX-Send-Message-in-Child-of-a-Child-of-an-Application
How to bring external application window on top?
How to set focus on other application based on process name VB
https://www.pinvoke.net/default.aspx/user32.EnumWindows
http://www.a1vbcode.com/snippet-5324.asp
http://vbnet.mvps.org/index.html?code/enums/enumwindows.htm
我必须忽视一些显而易见的事情。我当然可以提供任何帮助。