如:在form1有form3.show语句,在form2中也有form3.show,在程序运行时如何在form3中判断是在哪个窗口被show出来的?
三个窗口都是单文档界面的

解决方案 »

  1.   

    这么做:
    窗体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