我想知道是否有任何庫可以幫助我控制另一個窗口。例如,如果用戶運行calc.exe,我希望我的代碼移動它,調整它的大小,甚至可以刪除它的框架,附加東西,idk。用另一個窗口控制另一個窗口
現在我只知道如何使用腳本語言,如autoit或autohotkey或whatnot。
我想知道是否有任何庫可以幫助我控制另一個窗口。例如,如果用戶運行calc.exe,我希望我的代碼移動它,調整它的大小,甚至可以刪除它的框架,附加東西,idk。用另一個窗口控制另一個窗口
現在我只知道如何使用腳本語言,如autoit或autohotkey或whatnot。
是的,有幾個庫可以使用godoc.org或go-search.org找到。在這個例子中,我使用w32和w32syscall(其中提供了一些附加功能):
package main
import (
"log"
"strings"
"syscall"
"github.com/AllenDang/w32"
"github.com/hnakamur/w32syscall"
)
func main() {
err := w32syscall.EnumWindows(func(hwnd syscall.Handle, lparam uintptr) bool {
h := w32.HWND(hwnd)
text := w32.GetWindowText(h)
if strings.Contains(text, "Calculator") {
w32.MoveWindow(h, 0, 0, 200, 600, true)
}
return true
}, 0)
if err != nil {
log.Fatalln(err)
}
}
這兩個庫都只是暴露最小包裝底層的Win32 API,所以你必須讀微軟的corresponding documentation真正知道如何使用它們。
謝謝。我是否也可以通過w32去包裝來實現這個https://msdn.microsoft.com/en-us/library/windows/desktop/bb688195(v=vs.85).aspx? – user1340531 2015-04-04 19:35:39
看起來像是在w32庫中定義的:http://godoc.org/github.com/AllenDang/w32#DwmExtendFrameIntoClientArea – Caleb 2015-04-04 19:39:23
它返回0,並且不會不幸地做任何事情,甚至在我說框架改變之後w32.SetWindowPos( h,0,0,0,200,600,w32.SWP_FRAMECHANGED) – user1340531 2015-04-04 20:17:33
https://github.com/AllenDang/w32實現了Win32 API並擁有您所需的全部功能。 – tobiash 2015-04-04 15:23:28