I want to create a control as a child of another window which is in another process. (I am trying to implement preview for a screen saver written in C#). In order to do that I have code like this:-
public class PreviewWindow : System.Windows.Forms.Control { private IntPtr parentHandle; public PreviewWindow(IntPtr parent) { this.parentHandle = parent; } const int WS_VISIBLE = 0x10000000; const int WS_CHILD = 0x40000000; protected override System.Windows.Forms.CreateParams CreateParams { get { System.Windows.Forms.CreateParams cp = base.CreateParams; cp.Style = WS_VISIBLE | WS_CHILD; cp.Parent = parentHandle; UnmanagedMethods.RECT rect = new UnmanagedMethods.RECT(); UnmanagedMethods.GetClientRect(parentHandle, ref rect); cp.X = rect.left; cp.Y = rect.top; cp.Height = rect.Height; cp.Width = rect.Width; return cp; } } } This code successfully creates the control as a child window but when WM_CLOSE message is sent to the Child Window (this control), the parent window gets closed. In case of screen saver the desktop settings dialog box disappears. It looks like (ILDASM) in response to WM_CLOSE the implementation Control sends WM_CLOSE to the top most parent. Any idea why this has been implemented like that? This is surely a bug. The only workaround is to handle WM_CLOSE in the WndProc function. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.