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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题