castorix / WinUI3_SwapChainPanel_Layered

47 stars 2 forks source link

How to remove the white edge of window? #1

Closed Poker-sang closed 1 year ago

Poker-sang commented 1 year ago

When I create a resizable, transparent window, there is always a white edge on the top of the window. Anyway to remove it while keeping the window border and resizing function?

btw, I commented _presenter.IsResizable = false, and then the border would not be removed by _presenter.SetBorderAndTitleBar (see also issue7629). Is there any P/Invoke method to resolve this?

BBP%9F2 M% G{B )7H4D~)5

castorix commented 1 year ago

It is because of DWM DWM can be removed with DWMWA_NCRENDERING_POLICY but you will get the old big resizing borders Otherwise, you can see threads on Google with DwmExtendFrameIntoClientArea like https://stackoverflow.com/questions/39731497/create-window-without-titlebar-with-resizable-border-and-without-bogus-6px-whit but I did not test with WinUI 3...

Poker-sang commented 1 year ago

It is because of DWM DWM can be removed with DWMWA_NCRENDERING_POLICY but you will get the old big resizing borders Otherwise, you can see threads on Google with DwmExtendFrameIntoClientArea like https://stackoverflow.com/questions/39731497/create-window-without-titlebar-with-resizable-border-and-without-bogus-6px-whit but I did not test with WinUI 3...

Thank you! But I tested the code in WinUI3 and failed... Perhaps I misunderstood some points.

I found that when setting _presenter.IsResizable = false, I can still only resize the window from the white edge side, the left, right and bottom side are maybe too thin to grip and resize?

And if I write this way:

long nExStyle = GetWindowLong(hWndMain, GWL_EXSTYLE);
if ((nExStyle & WS_EX_LAYERED) == 0)
{
    SetWindowLong(hWndMain, GWL_EXSTYLE, (IntPtr)(nExStyle | WS_EX_LAYERED));
    // other code in this region is deleted
}
// _presenter property setting is moved under here
_presenter = _apw.Presenter as Microsoft.UI.Windowing.OverlappedPresenter;
_presenter.IsResizable = false;
_presenter.SetBorderAndTitleBar(false, false);

The white edge disappeared, but we cannot use resize and snap fonction now.

Resizing is easy to implement, but I don't know how to trigger or response Snap Shortcut(Drag title bar to the edge of screen and snap) in Win11? I hope I'm not bothering you XD

A M`EMLY8I0VNZRO6XX1$D2

castorix commented 1 year ago

I don't know about snapping. I have only Windows 10; from my tests, snapping works in a C++/Win32 app with WS_OVERLAPPEDWINDOW style (+ WS_VISIBLE) on a Layered window, but then I tested the same style with WinUI 3 and it did not work at all...

Poker-sang commented 1 year ago

I don't know about snapping. I have only Windows 10; from my tests, snapping works in a C++/Win32 app with WS_OVERLAPPEDWINDOW style (+ WS_VISIBLE) on a Layered window, but then I tested the same style with WinUI 3 and it did not work at all...

Thank you!! I used to hear that to enable snap layout, we should response WM_NCHITTEST event and return HTMAXBUTTON. So, I thought maybe snap short cut (or mouse snap) may be implemented in the similar way? I will try it later.

qjl1569 commented 1 year ago

It is because of DWM DWM can be removed with DWMWA_NCRENDERING_POLICY but you will get the old big resizing borders Otherwise, you can see threads on Google with DwmExtendFrameIntoClientArea like https://stackoverflow.com/questions/39731497/create-window-without-titlebar-with-resizable-border-and-without-bogus-6px-whit but I did not test with WinUI 3...

Thank you! But I tested the code in WinUI3 and failed... Perhaps I misunderstood some points.

I found that when setting , I can still only resize the window from the white edge side, the left, right and bottom side are maybe too thin to grip and resize?_presenter.IsResizable = false

And if I write this way:

long nExStyle = GetWindowLong(hWndMain, GWL_EXSTYLE);
if ((nExStyle & WS_EX_LAYERED) == 0)
{
    SetWindowLong(hWndMain, GWL_EXSTYLE, (IntPtr)(nExStyle | WS_EX_LAYERED));
    // other code in this region is deleted
}
// _presenter property setting is moved under here
_presenter = _apw.Presenter as Microsoft.UI.Windowing.OverlappedPresenter;
_presenter.IsResizable = false;
_presenter.SetBorderAndTitleBar(false, false);

The white edge disappeared, but we cannot use resize and snap fonction now.

Resizing is easy to implement, but I don't know how to trigger or response Snap Shortcut(Drag title bar to the edge of screen and snap) in Win11? I hope I'm not bothering you XD

A M`EMLY8I0VNZRO6XX1$D2

Here is an example to remove the title block and keep the resizing border

https://github.com/qjl1569/winui3-samples

Poker-sang commented 1 year ago

Here is an example to remove the title block and keep the resizing border

https://github.com/qjl1569/winui3-samples

Thank you! It looks nice. But I want to keep the SwapChainPanel and transparent background, they looks like cannot be both. And better implement snap layout and snap short cut. Do you have any ideas?

qjl1569 commented 1 year ago

Here is an example to remove the title block and keep the resizing border https://github.com/qjl1569/winui3-samples

Thank you! It looks nice. But I want to keep the SwapChainPanel and transparent background, they looks like cannot be both. And better implement snap layout and snap short cut. Do you have any ideas?

Transparent background needs to add to the window WS EX NOREDIRECTIONBITMAP extends the style and removes the mandatory background added in the composition window. I think this needs to be fixed by the Microsoft team. Snapshot layout only needs to be set in Calculate the coordinates in the WM_ NCHITTEST message and return HTMAXBUTTON. 1

Poker-sang commented 1 year ago

Transparent background needs to add to the window WS EX NOREDIRECTIONBITMAP extends the style and removes the mandatory background added in the composition window. I think this needs to be fixed by the Microsoft team. Snapshot layout only needs to be set in Calculate the coordinates in the WM_ NCHITTEST message and return HTMAXBUTTON. 1

Thanks, I learnt a lot! And how about snap shortcut? That is to say, when dragging the window to the edge of the screen, the window automatically snaps?