激活一个正在运行的程序

来源:互联网 发布:qq空间游戏没有数据 编辑:程序博客网 时间:2024/04/29 09:08

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Integer

'这里SciCalc是计算器的窗口类名
        Dim hCalcWnd As Integer = FindWindow("SciCalc", "计算器")

        If hCalcWnd = 0 Then
            Shell("calc.exe", AppWinStyle.NormalFocus)
        Else
            BringWindowToTop(hCalcWnd)
        End If