How to implement in WPF window sticking to the edge of the screen? Here is the code found for WinForms. PS For those who do not understand the assignment: sticking to the edge is when you move the form to the edge, and it at some distance is magnetized to the edge. ScreenSnap in VCL is called.
protected override void WndProc ( ref Message m ) { if (m.Msg == 0x0046 /* WM_WINDOWPOSCHANGING */) { Rectangle workArea = SystemInformation.WorkingArea; Rectangle rect = (Rectangle)Marshal.PtrToStructure((IntPtr)(IntPtr.Size * 2 + m.LParam.ToInt64()), typeof(Rectangle)); if (rect.X <= workArea.Left + DISTANCE) Marshal.WriteInt32(m.LParam, IntPtr.Size * 2, workArea.Left); if (rect.X + rect.Width >= workArea.Width - DISTANCE) Marshal.WriteInt32(m.LParam, IntPtr.Size * 2, workArea.Right - rect.Width); if (rect.Y <= workArea.Top + DISTANCE) Marshal.WriteInt32(m.LParam, IntPtr.Size * 2 + 4, workArea.Top); if (rect.Y + rect.Height >= workArea.Height - DISTANCE) Marshal.WriteInt32(m.LParam, IntPtr.Size * 2 + 4, workArea.Bottom - rect.Height); } base.WndProc(ref m); }