Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As LongPrivate Sub Command1_Click()
    Dim hWnd As Long
    hWnd = FindWindow(vbNullString, "程序主窗口的caption")
        
    If Not hWnd = 0 Then
        
        SetForegroundWindow hWnd
        
    End If
End Sub

解决方案 »

  1.   

    在VB中可以用APP.preinstance来判断是否已经有其它实例运行。
    例:Private sub Form_Load()
         If App.PreInstance Then
              将先前实例置于前台
              Exit Sub
         end If
    End Sub
      

  2.   

    加一个module,用sub main启动
    Sub Main()
    If App.PrevInstance Then
        AppActivate App.Title
        exit sub
    End If
    '正常启动代码,如form1.show
    End Sub
      

  3.   

    Public Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _
                                        (ByVal hwnd&, ByVal lpString$, ByVal cch&)
    Public Declare Function GetWindowRect& Lib "user32" (ByVal hwnd&, lpRect As RECT)
    Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hwnd&)
    Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
                                             (ByVal lpClassName$, ByVal lpWindowName$)
    我以前回复过这么一个贴子,但是我找不到了
    今天机器怀掉了,没法给你源码
    使它在前台显示就是这几个函数
    你自己研究一下