Added DPI awareness methods
This commit is contained in:
parent
390e65d845
commit
1110afa379
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2021 dorkbox, llc
|
* Copyright 2023 dorkbox, llc
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -38,7 +38,14 @@ import dorkbox.os.OS;
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
class ShCore {
|
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 GetDpiForMonitor = null;
|
||||||
|
private static Function SetProcessDpiAwareness = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (OS.Windows.INSTANCE.isWindows8_1_plus()) {
|
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.
|
// Abusing static fields this way is not proper, but it gets the job done nicely.
|
||||||
// GetDpiForMonitor is NOT always available! (Windows 8.1+)
|
// GetDpiForMonitor is NOT always available! (Windows 8.1+)
|
||||||
GetDpiForMonitor = library.getFunction("GetDpiForMonitor");
|
GetDpiForMonitor = library.getFunction("GetDpiForMonitor");
|
||||||
|
SetProcessDpiAwareness = library.getFunction("SetProcessDpiAwareness");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,4 +90,18 @@ class ShCore {
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 dorkbox, llc
|
* Copyright 2023 dorkbox, llc
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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_LBUTTONUP = 0x202;
|
||||||
int WM_RBUTTONUP = 0x205;
|
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.
|
* 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
|
* https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-monitorfrompoint
|
||||||
*/
|
*/
|
||||||
HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2017 dorkbox, llc
|
* Copyright 2023 dorkbox, llc
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -122,4 +122,12 @@ class User32_32 implements User32 {
|
||||||
@Override
|
@Override
|
||||||
public native
|
public native
|
||||||
HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags);
|
HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native
|
||||||
|
Pointer SetThreadDpiAwarenessContext(Pointer dpiContext);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native
|
||||||
|
int GetDpiForSystem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2017 dorkbox, llc
|
* Copyright 2023 dorkbox, llc
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -127,4 +127,12 @@ class User32_64 implements User32 {
|
||||||
@Override
|
@Override
|
||||||
public native
|
public native
|
||||||
HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags);
|
HMONITOR MonitorFromPoint(POINT.ByValue pt, int dwFlags);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native
|
||||||
|
Pointer SetThreadDpiAwarenessContext(Pointer dpiContext);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native
|
||||||
|
int GetDpiForSystem();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue