protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_SHOWWINDOW) { RECT rChild = new RECT(); RECT rOwner = new RECT(); GetWindowRect(data.SnapHandle, ref rOwner); SnapPoint sp = data.snapPoint; if (sp.NeedsChildRect) { GetWindowRect(Handle, ref rChild); } // must do this, otherwise when the window is invisible (e.g. owner is minimized) then its location resets Point pt = sp.GetLocation(rChild, rOwner); SetWindowPos(Handle, IntPtr.Zero, pt.X, pt.Y, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); } }
protected override void WndProc(ref Message m) { base.WndProc(ref m); // several different approaches were tried, such as WM_MOVING, WM_MOVED, WM_WINDOWPOSCHANGING // WM_MOVING and WM_MOVED do not account for resizing the window. WM_WINDOWPOSCHANGING fires // false events (e.g. clicking on the title bar near (but not on) the minimize window button). if (m.Msg == WM_WINDOWPOSCHANGED) { WINDOWPOS pos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS)); // -32000 means the window is minimized. if (pos.x > -32000 && pos.y > -32000) { RECT rChild = new RECT(); RECT rOwner = new RECT(); if (data.SnapHandle == Handle) { rOwner.Top = pos.y; rOwner.Left = pos.x; rOwner.Bottom = pos.y + pos.cy; rOwner.Right = pos.x + pos.cx; } else { GetWindowRect(data.SnapHandle, ref rOwner); } SnapPoint sp = data.snapPoint; if (sp.NeedsChildRect) { GetWindowRect(data.nwChild.Handle, ref rChild); } Point pt = sp.GetLocation(rChild, rOwner); SetWindowPos(data.nwChild.Handle, IntPtr.Zero, pt.X, pt.Y, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); } } }