Quote:
says...
> >SetParent Win-API function will do that.
> The SetParent function did almost do the job. The sub form is now
within the main
> form, but when I click on a control in the sub form the main form is
deactivated.
> Any idea?
You should have done it by using picturebox as a container.
Here is sample code:
-=Mike=-
(Jouni Tiainen, Carelcomp Forest, Imatra, Finland)
frmTest.frm (MAIN FORM)
-------------------------------------------------------
VERSION 4.00
Begin VB.Form frmTest
Caption = "Testing"
ClientHeight = 4050
ClientLeft = 2655
ClientTop = 2010
ClientWidth = 5085
Height = 4455
Left = 2595
LinkTopic = "Form1"
ScaleHeight = 4050
ScaleWidth = 5085
Top = 1665
Width = 5205
Begin VB.CommandButton cmdAdd
Caption = "Add"
Height = 435
Left = 3720
TabIndex = 1
Top = 180
Width = 1275
End
Begin VB.TextBox txtText
Height = 375
Left = 60
TabIndex = 0
Top = 180
Width = 3555
End
End
Attribute VB_Name = "frmTest"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdAdd_Click()
frmSub.lstList.AddItem txtText.Text
End Sub
Private Sub Form_Load()
Dim RC As Long
Load frmSub
RC = SetParent(frmSub.picX.hWnd, hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim RC As Long
RC = SetParent(frmSub.picX.hWnd, frmSub.hWnd)
Unload frmSub
End Sub
--------------------------------------------------
frmX.frm (SUBFORM)
--------------------------------------------------
VERSION 4.00
Begin VB.Form frmSub
Caption = "Subform"
ClientHeight = 4395
ClientLeft = 4740
ClientTop = 3810
ClientWidth = 6345
Height = 4800
Left = 4680
LinkTopic = "Form2"
ScaleHeight = 4395
ScaleWidth = 6345
Top = 3465
Width = 6465
Visible = 0 'False
Begin VB.PictureBox picX
Appearance = 0 'Flat
BackColor = &H00C0C0C0&
ForeColor = &H80000008&
Height = 3195
Left = 60
ScaleHeight = 3165
ScaleWidth = 4965
TabIndex = 0
Top = 840
Width = 4995
Begin VB.ListBox lstList
Height = 2790
Left = 120
TabIndex = 1
Top = 180
Width = 4695
End
End
End
Attribute VB_Name = "frmSub"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
--------------------------------------------
module1.bas
--------------------------------------------
Attribute VB_Name = "Module1"
Option Explicit
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long
--------------------------------------------