Setting external application focus

后端 未结 2 1311
南笙
南笙 2021-01-24 17:12

In VB.NET, you can set focus to an external application using

AppActivate(\"Windows Name\")

or

2条回答
  •  旧时难觅i
    2021-01-24 17:44

    Try these Win32 functions:

    Declare Sub SwitchToThisWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal fAltTab As Boolean)
    Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As IntPtr) As IntPtr
    Private Enum ShowWindowEnum
        Hide = 0
        ShowNormal = 1
        ShowMinimized = 2
        ShowMaximized = 3
        Maximize = 3
        ShowNormalNoActivate = 4
        Show = 5
        Minimize = 6
        ShowMinNoActivate = 7
        ShowNoActivate = 8
        Restore = 9
        ShowDefault = 10
        ForceMinimized = 11
    End Enum
    

    Use Process.MainWindowHandle to get the handle. This works on most, but not all, applications.

提交回复
热议问题