zoukankan      html  css  js  c++  java
  • golang 开发gui

    可能因为我电脑上的mingw下只有gcc,没有g++的原因,之前用walk和andlabs都不成功

    最后用github上gxui的sample代码终于编译出来一个丑陋的GUI,但编译过程也提示了一堆类似以下内容的东东:

    note: expected 'LPCWSTR {aka const short unsigned int *}' but argument is of type 'CHAR * {aka char *}'
     WINUSERAPI HANDLE WINAPI LoadImageW (HINSTANCE, LPCWSTR, UINT, int, int, UINT);
    // Copyright 2015 The Go Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style
    // license that can be found in the LICENSE file.
    
    package main
     
    import (
        "time"
    
        "github.com/google/gxui"
        "github.com/google/gxui/drivers/gl"
        "github.com/google/gxui/gxfont"
        "github.com/google/gxui/math"
        "github.com/google/gxui/samples/flags"
    )
    
    func appMain(driver gxui.Driver) {
        theme := flags.CreateTheme(driver)
    
        font, err := driver.CreateFont(gxfont.Default, 75)
        if err != nil {
            panic(err)
        }
    
        window := theme.CreateWindow(380, 100, "Hi")
        window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
    
        label := theme.CreateLabel()
        label.SetFont(font)
        label.SetText("Hello world")
    
        window.AddChild(label)
    
        ticker := time.NewTicker(time.Millisecond * 30)
        go func() {
            phase := float32(0)
            for _ = range ticker.C {
                c := gxui.Color{
                    R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi),
                    G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi),
                    B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi),
                    A: 0.50 + 0.50*math.Cosf(phase*10),
                }
                phase += 0.01
                driver.Call(func() {
                    label.SetColor(c)
                })
            }
        }()
    
        window.OnClose(ticker.Stop)
        window.OnClose(driver.Terminate)
    }
    
    func main() {
        gl.StartDriver(appMain)
    }

     补充:

    按后面的文章更新了mingw ,解决了g++的问题,就没有不正常的提示信息了(虽然之前编译时有提示信息的情况下,程序仍能正常编译和执行)

    也就是用了github上robotgo推荐的带有zlib和libpng库的gcc环境:

    https://github.com/go-vgo/Mingw 

    另外,这个GUI运行时会弹出黑框,之前的文章提到过解决办法,如下:

    不想出现dos窗口的话 ,参考:https://blog.csdn.net/wangkai_123456/article/details/71158341

    配置: go build -ldflags "-H windowsgui"              (注意:用这个命令行语句时,可能需要通过环境变量修改gopath)
    lite IDE配置 
         菜单 编译→编译配置 

    在“自定义”页面下的 BUILDAGRS 后添加 -ldflags "-H windowsgui"

    2020年1月2日补充:

    时隔一年,再次编译这个代码时,竟然提示:

    e:goapppkgmodgithub.comgooglegxui@v0.0.0-20151028112939-f85e0a97b3a4driversgldriver.go:191:12: assignment mismatch: 2 variables but c.window.Window.GetClipboardString returns 1 values

    根据提示将 driver.go的第191行,12个字符处的err变量去除。

    重新编译成功!

    另外,参考https://blog.csdn.net/qq_32394351/article/details/93468119用fyne也不错

  • 相关阅读:
    今年暑假不AC
    Java类的生命周期
    Java反射机制
    Java环境变量的配置及使用
    javaIO流(一)
    ftp服务器测试
    linux下svn使用及查看杀掉进程
    网络配置学习
    网络配置指令
    dos攻击与防御
  • 原文地址:https://www.cnblogs.com/pu369/p/10336699.html
Copyright © 2011-2022 走看看