Link to home
Start Free TrialLog in
Avatar of todd-
todd-

asked on

Easy SetParent question

I've done this before, but I can't remember how I got it working (and why it won't now). I want to set a form as a child of another form. I know I need to use the SetParent API, but it's like it doesn't see that line. My project is set up with frmMain and frmChannel. Here's the frmMain code:

Public Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
' The standard stuff goes here, taken out to save space
#End Region

    Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objTest As New frmChannel
        SetParent(objTest.Handle.ToInt32, Me.Handle.ToInt32)
        objTest.Show()
    End Sub
End Class

According to http://www.allapi.net/ SetParent returns nonzero when it succeeds. When I used MsgBox to see what the output was, it was a really huge number (nonzero) but it didn't get set as a child. What am I doing wrong?

I'm using VB.NET 2003 in case you're wondering.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of todd-
todd-

ASKER

Very nice, thanks a lot :)
It's odd though, I remember last time copying and pasting the API straight from allapi.net and to get it to work together I just had to use .ToInt32.

Whatever, thanks all the same :D