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

Add FindWindowEx #86

Open
rhinosharp opened this issue Aug 22, 2019 · 2 comments
Open

Add FindWindowEx #86

rhinosharp opened this issue Aug 22, 2019 · 2 comments

Comments

@rhinosharp
Copy link

rhinosharp commented Aug 22, 2019

// here: findWindow *windows.LazyProc
findWindowEx *windows.LazyProc

// here: findWindow = libuser32.NewProc("FindWindowW")
findWindowEx = libuser32.NewProc("FindWindowExW")

//here: func FindWindow(lpClassName, lpWindowName *uint16) HWND {
// add by rhinosharp team
func FindWindowEx(hWndParent HWND, hWndChild HWND, lpClassName, lpWindowName *uint16) HWND {
ret, _, _ := syscall.Syscall6(findWindowEx.Addr(), 4,
uintptr(hWndParent),
uintptr(hWndChild),
uintptr(unsafe.Pointer(lpClassName)),
intptr(unsafe.Pointer(lpWindowName)),
0,
0)

return HWND(ret)
}

@rhinosharp
Copy link
Author

example:
// StringToUTF16PtrElseNil String To UTF16Ptr if empty string trans to nil
func StringToUTF16PtrElseNil(str string) *uint16 {
if str == "" {
return nil
}
return syscall.StringToUTF16Ptr(str)
}

// FindWindow find window hwnd by name class="" if nil,nil mean ignore it
func FindWindow(class, title string) win.HWND {
var hwnd win.HWND
hwnd = win.FindWindow(StringToUTF16PtrElseNil(class), StringToUTF16PtrElseNil(title))
return hwnd
}

// FindWindowEx find window hwnd by name class="" if nil,nil mean ignore it
func FindWindowEx(hWndParent, hWndChild win.HWND, class, title string) win.HWND {
var hwnd win.HWND
hwnd = win.FindWindowEx(hWndParent, hWndChild,
StringToUTF16PtrElseNil(class),
StringToUTF16PtrElseNil(title))
return hwnd
}

@UDBIAWDIF
Copy link

// FindWindowEx find window hwnd by name class="" if nil,nil mean ignore it 这个注释要更新一下

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

2 participants