如何在 vb.net 中激活窗口 [英] How to make a window active in vb.net

查看:103
本文介绍了如何在 vb.net 中激活窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个程序,该程序可以输入一个没有 API 的开放应用程序.所以我需要选择那个窗口,这样我的程序就会输入进去.我正在使用此代码,但找不到过程.

So I'm working on a program that types into an open application that has no api. So I need to select that window so my program will type into it. I'm using this code and it can't find the proccess.

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

To show the "Calculator" you can call FocusWindow("Calculator", Nothing) or FocusWindow(Nothing, "CalcFrame")

这篇关于如何在 vb.net 中激活窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆