doucepei5298 2017-11-13 02:39
浏览 470

Windows-如何在Golang中获得屏幕分辨率

Great guy.

I have a requirement to get the windows system screen resolution,but I can't get any useful thing about this with google.

So I look for help in stackoverflow.

Anyone know how to do it?

Thanks advance.

updates: then I try this commandwmic desktopmonitor get screenheight screenwidth and get the answer like this:
this is the cmd: enter image description here

this is go-program: enter image description here

  • 写回答

4条回答 默认 最新

  • dow58115 2017-11-13 02:57
    关注

    I did some digging for you and found a way to get your screens width and height via command line in windows:

    wmic desktopmonitor get screenheight, screenwidth
    

    So all you have to do is execute this command in a Go program and print the output!

    package main
    
    import (
      "os/exec"
      "fmt"
      "log"
      "os"
    )
    
    func main() {
      command:= "wmic"
      args := []string{"desktopmonitor", "get", "screenheight,", "screenwidth"}
      cmd := exec.Command(command, args...)
      cmd.Stdin = os.Stdin
      out, err := cmd.Output()
      fmt.Printf("out: %#v
    ", string(out))
      fmt.Printf("err: %#v
    ", err)
      if err != nil {
        log.Fatal(err)
      }
    }
    

    Here is the Go Playground link : https://play.golang.org/p/KdIhrd3H1x

    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?