private void spawnInMonitor() { Rect rect = Rect.Empty; // Use the active window to determine the active monitor Win32.GUITHREADINFO gui = new Win32.GUITHREADINFO(); gui.cbSize = Marshal.SizeOf(gui); bool success = Win32.GetGUIThreadInfo(0, ref gui); if (success) { if (gui.hwndActive != IntPtr.Zero) { Win32.RECT windowRect = new Win32.RECT(); bool success2 = Win32.GetWindowRect(gui.hwndActive, ref windowRect); if (success2) { rect = windowRect.asRect(); } } } // If that fails, use the cursor to determine the active monitor if (rect.IsEmpty) { int left = System.Windows.Forms.Cursor.Position.X; int top = System.Windows.Forms.Cursor.Position.Y; rect = new Rect(left, top, 0, 0); } PlacementSide monitorPlacement = ((App)Application.Current).Preferences.monitorPlacement; WindowUtils.PutWindowNear(this, WindowUtils.MonitorWorkAreaFromRect(rect), monitorPlacement, PlacementInOut.INSIDE); }