mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Windows: fixed wrong layout in maximized frame after changing screen scale factor (issue #904)
Some checks failed
CI / build (11, ) (push) Has been cancelled
CI / build (17, ) (push) Has been cancelled
CI / build (21, ) (push) Has been cancelled
CI / build (23, ) (push) Has been cancelled
CI / build (8, ) (push) Has been cancelled
Native Libraries / Natives (macos) (push) Has been cancelled
Native Libraries / Natives (ubuntu) (push) Has been cancelled
Native Libraries / Natives (windows) (push) Has been cancelled
CI / snapshot (push) Has been cancelled
CI / release (push) Has been cancelled
Some checks failed
CI / build (11, ) (push) Has been cancelled
CI / build (17, ) (push) Has been cancelled
CI / build (21, ) (push) Has been cancelled
CI / build (23, ) (push) Has been cancelled
CI / build (8, ) (push) Has been cancelled
Native Libraries / Natives (macos) (push) Has been cancelled
Native Libraries / Natives (ubuntu) (push) Has been cancelled
Native Libraries / Natives (windows) (push) Has been cancelled
CI / snapshot (push) Has been cancelled
CI / release (push) Has been cancelled
Windows binaries built and signed locally in clean workspace
This commit is contained in:
@@ -309,6 +309,8 @@ public class FlatWindowsNativeWindowBorder
|
||||
WM_ENTERSIZEMOVE = 0x0231,
|
||||
WM_EXITSIZEMOVE = 0x0232,
|
||||
|
||||
WM_DPICHANGED = 0x02E0,
|
||||
|
||||
WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320;
|
||||
|
||||
// WM_SIZE wParam
|
||||
@@ -501,6 +503,22 @@ public class FlatWindowsNativeWindowBorder
|
||||
isMoving = true;
|
||||
break;
|
||||
|
||||
case WM_DPICHANGED:
|
||||
LRESULT lResult = User32Ex.INSTANCE.CallWindowProc( defaultWndProc, hwnd, uMsg, wParam, lParam );
|
||||
|
||||
// if window is maximized and DPI/scaling changed, then Windows
|
||||
// does not send a subsequent WM_SIZE message and Java window bounds,
|
||||
// which depend on scale factor, are not updated
|
||||
boolean isMaximized = User32Ex.INSTANCE.IsZoomed( hwnd );
|
||||
if( isMaximized ) {
|
||||
MyRECT r = new MyRECT( new Pointer( lParam.longValue() ) );
|
||||
int width = r.right - r.left;
|
||||
int height = r.bottom - r.top;
|
||||
User32Ex.INSTANCE.CallWindowProc( defaultWndProc, hwnd, WM_SIZE, new WPARAM( SIZE_MAXIMIZED ), MAKELPARAM( width, height ) );
|
||||
}
|
||||
|
||||
return lResult;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
// do not erase background while the user is moving the window,
|
||||
// otherwise there may be rendering artifacts on HiDPI screens with Java 9+
|
||||
@@ -818,6 +836,13 @@ public class FlatWindowsNativeWindowBorder
|
||||
return (low & 0xffff) | ((high & 0xffff) << 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same implementation as MAKELPARAM(l, h) macro in winuser.h.
|
||||
*/
|
||||
private LPARAM MAKELPARAM( int low, int high ) {
|
||||
return new LPARAM( MAKELONG( low, high ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Same implementation as RGB(r,g,b) macro in wingdi.h.
|
||||
*/
|
||||
@@ -937,6 +962,23 @@ public class FlatWindowsNativeWindowBorder
|
||||
}
|
||||
}
|
||||
|
||||
//---- class MyRECT -------------------------------------------------------
|
||||
|
||||
@FieldOrder( { "left", "top", "right", "bottom" } )
|
||||
public static class MyRECT
|
||||
extends Structure
|
||||
{
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
|
||||
public MyRECT( Pointer pointer ) {
|
||||
super( pointer );
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
//---- class MENUITEMINFO -------------------------------------------------
|
||||
|
||||
@FieldOrder( { "cbSize", "fMask", "fType", "fState", "wID", "hSubMenu",
|
||||
|
||||
@@ -19,3 +19,32 @@ The DLLs were built on a GitHub server with the help of GitHub Actions. See:
|
||||
[Native Libraries](https://github.com/JFormDesigner/FlatLaf/actions/workflows/natives.yml)
|
||||
workflow. Then the produced Artifacts ZIP was downloaded, signed DLLs with
|
||||
FormDev Software code signing certificate and committed the DLLs to Git.
|
||||
|
||||
|
||||
## Development
|
||||
|
||||
To build the library on Windows using Gradle, (parts of)
|
||||
[Visual Studio Community
|
||||
2022](https://visualstudio.microsoft.com/downloads/)
|
||||
needs to be installed. After downloading and running `VisualStudioSetup.exe` the
|
||||
**Visual Studio Installer** is installed and started. Once running, it shows the
|
||||
**Workloads** tab that allows you to install additional packages. Either choose
|
||||
**Desktop development with C++**, or to save some disk space switch to the
|
||||
**Single Components** tab and choose following components (newest versions):
|
||||
|
||||
- MSVC v143 - VS 2022 C++ x64/x86 Buildtools
|
||||
- MSVC v143 - VS 2022 C++ ARM64/ARM64EC Buildtools
|
||||
- Windows 11 SDK
|
||||
|
||||
Note that the Visual Studio Installer shows many similar named components for
|
||||
MSVC. Make sure to choose exactly those components listed above.
|
||||
|
||||
Using
|
||||
[Build Tools for Visual Studio 2022](https://visualstudio.microsoft.com/downloads/#remote-tools-for-visual-studio-2022)
|
||||
(installs only compiler and SDKs) instead of
|
||||
[Visual Studio Community
|
||||
2022](https://visualstudio.microsoft.com/downloads/)
|
||||
does not work with Gradle.
|
||||
|
||||
[Visual Studio Code](https://code.visualstudio.com/) with **C/C++** extension
|
||||
can be used for C++ code editing.
|
||||
|
||||
@@ -288,6 +288,23 @@ LRESULT CALLBACK FlatWndProc::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, L
|
||||
isMoving = true;
|
||||
break;
|
||||
|
||||
case WM_DPICHANGED: {
|
||||
LRESULT lResult = ::CallWindowProc( defaultWndProc, hwnd, uMsg, wParam, lParam );
|
||||
|
||||
// if window is maximized and DPI/scaling changed, then Windows
|
||||
// does not send a subsequent WM_SIZE message and Java window bounds,
|
||||
// which depend on scale factor, are not updated
|
||||
bool isMaximized = ::IsZoomed( hwnd );
|
||||
if( isMaximized ) {
|
||||
RECT* r = reinterpret_cast<RECT*>( lParam );
|
||||
int width = r->right - r->left;
|
||||
int height = r->bottom - r->top;
|
||||
::CallWindowProc( defaultWndProc, hwnd, WM_SIZE, SIZE_MAXIMIZED, MAKELPARAM( width, height ) );
|
||||
}
|
||||
|
||||
return lResult;
|
||||
}
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
// do not erase background while the user is moving the window,
|
||||
// otherwise there may be rendering artifacts on HiDPI screens with Java 9+
|
||||
|
||||
Reference in New Issue
Block a user