diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-04 10:42:42 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-04 10:42:42 +0200 |
commit | 4acbabbcec8d1bcb898079ba71f8f41383940594 (patch) | |
tree | 9a45d9a1a08740ef9422b61b4359dbf76656a903 | |
parent | Merge pull request #66 from zx2c4-forks/jd/shellexecute (diff) | |
download | wireguard-windows-4acbabbcec8d1bcb898079ba71f8f41383940594.tar.xz wireguard-windows-4acbabbcec8d1bcb898079ba71f8f41383940594.zip |
user32/kernel32: add thread attachment functions
These generally help with raising windows to the foreground forcibly.
Resolves: https://github.com/lxn/win/pull/22
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | kernel32.go | 11 | ||||
-rw-r--r-- | user32.go | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/kernel32.go b/kernel32.go index b81b7573..0a50aee1 100644 --- a/kernel32.go +++ b/kernel32.go @@ -64,6 +64,7 @@ var ( fileTimeToSystemTime *windows.LazyProc getConsoleTitle *windows.LazyProc getConsoleWindow *windows.LazyProc + getCurrentThreadId *windows.LazyProc getLastError *windows.LazyProc getLocaleInfo *windows.LazyProc getLogicalDriveStrings *windows.LazyProc @@ -144,6 +145,7 @@ func init() { fileTimeToSystemTime = libkernel32.NewProc("FileTimeToSystemTime") getConsoleTitle = libkernel32.NewProc("GetConsoleTitleW") getConsoleWindow = libkernel32.NewProc("GetConsoleWindow") + getCurrentThreadId = libkernel32.NewProc("GetCurrentThreadId") getLastError = libkernel32.NewProc("GetLastError") getLocaleInfo = libkernel32.NewProc("GetLocaleInfoW") getLogicalDriveStrings = libkernel32.NewProc("GetLogicalDriveStringsW") @@ -222,6 +224,15 @@ func GetConsoleWindow() HWND { return HWND(ret) } +func GetCurrentThreadId() uint32 { + ret, _, _ := syscall.Syscall(getCurrentThreadId.Addr(), 0, + 0, + 0, + 0) + + return uint32(ret) +} + func GetLastError() uint32 { ret, _, _ := syscall.Syscall(getLastError.Addr(), 0, 0, @@ -1610,6 +1610,7 @@ var ( // Functions addClipboardFormatListener *windows.LazyProc adjustWindowRect *windows.LazyProc + attachThreadInput *windows.LazyProc animateWindow *windows.LazyProc beginDeferWindowPos *windows.LazyProc beginPaint *windows.LazyProc @@ -1669,6 +1670,7 @@ var ( getWindowLongPtr *windows.LazyProc getWindowPlacement *windows.LazyProc getWindowRect *windows.LazyProc + getWindowThreadProcessId *windows.LazyProc insertMenuItem *windows.LazyProc invalidateRect *windows.LazyProc isChild *windows.LazyProc @@ -1739,6 +1741,7 @@ func init() { // Functions addClipboardFormatListener = libuser32.NewProc("AddClipboardFormatListener") adjustWindowRect = libuser32.NewProc("AdjustWindowRect") + attachThreadInput = libuser32.NewProc("AttachThreadInput") animateWindow = libuser32.NewProc("AnimateWindow") beginDeferWindowPos = libuser32.NewProc("BeginDeferWindowPos") beginPaint = libuser32.NewProc("BeginPaint") @@ -1803,6 +1806,7 @@ func init() { } getWindowPlacement = libuser32.NewProc("GetWindowPlacement") getWindowRect = libuser32.NewProc("GetWindowRect") + getWindowThreadProcessId = libuser32.NewProc("GetWindowThreadProcessId") insertMenuItem = libuser32.NewProc("InsertMenuItemW") invalidateRect = libuser32.NewProc("InvalidateRect") isChild = libuser32.NewProc("IsChild") @@ -1891,6 +1895,15 @@ func AdjustWindowRect(lpRect *RECT, dwStyle uint32, bMenu bool) bool { return ret != 0 } +func AttachThreadInput(idAttach int32, idAttachTo int32, fAttach bool) bool { + ret, _, _ := syscall.Syscall(attachThreadInput.Addr(), 3, + uintptr(idAttach), + uintptr(idAttachTo), + uintptr(BoolToBOOL(fAttach))) + + return ret != 0 +} + func AnimateWindow(hwnd HWND, dwTime, dwFlags uint32) bool { ret, _, _ := syscall.Syscall(animateWindow.Addr(), 3, uintptr(hwnd), @@ -1909,6 +1922,15 @@ func BeginDeferWindowPos(nNumWindows int32) HDWP { return HDWP(ret) } +func GetWindowThreadProcessId(hwnd HWND, processId *uint32) uint32 { + ret, _, _ := syscall.Syscall(getWindowThreadProcessId.Addr(), 2, + uintptr(hwnd), + uintptr(unsafe.Pointer(processId)), + 0) + + return uint32(ret) +} + func BeginPaint(hwnd HWND, lpPaint *PAINTSTRUCT) HDC { ret, _, _ := syscall.Syscall(beginPaint.Addr(), 2, uintptr(hwnd), |