[RESOLVED] Form is a child of another form
How do you determine/test if a nonMDI form is the child of another nonMDI form?
I tried the following APIs but there is no difference in the return value, WS_ , WS_EX_ after the form was made a child (using SetParent).
GetWindowLong
IsChild
GetParent
Edit: GetWindow (.hwnd, GW_OWNER) doesn't work either
Re: Form is a child of another form
In Form1 someplace
In Form2
Code:
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_OWNER = 4
Private Sub Command1_Click()
Dim lngOwnerHwnd As Long
Dim frm As Form
lngOwnerHwnd = GetWindow(Me.hwnd, GW_OWNER)
For Each frm In Forms
If frm.hwnd = lngOwnerHwnd Then
MsgBox "My owner is " & frm.Name
Exit For
End If
Next
End Sub
Re: Form is a child of another form
Quote:
Originally Posted by
MartinLiss
In Form1 someplace
In Form2
Code:
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_OWNER = 4
Private Sub Command1_Click()
Dim lngOwnerHwnd As Long
Dim frm As Form
lngOwnerHwnd = GetWindow(Me.hwnd, GW_OWNER)
For Each frm In Forms
If frm.hwnd = lngOwnerHwnd Then
MsgBox "My owner is " & frm.Name
Exit For
End If
Next
End Sub
Sorry I forgot to mention that I had already tried GetWindow GW_OWNER and it doesn't work either.
Whether or not form2 is made a child of form1 using SetParent(and you can tell when form2 is a child because it moves with form1 when form1 moves),
In both cases (form2 a child or not a child) GetWindow (form2.hwnd,GW_OWNER ) reports ThunderMain as the owner.
Re: Form is a child of another form
GOOD NEWS! I found it! use GetAncestor with GA_PARENT