Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from shelllet/master
Browse files Browse the repository at this point in the history
add shcore, setprocessdpiaware
  • Loading branch information
JamesHovious authored Jul 25, 2019
2 parents 542e7ed + 8beb721 commit 8fb80e0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
22 changes: 22 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3026,3 +3026,25 @@ const (
ALPC_SYNC_OBJECT_TYPE uint32 = 2
ALPC_THREAD_OBJECT_TYPE uint32 = 4
)

// Device scale factor
// https://docs.microsoft.com/zh-cn/windows/win32/api/shtypes/ne-shtypes-device_scale_factor
const (
DEVICE_SCALE_FACTOR_INVALID = 0
SCALE_100_PERCENT = 100
SCALE_120_PERCENT = 120
SCALE_125_PERCENT = 125
SCALE_140_PERCENT = 140
SCALE_150_PERCENT = 150
SCALE_160_PERCENT = 160
SCALE_175_PERCENT = 175
SCALE_180_PERCENT = 180
SCALE_200_PERCENT = 200
SCALE_225_PERCENT = 225
SCALE_250_PERCENT = 250
SCALE_300_PERCENT = 300
SCALE_350_PERCENT = 350
SCALE_400_PERCENT = 400
SCALE_450_PERCENT = 450
SCALE_500_PERCENT = 500
)
24 changes: 24 additions & 0 deletions shcore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2010-2012 The W32 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package w32

import (
"syscall"
"unsafe"
)

var (
modshcore = syscall.NewLazyDLL("Shcore.dll")

getScaleFactorForMonitor = modshcore.NewProc("GetScaleFactorForMonitor")
)

func GetScaleFactorForMonitor(hMonitor HMONITOR, scale *int) HRESULT {
ret, _, _ := getScaleFactorForMonitor.Call(
uintptr(hMonitor),
uintptr(unsafe.Pointer(scale)))

return HRESULT(ret)
}
11 changes: 10 additions & 1 deletion user32.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/binary"
"errors"
"fmt"

//"regexp"
"syscall"
"unicode/utf8"
Expand Down Expand Up @@ -136,6 +137,7 @@ var (
procVkKeyScanW = moduser32.NewProc("VkKeyScanW")
procVkKeyScanExW = moduser32.NewProc("VkKeyScanExW")
procWaitMessage = moduser32.NewProc("WaitMessage")
setProcessDPIAware = moduser32.NewProc("SetProcessDPIAware")
)

func SendMessageTimeout(hwnd HWND, msg uint32, wParam, lParam uintptr, fuFlags, uTimeout uint32, lpdwResult uintptr) uintptr {
Expand Down Expand Up @@ -1261,11 +1263,18 @@ func VkKeyScanW(char uint16) int16 {
}

// Translates a character to the corresponding virtual-key code and shift state.
//See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-vkkeyscanexw
// See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-vkkeyscanexw
func VkKeyScanExW(char uint16, hkl HKL) int16 {
ret, _, _ := procVkKeyScanExW.Call(
uintptr(char),
uintptr(hkl),
)
return int16(ret)
}

// Sets the process-default DPI awareness to system-DPI awareness.
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware
func SetProcessDPIAware() bool {
ret, _, _ := setProcessDPIAware.Call()
return ret != 0
}

0 comments on commit 8fb80e0

Please sign in to comment.