如何在vb.net中激活窗口

时间:2014-01-09 23:59:48

标签: vb.net windows

所以我正在开发一个类型为没有api的开放应用程序的程序。所以我需要选择那个窗口,这样我的程序就会输入它。我正在使用此代码,但无法找到进程。

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}")

1 个答案:

答案 0 :(得分:6)

试试这个:

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")

相关问题