public SurrogateMdiChild(HookedMdiWindow parent, string title, Rectangle location, bool isResizable, bool isMovable, ISurrogateMdiChildContent childContent) { Contract.Requires(parent != null); Contract.Requires(childContent != null); this.Parent = parent; this.IsResizable = isResizable; this.IsMovable = isMovable; this.ChildContent = childContent; this.Surrogate = new SurrogateMdiChildControl(this); this.Surrogate.Text = title; this.Surrogate.ClientSize = location.Size; this.Surrogate.Location = location.Location; this.Surrogate.CreateControl(); // for some reason, these are re-added despite CreateParams // so we have to remove them here var hwnd = this.Surrogate.Handle; var ws = GetWindowLong(hwnd, GWL_STYLE); ws &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX); ws &= ~(IsResizable ? 0 : WS_THICKFRAME); SetWindowLong(hwnd, GWL_STYLE, ws); // since we changed the window styles, we have to redraw SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); }
// called by Surrogate private void OnDestroy() { if (IsDestroyed) { return; } IsDestroyed = true; // GC Roots: // - Parent.SurrogatedChildren // released via Parent.NotifyClosed(this) // - UI -> SurrogateMdiChildControl // released in WM_DESTROY (caller to this method) // - CCW -> this // not in our control, so we have to minimize held references // Held references: // - ChildContent (CCW) // - Surrogate ChildContent = null; Surrogate = null; Parent.NotifyClosed(this); }