Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DCorrBECare opened this issue Sep 12, 2024 · 11 comments
Open
Labels
area-AppWindow bug Something isn't working Regression team-CompInput Issue for IXP (Composition, Input) team

Comments

@DCorrBECare
Copy link

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 DCorrBECare added the bug Something isn't working label Sep 12, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 12, 2024
@codendone codendone added area-AppWindow team-CompInput Issue for IXP (Composition, Input) team Regression and removed needs-triage Issue needs to be triaged by the area owners labels Sep 13, 2024
@Usergitbit
Copy link

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

@DCorrBECare
Copy link
Author

DCorrBECare commented Sep 26, 2024

@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.

@castorix
Copy link

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;

@Usergitbit
Copy link

Usergitbit commented Sep 27, 2024

That seems to work for me, thanks @castorix!

@bszymik
Copy link

bszymik commented Oct 25, 2024

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

@Sebbe909
Copy link

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

@Prochy
Copy link

Prochy commented Nov 1, 2024

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);

@ghost1372
Copy link
Contributor

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

@Lightczx
Copy link

Lightczx commented Nov 5, 2024

Try OverlappedPresenter.CreateForContextMenu()

@Lightczx
Copy link

Lightczx commented Nov 7, 2024

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 microsoft/WindowsAppSDK#3258
IsResizable = WS_SIZEBOX(WS_THICKFRAME)

@ghost1372
Copy link
Contributor

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-AppWindow bug Something isn't working Regression team-CompInput Issue for IXP (Composition, Input) team
Projects
None yet
Development

No branches or pull requests

9 participants