You create a Microsoft Windows form (such as Form1), and then you set the IsMdiContainer property of the form to True. You create a Microsoft Visual Basic 6.0 user control, and then you add the user control to a Windows form (Form1) in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005. If you create the Windows form as the parent form of another Windows form that contains user controls, you display the child form, and then you run the application on a computer that runs on the Microsoft Windows 98 operating system, you receive the following error message:
System.InvalidOperationException: Unable to get the window handle for the 'AxUserControl1' control. Windowless ActiveX controls are not supported.
Note This article assumes that Visual Basic 6.0 and Microsoft .NET Framework 1.0 are installed on your computer with Windows 98.
When you create a Windows form that contains user controls as a multiple-document interface (MDI) child form, the Windows form always destroys the child form, and then re-creates the child form. The Windows form destroys all the controls on the child form, and then re-creates the controls. However, the first user control is destroyed, but it is not re-created. The second user control is not destroyed or re-created. Therefore, you receive the error when you display the child form, because the first user control hwnd is NULL.
To work around this problem, put the user controls in a Panel control. To do this, follow these steps:
From the toolbox, drag a Panel control to Form1.
By default, Panel1 is created.
Move two user controls to Panel1.
On the Build menu, click Build Solution.
In the Bin subfolder of the WindowsApplication1 project folder, copy the WindowsApplication1.exe file, and then paste the file in the Setup1 folder on the computer that runs on Windows 98.
This behavior is by design.
Steps to Reproduce the Behavior
To create a Microsoft Visual Basic ActiveX control, follow these steps:
Open Visual Basic 6.0.
In the New Project dialog box, click ActiveX Control, and then click Open.
By default, UserControl1 is created.
Right-click UserControl1, and then click Properties.
In the Properties window, set the BackColor property to Highlight.
On File menu, click Make Project1.ocx.
Click to select a location to save your control file in, and then click OK.
To create a Windows application with the user control that you created in step 1, follow these steps:
In Visual Studio .NET or in Visual Studio 2005, start a new Windows application by using Microsoft Visual Basic .NET, Microsoft Visual Basic 2005, or Microsoft Visual C# .NET.
By default, Form1 is created.
On the Tools menu, click Customize Toolbox.
In Microsoft Visual Studio .NET 2003, click Add/Remove Toolbox Items on the Tools menu.
In Microsoft Visual Studio 2005, click Choose Toolbox Items on the Tools menu.
Click the COM Components tab, and then click Browse.
Locate the Project1.ocx file that you created in step 1, click Project1.ocx, and then click Open.
In the Customize Toolbox dialog box, click OK.
From the toolbox, drag UserControl1 to Form1.
Repeat step 2f to add another user control to the form.
On the Project menu, click Add Windows Form, and then click Open.
By default, Form2 is created
Right-click Form2, and then set the IsMdiContainer property to True.
From the toolbox, drag a Button control to Form2.
Add the following code to the Button1_Click event handler:
Visual Basic .NET or Visual Basic 2005 Code
Dim b As Form1b = New Form1()'Set Form2 as the parent of Form1.b.MdiParent = Me'Display Form1 when the button is clicked.b.Show()
Visual C# .NET Code
Form1 b= new Form1();//Set Form2 as the parent of Form1.b.MdiParent=this;//Display Form1 when the button is clicked.b.Show();
Note Add the following code after the Button1_Click event handler in Visual C# .NET:
In Solution Explorer, right-click WindowsApplication1, and then click Properties.
In the WindowsApplication1 property pages, click to select Form2 in the Startup object list, and then click OK.
On the Build menu, click Build Solution.
Create a Setup1 folder on your computer.
From the Bin subfolder in your WindowsApplication1 project folder, copy the AxInterop.Project1.dll file, copy the Interop.Project1.dll file, and copy the WindowsApplication1.exe file to the Setup folder.
From the location you where you saved the Visual Basic 6.0 user control that you created, copy the Project1.ocx file to the Setup1 folder.
Copy the Setup1 folder to a computer that runs on the Windows 98 operating system.
On the computer that runs on the Windows 98 operating system, click Start, and then click Run.
Type cmd in the Open text box, and then press the ENTER key.
To register the control, run the following command at the command prompt:
regsvr32 <project1.ocx file path on your local computer>
Right-click WindowsApplication1, click Open, and then click Button1.
You receive the exception mentioned in the "Symptoms" section of this article.
For more information, visit the following MSDN Web site:
Microsoft Visual Basic 2005, Microsoft Visual Basic .NET 2003 Standard Edition, Microsoft Visual Basic .NET 2002 Standard Edition, Microsoft Visual C# .NET 2003 Standard Edition, Microsoft Visual C# .NET 2002 Standard Edition, Microsoft Visual Basic 4.0 Enterprise Edition, Microsoft Windows 98 Standard Edition