尝试通过syscall获取窗口信息(例如EnumWindows等)。

huangapple go评论103阅读模式
英文:

Go/Golang Trying to get window information via syscall. (As in EnumWindows, etc.)

问题

感谢阅读和您可能有的任何评论。

背景:

  • 我已经从事UI/R&D开发(原型制作等)超过20年,刚开始进行服务器/后端开发。
  • 我对Go非常陌生-不到2个月的时间-并且已经完成了GoByExample的大部分内容,并在Amazon EC2实例上设置了一个简单的工作Web服务器。
  • 我使用另一种语言创建了一个UI,用于为另一个第三方应用程序提供HUD(抬头显示)-一个生成多个窗口的游戏(类似于多个窗口中运行的多个扑克桌)。
  • 我将HUD连接到我创建的Go客户端。
  • 我使用Go获取操作系统信息,因为第一种语言存在一些限制。
  • 我想继续使用Go,因为我真的很喜欢它。
  • 我使用的是Windows 7机器。

目标:

  • 大局观:当用户移动一个窗口时,我希望HUD也随之移动。

  • 为此,我需要关于窗口文本以“Game”开头的主窗口的信息。

  • 理想情况下,应该是这样的:

      windows: [ { windowHwnd:hwnd, windowText:windowText, windowX:x, windowY:y, windowWidth:width, windowHeight:height },
      .
      .
      .
      { windowHwnd:hwnd, windowText:windowText, windowX:x, windowY:y, windowWidth:width, windowHeight:height } ]
    

我已经采取的步骤:

  • 我已经获取并修改了github.com/AllenDang/w32,我认为它可以为Go格式化syscall。
  • 当我需要从user32.go中获取未列出的函数时,我会添加它。
  • 尝试使用GetForegroundWindow和GetWindowText获取结果,然后使用GetWindow(hwnd, previous)遍历所有窗口。
  • 阅读了以下内容:
    • syscall文档(http://golang.org/pkg/syscall/)
    • syscall/dll_windows.go
    • syscall/env_windows.go
    • syscall/exec_windows.go
    • syscall/syscall.go
    • syscall/syscall_windows.go
    • syscall/syscall_windows_386.go
    • syscall/syscall_windows_amd86.go
    • syscall/syscall_windows_test.go
    • syscall/zsyscall_windows_386.go
    • syscall/zsyscall_windows_amd86.go
    • syscall/ztypes_windows.go
    • syscall/ztypes_windows_386.go
    • syscall/ztypes_windows_amd86.go
  • 查找Windows Dev Center上的每个潜在窗口函数。
  • 在StackExchange、Google和DuckDuckGo上搜索。
  • 我可以看到有一些东西(TestEnumWindows)
    • 在runtime/syscall_windows_test.go的第125行(http://golang.org/src/pkg/runtime/syscall_windows_test.go)
    • 尽管这个函数在syscall_windows_test.go中不存在

问题:

  • 有更好的解决方案吗?在我的无知中,我可能很容易忽视像GiveGeoffreyExactlyWhatHeWants()这样的方法。
  • 我的方向正确吗?
  • 在Go中是否可行?
  • 前进的正确方向是什么?
  • 还有其他人需要这个吗?
英文:

Thanks for reading and any comments you may have.

Context:

  • I've been a UI/R&D dev (prototyping, etc.) for over 20 years and just started server/backend development.
  • I'm very new to Go - less than 2 months - and have 1) run through much of GoByExample and 2) set up a primitive, working web server on an Amazon EC2 instance.
  • I created a UI in another language which serves a HUD (Heads Up Display) for another 3rd party application - a game which spawns multiple windows. (Think multiple poker tables running in multiple windows.)
  • I connected the HUD to a Go client I created.
  • I use Go to grab OS information because of limitations in the first language.
  • I want to continue to use Go because I really enjoy it.
  • I'm on a Windows 7 machine.

Goal(s):

  • Big picture: When a User moves a window, I want the HUD to move with it.

  • To do this I need information about the main windows whos WindowText starts with "Game".

  • The ideal would be something like this:

     windows: [ { windowHwnd:hwnd, windowText:windowText, windowX:x, windowY:y, windowWidth:width, windowHeight:height },
     .
     .
     .
     { windowHwnd:hwnd, windowText:windowText, windowX:x, windowY:y, windowWidth:width, windowHeight:height } ]
    

Steps I've taken:

  • I've grabbed and modified github.com/AllenDang/w32 which I think formats syscall for Go.
  • When I need an unlisted function from user32.go, I add it.
  • Tried using GetForegroundWindow and GetWindowText with result, then GetWindow( hwnd, previous ) to just walkthrough everything
  • Read through:
  • syscall docs (http://golang.org/pkg/syscall/)
  • syscall/dll_windows.go
  • syscall/env_windows.go
  • syscall/exec_windows.go
  • syscall/syscall.go
  • syscall/syscall_windows.go
  • syscall/syscall_windows_386.go
  • syscall/syscall_windows_amd86.go
  • syscall/syscall_windows_test.go
  • syscall/zsyscall_windows_386.go
  • syscall/zsyscall_windows_amd86.go
  • syscall/ztypes_windows.go
  • syscall/ztypes_windows_386.go
  • syscall/ztypes_windows_amd86.go
  • Every potential Window Function at Windows Dev Center
  • Searched StackExchange, Google, DuckDuckGo
  • I can see there's something (TestEnumWindows)
  • line 125 in runtime/syscall_windows_test.go (http://golang.org/src/pkg/runtime/syscall_windows_test.go)
  • Though this function doesn't exist in syscall_windows_test.go

Questions:

  • Better solution? In my ignorance I could easily be overlooking some method like: GiveGeoffreyExactlyWhatHeWants()
  • Am I in the right ballpark?
  • Is this doable in Go?
  • What's the right direction to head?
  • Is this something anybody else needs?

答案1

得分: 9

不清楚你想要什么,但也许这个链接可以帮到你:http://play.golang.org/p/YfGDtIuuBw。它使用EnumWindows函数来查找具有特定标题的窗口。

Alex

英文:

It is not clear what you want , but perhaps http://play.golang.org/p/YfGDtIuuBw will help. It uses EnumWindows to find window with a particular title.

Alex

huangapple
  • 本文由 发表于 2013年10月18日 04:41:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/19436860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定