private LRESULT WmNcCalcSize( HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam ) {
			if( wParam.intValue() != 1 )
				return User32Ex.INSTANCE.CallWindowProc( defaultWndProc, hwnd, uMsg, wParam, lParam );

			NCCALCSIZE_PARAMS params = new NCCALCSIZE_PARAMS( new Pointer( lParam.longValue() ) );

			// store the original top before the default window proc applies the default frame
			int originalTop = params.rgrc[0].top;

			// apply the default frame
			LRESULT lResult = User32Ex.INSTANCE.CallWindowProc( defaultWndProc, hwnd, uMsg, wParam, lParam );
			if( lResult.longValue() != 0 )
				return lResult;

			// re-read params from native memory because defaultWndProc changed it
			params.read();

			// re-apply the original top from before the size of the default frame was applied
			params.rgrc[0].top = originalTop;

			boolean isMaximized = User32Ex.INSTANCE.IsZoomed( hwnd );
			if( isMaximized && !isFullscreen() ) {
				// When a window is maximized, its size is actually a little bit larger
				// than the monitor's work area. The window is positioned and sized in
				// such a way that the resize handles are outside of the monitor and
				// then the window is clipped to the monitor so that the resize handle
				// do not appear because you don't need them (because you can't resize
				// a window when it's maximized unless you restore it).
				params.rgrc[0].top += getResizeHandleHeight();

				// check whether taskbar is in the autohide state
				APPBARDATA autohide = new APPBARDATA();
				autohide.cbSize = new DWORD( autohide.size() );
				int state = Shell32.INSTANCE.SHAppBarMessage( new DWORD( ABM_GETSTATE ), autohide ).intValue();
				if( (state & ABS_AUTOHIDE) != 0 ) {
					// get monitor info
					// (using MONITOR_DEFAULTTONEAREST finds right monitor when restoring from minimized)
					HMONITOR hMonitor = User32.INSTANCE.MonitorFromWindow( hwnd, MONITOR_DEFAULTTONEAREST );
					MONITORINFO monitorInfo = new MONITORINFO();
					User32.INSTANCE.GetMonitorInfo( hMonitor, monitorInfo );

					// If there's a taskbar on any side of the monitor, reduce our size
					// a little bit on that edge.
					if( hasAutohideTaskbar( ABE_TOP, monitorInfo.rcMonitor ) )
						params.rgrc[0].top++;
					if( hasAutohideTaskbar( ABE_BOTTOM, monitorInfo.rcMonitor ) )
						params.rgrc[0].bottom--;
					if( hasAutohideTaskbar( ABE_LEFT, monitorInfo.rcMonitor ) )
						params.rgrc[0].left++;
					if( hasAutohideTaskbar( ABE_RIGHT, monitorInfo.rcMonitor ) )
						params.rgrc[0].right--;
				}
			} else if( SystemInfo.isWindows_11_orLater ) {
				// For Windows 11, add border thickness to top, which is necessary to make the whole Java area visible.
				// This also avoids that a black line is sometimes painted on top window border.
				// Note: Do not increase top on Windows 10 because this would not hide Windows title bar.
				IntByReference borderThickness = new IntByReference();
				if( DWMApi.INSTANCE.DwmGetWindowAttribute( hwnd, DWMApi.DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
						borderThickness.getPointer(), 4 ) == WinError.S_OK.intValue() )
					params.rgrc[0].top += borderThickness.getValue();
			}

			// write changed params back to native memory
			params.write();

			return lResult;
		}
Handle WM_NCCALCSIZE

https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-nccalcsize

See also NonClientIslandWindow::_OnNcCalcSize() here:
https://github.com/microsoft/terminal/blob/main/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
flatlaf-natives/flatlaf-natives-jna/src/main/java/com/formdev/flatlaf/natives/jna/windows/FlatWindowsNativeWindowBorder.java