microsoft / microsoft/PowerToys
[FancyZones] Feature Request: Add "Force window resize"
- Dominant language
- C
- Stars
- 139k
- Forks
- 8.6k
- PR merge metrics
- PR metrics pending
Description
### Description of the new feature / enhancement
**Description**
Currently, FancyZones respects the minimum and maximum size constraints set by the application window itself. Some applications (especially those with fixed layouts or legacy interfaces) cannot be snapped to small or specific zones because they refuse to be resized beyond their internal limits.
I propose a new feature/toggle: "Force window resize".
When enabled, FancyZones will use Win32 API methods (like SetWindowPos with specific flags) to override these constraints and force the window into the selected zone dimensions during the snapping process.
**Proposed Behavior**
User enables "Force window resize" in FancyZones settings.
User drags a window towards a zone.
Even if the window has a MINMAXINFO constraint that is larger than the zone, FancyZones forces the window to match the zone's size.
**example**
bilibili.exe
current
expected
### Scenario when this would be used?
When dragging windows with hard-coded resolution constraints.
### Supporting information
```c#
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
class WindowResizer
{
// --- Win32 API 导入 ---
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
// 关键 API:让程序运行在“无 DPI 感知”模式,直接操作原始像素
[DllImport("user32.dll")]
static extern bool SetProcessDPIAware();
[StructLayout(LayoutKind.Sequential)]
public struct RECT { public int Left, Top, Right, Bottom; }
const uint SWP_NOSENDCHANGING = 0x0400;
const uint SWP_NOACTIVATE = 0x0010;
static void Main()
{
// 第一步:彻底忽略 Windows 的缩放设置
SetProcessDPIAware();
string processName = "QQMusic"; // 按需修改
int targetW = 1300;
int targetH = 1100;
Console.WriteLine($"[VS Code 运行中] 正在死守 {processName} 尺寸为 {targetW}x{targetH}");
while (true)
{
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 0)
{
IntPtr hWnd = processes[0].MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
GetWindowRect(hWnd, out RECT rect);
int currentW = rect.Right - rect.Left;
int currentH = rect.Bottom - rect.Top;
// 只要尺寸不对,就强制重置
if (currentW != targetW || currentH != targetH)
{
// 保持当前位置 (rect.Left, rect.Top),仅修改大小
SetWindowPos(hWnd, IntPtr.Zero, rect.Left, rect.Top, targetW, targetH, SWP_NOSENDCHANGING | SWP_NOACTIVATE);
}
}
}
Thread.Sleep(50); // 50ms 检查一次,反应极快且不占 CPU
}
}
}
```
A somewhat janky C# implementation powered by AI.
Contributor guide
Research direction
Start by reviewing the FancyZones settings flow and the window snapping process described in the issue. Determine how a "Force window resize" toggle would interact with existing MINMAXINFO constraints and Win32 resizing behavior. Done means the setting is available, enabled windows can match smaller zones, and normal constraint-respecting behavior remains unchanged when it is disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100