如何在vb.net中激活窗口

 黑小羊Mark 发布于 2023-02-04 18:08

所以我正在开发一个类型为没有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}")

小智.. 7

试试这个:

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

1 个回答
  • 试试这个:

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

    2023-02-04 18:10 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有