Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing WaitForInputIdle and GetWindowModuleFileName #63

Open
StephanVerbeeck opened this issue Apr 2, 2019 · 0 comments
Open

missing WaitForInputIdle and GetWindowModuleFileName #63

StephanVerbeeck opened this issue Apr 2, 2019 · 0 comments

Comments

@StephanVerbeeck
Copy link

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant