第一个工程 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function AllowSetForegroundWindow Lib "user32.dll" (ByVal dwProcessId As Long) As Long Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click() Dim mWnd As Long, hProcessID As Long mWnd = FindWindow(vbNullString, "这是测试窗口2") If mWnd = 0 Then MsgBox "没有发现文件" Exit Sub End If lHandle = SetForegroundWindow(mWnd) End Sub
第二个工程 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 Long Private Sub Command1_Click() Dim mWnd As Long, hProcessID As Long mWnd = FindWindow(vbNullString, "这是测试窗口1") If mWnd = 0 Then MsgBox "没有发现这个文件" Exit Sub End If lHandle = SetForegroundWindow(mWnd) End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function AllowSetForegroundWindow Lib "user32.dll" (ByVal dwProcessId As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Dim mWnd As Long, hProcessID As Long
mWnd = FindWindow(vbNullString, "这是测试窗口2")
If mWnd = 0 Then
MsgBox "没有发现文件"
Exit Sub
End If
lHandle = SetForegroundWindow(mWnd)
End Sub
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 Long
Private Sub Command1_Click()
Dim mWnd As Long, hProcessID As Long
mWnd = FindWindow(vbNullString, "这是测试窗口1")
If mWnd = 0 Then
MsgBox "没有发现这个文件"
Exit Sub
End If
lHandle = SetForegroundWindow(mWnd)
End Sub