簡體   English   中英

如何在vb.net中激活窗口

[英]How to make a window active in vb.net

因此,我正在研究一種程序,該程序可以鍵入沒有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}")

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM