-
Notifications
You must be signed in to change notification settings - Fork 11
/
dpi_windows.go
46 lines (38 loc) · 985 Bytes
/
dpi_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// +build windows
package strife
import (
"fmt"
"log"
"syscall"
)
func abort(funcname string, err error) {
panic(fmt.Sprintf("%s failed: %v", funcname, err))
}
// windows allows us to set the DPI awareness
// to be enabled programmatically. Mac does not
// however... but maybe in the future :(
func EnableDPI() {
mod := syscall.NewLazyDLL("Shcore.dll")
if mod != nil {
log.Println("EnableDPI: Error loading DLL?")
return
}
proc := mod.NewProc("SetProcessDpiAwareness")
if err := proc.Find(); err != nil {
log.Println("EnableDPI: ", err)
return
}
PROCESS_PER_MONITOR_DPI_AWARE := 0x00000002
type HRESULT int32
const (
S_OK HRESULT = 0x00000000
E_INVALIDARG = 0x80070057
E_ACCESSDENIED = 0x80070005
)
ret, _, _ := proc.Call(uintptr(PROCESS_PER_MONITOR_DPI_AWARE))
if HRESULT(ret) == S_OK {
log.Println("DPI Awareness enabled!", string(ret))
} else {
log.Println("Failed to enable DPI Awareness ", string(ret))
}
}