这么做: 窗体1: Option ExplicitPrivate Sub Command1_Click() Form3.Show , Me End Sub窗体2: Option ExplicitPrivate Sub Command1_Click() Form3.Show , Me End Sub窗体3: Option Explicit Private Const GW_OWNER = 4 Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Sub Command1_Click() Dim mhwnd As Long mhwnd = GetWindow(Me.hwnd, GW_OWNER) Dim a As Form For Each a In Forms If a.hwnd = mhwnd Then MsgBox "form3的owner window是:" + a.Name Exit For End If Next End Sub
窗体1:
Option ExplicitPrivate Sub Command1_Click()
Form3.Show , Me
End Sub窗体2:
Option ExplicitPrivate Sub Command1_Click()
Form3.Show , Me
End Sub窗体3:
Option Explicit
Private Const GW_OWNER = 4
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Sub Command1_Click()
Dim mhwnd As Long
mhwnd = GetWindow(Me.hwnd, GW_OWNER)
Dim a As Form
For Each a In Forms
If a.hwnd = mhwnd Then
MsgBox "form3的owner window是:" + a.Name
Exit For
End If
Next
End Sub