Looking to work around a window sizing bug

I just filed <https://xojo.com/issue/67988> but in the meantime I’m looking for a workaround. I need to know the size of the window chrome around a window. This should be simple with Window.Bounds, but on Windows 11 it isn’t returning the correct data. It thinks there is a border on the edges.

I don’t know Windows declares well enough. I looked through MBS, but I didn’t see anything that might help. But there’s so much there that I could have missed it.

As a sidenote, I suspect this bug is related to the reason we can resize our windows just a few pixels smaller than the minimum, and then it jumps to what the minimum is supposed to be.

i think DesktopWindow still belongs to Win32.

you could see what location returns here.

Sub Pressed() Handles Pressed
  System.DebugLog System.Version.ToString
  #If TargetWindows Then
    ' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect
    ' https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-rect
    Declare Function GetWindowRect Lib "User32" Alias "GetWindowRect" (hWnd As Ptr, lpRect As Ptr) As Boolean
    Dim mb As New MemoryBlock( 16 ) '4+4+4+4
    Call GetWindowRect(Self.Handle, mb)
    System.DebugLog mb.Int32Value(0).ToString 'left
    System.DebugLog mb.Int32Value(4).ToString 'top
    System.DebugLog mb.Int32Value(8).ToString 'right
    System.DebugLog mb.Int32Value(12).ToString 'bottom
End Sub

Returns the same thing. So I guess this is a Win32 issue, not a Xojo issue?

I think that the 16 pixel difference in the width is Windows allowing for the 8 pixels for the rounded corners on each side. It doesn’t prevent you from using the full width but you have to figure it in (unless/until Micro$oft gives us a way to choose the corner style).

I mean, it kind of does. If I want my actual window width to be 1200, I would do something like

Var Frame As Rect = Self.Bounds
Frame.Width = 1200
Self.Bounds = Frame

This is supposed to mean that the outside width of the window is 1200, instead of the inside width. So if this were on Windows 7, the window actually takes up 1200 pixels but the content is smaller. Windows 10 and 11 allow edge-to-edge content, but this code still produces an 1184px wide inner size. So I don’t get the effect I want since I now have an 1184 pixel wide window instead of the 1200 I asked for.

You could try this one from the example project Monitors:
Declare Function MoveWindow Lib "User32" (hWnd As Integer, x As Int32, y As Int32, nWidth As Int32, nHeight As Int32, bRepaint As Boolean) As Boolean

That should allow you to position and size a Window the way you want/need. But you obviously need to handle the Scale Factor yourself (the Declare works with “pixels”, not “points” such as Xojo does)… as well as the correct x, y (especially with multiple Monitors, and worse with multi-monitors that have different DPI - which is what this example is all about, to work around Xojo’s bugs in that regard).

But honestly: I haven’t tried this on Windows 11 myself yet.