diff --git a/src/dorkbox/jna/windows/ShCore.java b/src/dorkbox/jna/windows/ShCore.java index 2b72952..0ff266e 100644 --- a/src/dorkbox/jna/windows/ShCore.java +++ b/src/dorkbox/jna/windows/ShCore.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,14 @@ import dorkbox.os.OS; */ public class ShCore { + public static final int DPI_AWARENESS_INVALID = -1; + public static final int DPI_AWARENESS_UNAWARE = 0; + public static final int DPI_AWARENESS_SYSTEM_AWARE = 1; + public static final int DPI_AWARENESS_PER_MONITOR_AWARE = 2; + + private static Function GetDpiForMonitor = null; + private static Function SetProcessDpiAwareness = null; static { if (OS.Windows.INSTANCE.isWindows8_1_plus()) { @@ -47,6 +54,7 @@ class ShCore { // Abusing static fields this way is not proper, but it gets the job done nicely. // GetDpiForMonitor is NOT always available! (Windows 8.1+) GetDpiForMonitor = library.getFunction("GetDpiForMonitor"); + SetProcessDpiAwareness = library.getFunction("SetProcessDpiAwareness"); } } @@ -82,4 +90,18 @@ class ShCore { return null; } } + + /** + * https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness + */ + public static int SetProcessDpiAwareness(int value) { + if (SetProcessDpiAwareness != null) { + // HRESULT SetProcessDpiAwareness( + // [in] PROCESS_DPI_AWARENESS value + // ); + return (int) SetProcessDpiAwareness.invoke(Integer.class, new Object[]{value}); + } else { + return -1; + } + } } diff --git a/src/dorkbox/jna/windows/User32.java b/src/dorkbox/jna/windows/User32.java index adf62e5..fcaabda 100644 --- a/src/dorkbox/jna/windows/User32.java +++ b/src/dorkbox/jna/windows/User32.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,10 @@ interface User32 { int WM_LBUTTONUP = 0x202; int WM_RBUTTONUP = 0x205; + Pointer DPI_AWARENESS_CONTEXT_UNAWARE = new Pointer(-1); + Pointer DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = new Pointer(-2); + Pointer DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = new Pointer(-3); + /** * This is overridden by the 64-bit version to be SetWindowLongPtr instead. */ @@ -170,4 +174,14 @@ interface User32 { * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-monitorfrompoint */ HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags); + + /** + * https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforsystem + */ + int GetDpiForSystem(); + + /** + * https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setthreaddpiawarenesscontext + */ + Pointer SetThreadDpiAwarenessContext(Pointer dpiContext); } diff --git a/src/dorkbox/jna/windows/User32_32.java b/src/dorkbox/jna/windows/User32_32.java index 9b36b97..27f560e 100644 --- a/src/dorkbox/jna/windows/User32_32.java +++ b/src/dorkbox/jna/windows/User32_32.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,4 +122,12 @@ class User32_32 implements User32 { @Override public native HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags); + + @Override + public native + Pointer SetThreadDpiAwarenessContext(Pointer dpiContext); + + @Override + public native + int GetDpiForSystem(); } diff --git a/src/dorkbox/jna/windows/User32_64.java b/src/dorkbox/jna/windows/User32_64.java index c0a1a7c..8cdf13a 100644 --- a/src/dorkbox/jna/windows/User32_64.java +++ b/src/dorkbox/jna/windows/User32_64.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,4 +127,12 @@ class User32_64 implements User32 { @Override public native HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags); + + @Override + public native + Pointer SetThreadDpiAwarenessContext(Pointer dpiContext); + + @Override + public native + int GetDpiForSystem(); }