Hosting System.Windows.Forms.Form (instead of UserControl)

G

Guest

I have an (ActiveX) UserControl hosted in MFC application. Because the
UserControl does not support main menu, which I need, I tried to host Form
directly, but MFC hosting (VC++ 6.0) reports a "Not Supported" exception
while attempting to set site. Does anyone know whether is possible to host
Form instead of UserControl? I have not found any differences in UserControl
and Form code (using Lutz Roeder's Reflector) that should have effect on
hosting behavior (both UserControl and Form are derived from
ContainerControl). Am I missing something important?
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Stanislav,

No form's cannot be hosted. Forms represent TopLevel windows. Top-level
widnows is the one used for application's main windows and are shown on the
taskbar, etc. Top-level windows cannot have parent's, but they might have
owners.
Child windows on the other hand is the ones that can be hosted. Child
windows, though, cannot have main menu. If you look at the Win32 API for
creating windows you'll see that the same paramether that is used to set
top-level window's main menu for the child windows is used to set the
control ID.

Form class has one proeprty TopLevel. When set to false the form can be
hosted by other form's. However, what the property does is it make the form
a child window thus, the form loses its main menu.

But you are right there is not much of difference between form's and user
controls. At the very end they are control's (windows). However they are
meant to serve different purposes.

The botton line: unless you don't use some third party menubar conrol you
cannot have main menu on child control (window). Windows OS says so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top