gpt4 book ai didi

go - golang 中的 EnumChildWindows 回调函数

转载 作者:IT王子 更新时间:2023-10-29 02:23:28 33 4
gpt4 key购买 nike

在 main 中使用包 lxn/win:

win.EnumChildWindows(hw, printme, 0)

然后在 main 之后:

func printme(HWND win.HANDLE, LPARAM uintptr) { //HWND hwnd, LPARAM lParam
spew.Dump(HWND)
}

我得到:

.\test.go:40: cannot use printme (type func(win.HANDLE, uintptr)) as type uintptr in argument to win.EnumChildWindows

error:exit status 2

我不明白错误信息。

最佳答案

我让它工作于:

win.EnumChildWindows(hwnd, syscall.NewCallback(printme), 0)

func printme(hwnd uintptr, lParam uintptr) uintptr {
spew.Dump(hwnd)
fmt.Printf("getWindowText: '%s'\n", getWindowText(hwnd))
return 1 // true to continue
}

参见 lxn/win issue 19 :

The callback signature is wrong: it has to return a value of type int32 (C BOOL) that is nonzero if the function should continue enumeration.
See MSDN.

For example, it could be:

func printme(hwnd uintptr, lParam uintptr) int32 {
spew.Dump(hwnd)
return 1 // true to continue
}

关于go - golang 中的 EnumChildWindows 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35370748/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com