Results 1 to 4 of 4

Thread: [RESOLVED] Form is a child of another form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Resolved [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
    Last edited by vb_lover; May 14th, 2011 at 09:46 AM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Form is a child of another form

    In Form1 someplace

    Code:
    Form2.Show , Form1
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Arrow Re: Form is a child of another form

    Quote Originally Posted by MartinLiss View Post
    In Form1 someplace

    Code:
    Form2.Show , Form1
    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.
    Last edited by vb_lover; May 14th, 2011 at 09:48 AM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Re: Form is a child of another form

    GOOD NEWS! I found it! use GetAncestor with GA_PARENT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width