Actually, I am calling SetParent from within the parent form. Also, my code (and yours) contains an error: Form2.Load will not work. It should be Form2.Show. Sorry about that.
The actual code should read:
Form1:
=====
Private Sub Form_Load
Me.Show
Form2.Show
Call SetParent(Form2.hwnd, Form1.hwnd)
End Sub
No code is required in Form2.
Regarding the Null handle, there is no such thing. When Windows creates a new window (or any other element for that matter) the very first thing that it does is allocates a memory handle. Therefore, even if the SetParent call was being made in the child form, the .hWnd property would still not be null.
Main Topics
Browse All Topics





by: jbabcockPosted on 1998-04-02 at 08:08:24ID: 1460182
The SetParent function makes the target window parentless if the second parameter is Null. I'll bet you that Null is being passed in that call.
To test this, put a stop marker at the beginning of Form2.Load(), and check the value of Form1.hWnd. It may be zero, which means that you're attempting to use an invalid handle.
Try moving the setparent call up into Form1.Load(), like this:
Form1:
=====
Private Sub Form_Load()
Form2.Load
Call SetParent(Form2.hWnd, Form1.hWnd)
End Sub