在VB里用App.PrevInstance可知已有程序运行,怎样把已运行的程序调到前台呢?

解决方案 »

  1.   

    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_RESTORE = 9Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Sub Form_Load()
        Dim tmp As String
        Dim h As Long
        If App.PrevInstance Then
            tmp = Me.Caption
            Me.Caption = ""
            h = FindWindow(vbNullString, "你的窗口的标题栏文字")
            If h Then
                ShowWindow h, SW_RESTORE
                SetForegroundWindow h
                End
            End If
        End If
    End Sub
      

  2.   

    谢谢楼上大虾,你这个是通过CAPTION来判断的把