lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.19k stars 313 forks source link

missing WaitForInputIdle and GetWindowModuleFileName #63

Open StephanVerbeeck opened 5 years ago

StephanVerbeeck commented 5 years ago

Could you merge these functions?

var (
    moduser32                  = syscall.NewLazyDLL("user32.dll")
    procWaitForInputIdle       = moduser32.NewProc("WaitForInputIdle")
    proGetWindowModuleFileName = moduser32.NewProc("GetWindowModuleFileNameW")
)

// WaitForInputIdle waits until the specified process has finished processing its initial input and is waiting for user input with no input pending, or until the time-out interval has elapsed.
func WaitForInputIdle(hwnd win.HWND, timeoutMsec int) {
    _, _, _ = procWaitForInputIdle.Call(
        uintptr(hwnd),
        uintptr(timeoutMsec))
}

// GetWindowModuleFileName retrieves the full path and file name of the module associated with the specified window handle.
func GetWindowModuleFileName(hwnd win.HWND) (moduleFileName string) {
    bufLen := 1000
    buf := make([]uint16, bufLen+1)
    textLen, _, _ := proGetWindowModuleFileName.Call(
        uintptr(hwnd),
        uintptr(unsafe.Pointer(&buf[0])),
        uintptr(bufLen))

    if textLen > 0 { // processes of other owner do not reveal their info (unless we have elevated privilege)
        moduleFileName = syscall.UTF16ToString(buf)
    }
    return
}