如何在vb.net中激活一个窗口

所以我正在编写一个程序,input一个没有API的开放式应用程序。 所以我需要select那个窗口,这样我的程序就可以input了。 我正在使用这个代码,它不能find进程。

Dim windowHandle As IntPtr = FindWindow("LolClient", "League of Legends (TM) Client") Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As IntPtr SetForegroundWindow(windowHandle) SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait("{TAB}") SendKeys.SendWait(ComboBox1.Text) SendKeys.SendWait("{Enter}") 

尝试这个:

 Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer Public Const SW_RESTORE As Integer = 9 Public Const SW_SHOW As Integer = 5 Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String) Dim hWnd As Integer hWnd = FindWindow(strClassName, strWindowCaption) If hWnd > 0 Then SetForegroundWindow(hWnd) If IsIconic(hWnd) Then 'Restore if minimized ShowWindow(hWnd, SW_RESTORE) Else ShowWindow(hWnd, SW_SHOW) End If End If End Sub 

要显示“计算器”,您可以调用FocusWindow("Calculator", Nothing)FocusWindow(Nothing, "CalcFrame")