microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Non resizable window withouth title bar has border when updating to 1.6

Open DCorrBECare opened this issue 1 year ago • 4 comments

Describe the bug

With the 1.6 version i get a white border around a window that's not resizable.

Steps to reproduce the bug

Create a window with the following code:

Window window = new();
OverlappedPresenter presenter = OverlappedPresenter.Create();
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(false, false);
window.AppWindow.SetPresenter(presenter);
window.AppWindow.Show();

Expected behavior

There is no border around the window

Screenshots

Window1_5 Window1_6

NuGet package version

WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007

Windows version

Windows 11 (22H2): Build 22621

Additional context

Works fine with WindowsAppSDK 1.5.240802000

DCorrBECare avatar Sep 12 '24 10:09 DCorrBECare

Also running into this issue, worked fine on 1.5. Is there any fix / workaround?

Usergitbit avatar Sep 26 '24 16:09 Usergitbit

@Usergitbit There is no fix that I'm aware of and I do not now if this will be fixed in the next release.

I guess as a workaround you can manually implement the MaxWidth/MaxHeight/MinWidth/MinHeight on the window, set the window resizable and set the same value to the max and min property. The downside would be that the cursor appears to be resizable on the window when it's actually not.

You can look at this great project for extended features on the Window class.

DCorrBECare avatar Sep 26 '24 18:09 DCorrBECare

Also running into this issue, worked fine on 1.5. Is there any fix / workaround?

You can remove the style for the frame :

private IntPtr hWndMain = IntPtr.Zero;

hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
SetWindowLong(hWndMain, GWL_STYLE, (IntPtr)(GetWindowLong(hWndMain, GWL_STYLE) & ~(WS_DLGFRAME)));

with :

        const int GWL_STYLE = (-16);
        const int GWL_EXSTYLE = (-20);
        public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
        {
            if (IntPtr.Size == 4)
            {
                return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
            }
            return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
        }

        [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
        public static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

        [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
        public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

        public static long GetWindowLong(IntPtr hWnd, int nIndex)
        {
            if (IntPtr.Size == 4)
            {
                return GetWindowLong32(hWnd, nIndex);
            }
            return GetWindowLongPtr64(hWnd, nIndex);
        }

        [DllImport("User32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern long GetWindowLong32(IntPtr hWnd, int nIndex);

        [DllImport("User32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern long GetWindowLongPtr64(IntPtr hWnd, int nIndex);

        public const int WS_DLGFRAME = 0x00400000;

castorix avatar Sep 26 '24 19:09 castorix

That seems to work for me, thanks @castorix!

Usergitbit avatar Sep 27 '24 13:09 Usergitbit

Workaround works for me, but still it's a workaround please fix that

bszymik avatar Oct 25 '24 08:10 bszymik

Really annoying bug where customers are asking questions to the developer (us) on why their app is "messed up".. Years later and WinUI3 is still terrible

Sebbe909 avatar Oct 31 '24 12:10 Sebbe909

This trick works for me after upgrading 1.6 even though I decided to revert back to 1.5 because of other issues.

ExtendsContentIntoTitleBar = true;
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(true, false);

Prochy avatar Nov 01 '24 09:11 Prochy

This trick works for me after upgrading 1.6 even though I decided to rollback back to 1.5 because of other issues.

ExtendsContentIntoTitleBar = true;
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(true, false);

Nice Trick tnx

ghost1372 avatar Nov 01 '24 16:11 ghost1372

Try OverlappedPresenter.CreateForContextMenu()

Lightczx avatar Nov 05 '24 07:11 Lightczx

Just did some reverse work: CreateForContextMenu = WS_BORDER CreateForDialog = WS_SYSMENU | WS_CAPTION CreateForToolWindow = WS_OVERLAPPEDWINDOW

IsAlwaysOnTop = WS_EX_TOPMOST IsMaximizable = WS_MAXIMIZEBOX IsMinimizable = WS_MINIMIZEBOX IsModal = Enable/Disable parent Window and some other stuff (restricted to hwnd with owner set) See https://github.com/microsoft/WindowsAppSDK/issues/3258 IsResizable = WS_SIZEBOX(WS_THICKFRAME)

Lightczx avatar Nov 07 '24 02:11 Lightczx

another solution:

private const int GWL_STYLE = -16;
private const long WS_BORDER = 0x00800000;
private const long WS_CAPTION = 0x00C00000;
private const long WS_THICKFRAME = 0x00040000;

// Importing necessary P/Invoke methods
[DllImport("user32.dll", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(
    IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

private const uint SWP_NOMOVE = 0x0002;
private const uint SWP_NOSIZE = 0x0001;
private const uint SWP_FRAMECHANGED = 0x0020;

var hWnd = (nint)AppWindow.Id.Value;

// Get the current window style
long style = GetWindowLong(hWnd, GWL_STYLE);

// Remove border, caption, and thick frame
style &= ~WS_BORDER & ~WS_CAPTION & ~WS_THICKFRAME;

// Apply the new style
SetWindowLong(hWnd, GWL_STYLE, style);

// Update the window's appearance
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);

ghost1372 avatar Jan 14 '25 12:01 ghost1372

Still an issue for 1.6.250205002 (released Fed 11, 2025). Kind of epic that it took >4 years and can't make a window correct. I updated to 1.6 because 1.5 has #8947, and now it has this regression that did not exist in 1.5

HO-COOH avatar Feb 26 '25 07:02 HO-COOH

This seems to continue to be an issue for 1.7.250310001 (Windows 11 24H2 fwiw).

The workarounds above do continue to work. The only thing is that if you then turn on again borders/resizable the application ends up in a bit of an odd state where you can't move the window anymore(?). I tried to apply the same style flag again but that did seem to quite work.. But take this with a grain of salt, since I only tested it briefly. I would much rather this just gets fixed since the application I'm working on, while it in borderless mode for customers, when we developers are working on it we like having a titlebar and border so we can move it around in our own environment.

torleifat avatar Apr 01 '25 12:04 torleifat