We are starting to use Winforms mixed with MFC.
I would create a C++ View window managing the Winforms sub-window.
We found information on the net how to create and reparent a WinForms window.
/// <summary>
/// Win32 wrapper for API call SetParent
/// </summary>
public class Win32
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetParent(int hWndChild, int hWndNewParent);
public static void SetParentWnd(int hWndChild, int hWndNewParent)
{
try
{
SetParent(hWndChild, hWndNewParent);
}
catch (Exception e)
{
ScLog.Debug("EchoDotNet2", "Win32.SetParentWnd() call caused
exception: " + e.Message);
}
}
}
Creating Winforms: TheForm is a Winform class:
m_theForm = new TheForm();
VoidPtr rootWindow; // Window handle from C++
// Set Win32 parent window (from host), needed for true
Win32 parent/child
Win32.SetParentWnd(m_theForm.Handle.ToInt32(),
rootVP.ToInt32());
// Show it
m_theForm.Show();
Also handle window resize when the C++ View resizes:
System.Drawing.Point pt = new System.Drawing.Point(m_size.X,
m_size.Y);
m_theForm.Location = pt;
m_theForm.Width = m_size.Width;
m_theForm.Height = m_size.Height;
This + a bit of glue to create from C++ and pass window + Rect on resize may
give you a start.
Cheers
Ditlef
> Is it possible to show a C# winform that stays within an unmanaged C++
> MDI client area? Basically, I want the winform to behave like a
> standard view window. If it is possible, how can I accomplish it?
>
> Thanks