From 0df2131ae363d24eb52316e51d47503aee0642e6 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Wed, 6 Jan 2021 18:08:16 +1100 Subject: [PATCH] windows: add GetShellWindow and GetWindowThreadProcessId I am trying to implement https://devblogs.microsoft.com/oldnewthing/20190425-00/?p=102443 so I need these functions. Change-Id: Id5082e4cc450569ffd021f4a300d56de325e4952 Reviewed-on: https://go-review.googlesource.com/c/sys/+/280717 Trust: Alex Brainman Trust: Brad Fitzpatrick Run-TryBot: Alex Brainman TryBot-Result: Go Bot Reviewed-by: Brad Fitzpatrick --- windows/syscall_windows.go | 2 ++ windows/zsyscall_windows.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 8ad1cae8..38344590 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -213,6 +213,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys CancelIoEx(s Handle, o *Overlapped) (err error) //sys CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessW //sys OpenProcess(desiredAccess uint32, inheritHandle bool, processId uint32) (handle Handle, err error) +//sys GetWindowThreadProcessId(wnd uintptr, pid *uint32) (tid uint32) = user32.GetWindowThreadProcessId +//sys GetShellWindow() (desktopWindow uintptr) = user32.GetShellWindow //sys ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) [failretval<=32] = shell32.ShellExecuteW //sys shGetKnownFolderPath(id *KNOWNFOLDERID, flags uint32, token Token, path **uint16) (ret error) = shell32.SHGetKnownFolderPath //sys TerminateProcess(handle Handle, exitcode uint32) (err error) diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 5ad0b9bf..06273735 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -341,6 +341,8 @@ var ( procSHGetKnownFolderPath = modshell32.NewProc("SHGetKnownFolderPath") procShellExecuteW = modshell32.NewProc("ShellExecuteW") procExitWindowsEx = moduser32.NewProc("ExitWindowsEx") + procGetShellWindow = moduser32.NewProc("GetShellWindow") + procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId") procMessageBoxW = moduser32.NewProc("MessageBoxW") procCreateEnvironmentBlock = moduserenv.NewProc("CreateEnvironmentBlock") procDestroyEnvironmentBlock = moduserenv.NewProc("DestroyEnvironmentBlock") @@ -2896,6 +2898,18 @@ func ExitWindowsEx(flags uint32, reason uint32) (err error) { return } +func GetShellWindow() (desktopWindow uintptr) { + r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0) + desktopWindow = uintptr(r0) + return +} + +func GetWindowThreadProcessId(wnd uintptr, pid *uint32) (tid uint32) { + r0, _, _ := syscall.Syscall(procGetWindowThreadProcessId.Addr(), 2, uintptr(wnd), uintptr(unsafe.Pointer(pid)), 0) + tid = uint32(r0) + return +} + func MessageBox(hwnd Handle, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) { r0, _, e1 := syscall.Syscall6(procMessageBoxW.Addr(), 4, uintptr(hwnd), uintptr(unsafe.Pointer(text)), uintptr(unsafe.Pointer(caption)), uintptr(boxtype), 0, 0) ret = int32(r0)