Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

My question is simple, but VERY important to me [sigh] .. as far as I know, one managed wnd can be parent of any unmanaged wnd... no vicevesa... I'm not an expert and I'd like to suggest that someone could post one example to do this...could be VERY useful to everybody :)

One unmanaged window ( C++ ) can be parent of one Managed ( C#.NET ) window ?? if this is possible... please share with me the answer...

Thanks in advance,
Best regards.
Posted

1 solution

richard072 wrote:
could be VERY useful to everybody


Whehe, good argument [laugh]

First, you add a using clause;
using System.Runtime.InteropServices;
Next, copy this code into your class;
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]<br />static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);<br />[DllImport("user32.dll", EntryPoint = "SetParent", SetLastError = true)]<br />static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
Next, add this code to the place where you want to change the parent;
IntPtr window = FindWindowByCaption(IntPtr.Zero, "Calculator");<br />SetParent(window, this.Handle);


--edit--
I posted the reverse thing, but it's also possible from C++ using the same technique. A quick suggestion tho - why not make an ActiveX-control out of the C# window?

Enjoy :)

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900