Solved

Easy SetParent question

Posted on 2004-04-20
2
461 Views
Last Modified: 2008-03-04
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.
0
Comment
Question by:todd-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 25 total points
ID: 10873443
Your API declaration was for VB6.  Try this out instead:

Public Class Form1
    Inherits System.Windows.Forms.Form

    ' Region " Windows Form Designer generated code "

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

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

Regards,

Idle_Mind
0
 
LVL 1

Author Comment

by:todd-
ID: 10873536
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question