Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

Winform inside MDI client

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MLM450@hotmail.com - 18 Oct 2005 21:17 GMT
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
Ditlef - 21 Oct 2005 15:04 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.