doubi4491 2015-04-04 14:52 采纳率: 0%
浏览 86
已采纳

使用Go控制另一个窗口

I'm wondering if there are any libraries that help me take control of another window. For example if user has calc.exe running, I'd like my go code to move it, resize it, maybe even remove it's frame, attach stuff to it, idk.

Right now I only know how to do it with scripting languages like autoit or autohotkey or whatnot.

  • 写回答

1条回答 默认 最新

  • douxin8383 2015-04-04 15:30
    关注

    Yes there are several libraries which can be found using godoc.org or go-search.org. In this example I'm using w32 and w32syscall (which supplies some additional functions):

    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)
        }
    }
    

    Both of these libraries are merely exposing the underlying win32 API with minimal wrapping, so you will have to read the corresponding documentation from Microsoft to really know how to use them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题