app/internal/window: use GetDpiForWindow if available

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-07-19 10:41:47 +02:00
parent ae07c5f470
commit 39fd161bea
2 changed files with 22 additions and 9 deletions
+13 -1
View File
@@ -207,6 +207,7 @@ var (
_GetClientRect = user32.NewProc("GetClientRect")
_GetClipboardData = user32.NewProc("GetClipboardData")
_GetDC = user32.NewProc("GetDC")
_GetDpiForWindow = user32.NewProc("GetDpiForWindow")
_GetKeyState = user32.NewProc("GetKeyState")
_GetMessage = user32.NewProc("GetMessageW")
_GetMessageTime = user32.NewProc("GetMessageTime")
@@ -343,7 +344,7 @@ func getDpiForMonitor(hmonitor syscall.Handle, dpiType uint32) int {
// GetSystemDPI returns the effective DPI of the system.
func GetSystemDPI() int {
// Check for getDpiForMonitor, introduced in Windows 8.1.
// Check for GetDpiForMonitor, introduced in Windows 8.1.
if _GetDpiForMonitor.Find() == nil {
hmon := monitorFromPoint(Point{}, MONITOR_DEFAULTTOPRIMARY)
return getDpiForMonitor(hmon, MDT_EFFECTIVE_DPI)
@@ -377,6 +378,17 @@ func GetMessageTime() time.Duration {
return time.Duration(r) * time.Millisecond
}
// GetWindowDPI returns the effective DPI of the window.
func GetWindowDPI(hwnd syscall.Handle) int {
// Check for GetDpiForWindow, introduced in Windows 10.
if _GetDpiForWindow.Find() == nil {
dpi, _, _ := _GetDpiForWindow.Call(uintptr(hwnd))
return int(dpi)
} else {
return GetSystemDPI()
}
}
func GlobalAlloc(size int) (syscall.Handle, error) {
r, _, err := _GlobalAlloc.Call(GHND, uintptr(size))
if r == 0 {