Windows GUI framework for Go.

gform is an easy to use Windows GUI toolkit for Go

It provides two approaches to create UI.

1. Pure code.

gform.Init()

mainWindow := gform.NewForm(nil)
mainWindow.SetPos(300, 100)
mainWindow.SetSize(500, 300)
mainWindow.SetCaption("Controls Demo")

btn := gform.NewPushButton(mainWindow)
btn.SetPos(10, 10)
btn.OnLBUp().Bind(btn_onclick)

mainWindow.Show()

gform.RunMainLoop()

2. Create dialog in resource file and attach to it.

gform.Init()

dialog := gform.NewDialogFromResId(nil, 101) //101 is the resource Id.
dialog.Center()
dialog.Show()

edt = gform.AttachEdit(dialog, 1000)
edt.SetCaption("Hello")

btn := gform.AttachPushButton(dialog, 2)
btn.OnLBDown().Attach(onclick)

gform.RunMainLoop()

Event handling

gform provides two approaches to handle event. For most commonly used events, convenient event handler is introduced. To handle windows message directly, "Bind" mechanism is introduce.

1. Convenient event handler.

These kind of event handler follows the same naming convention, "OnSomething".

btn.OnLBUp().Bind(btn_onclick) //LB means Left Button.
btn.OnMBUp //MB means middle button
btn.OnKillFocus
btn.OnDropFiles
...

If you bind two methods for one event, the first bind will be overwritten by later bind. E.g.

btn.OnLBUp().Bind(btn_onclick1)
btn.OnLBUp().Bind(btn_onclick2)

Only "btn_onclick2" will be triggered.

You can also bind "nil" to a event handler, that simply means nothing will be triggered.

2. Raw windows message handler.

It's a common case that we need to handler various windows messages in GUI, and to wrap them all is basically "mission impossible" (and I don't think a GUI framework should do that frankly), so gform leaves the freedom to user. The "Bind" method could bind an event handler directly to a raw windows message. E.g.

btn.Bind(w32.WM_CLIPBOARDUPDATE, btn_onClipboardUpdate)

func btn_onClipboardUpdate(arg *EventArg) {
    sender := arg.Sender()
    if data, ok := arg.Data().(*gform.RawMsg); ok {
        println(data.Hwnd, data.Msg, data.WParam, data.LParam)
    }
}

The event handler uses the same method signature "func(arg *EventArg)", but a new struct named "RawMsg" will be filled to the "data" field of EventArg.

type RawMsg struct {
    Hwnd           w32.HWND
    Msg            uint
    WParam, LParam uintptr
} 

The same with convenient event handler, if you bind two methods for one event, the first bind will be overwritten by later bind. And bind "nil" to a message is allowed.

Setup

  1. Make sure you have a working Go installation and build environment, see more for details from below page. http://golang.org/doc/install

  2. go get github.com/AllenDang/gform

  3. go install github.com/AllenDang/gform

Have fun now!

Recommand Tools

  1. ResEdit - very good tool to edit resource file, strongly recommand! http://www.resedit.net/

  2. windres - tools to compile *.rc file to *.o which makes it is possible to embed resource file into *.exe.

Contribute

Contributions in form of design, code, documentation, bug reporting or other ways you see fit are very welcome.

Thank You!

Comments
  • Demo canvas import

    Demo canvas import

    demo\canvas>go build testcanvas.go

    testcanvas.go:4:2: import "gform": cannot find package testcanvas.go:6:2: import "w32": cannot find package

    File testcanvas.go

    import ( "gform" "syscall" "w32" )

    Change to

    import ( "syscall" "github.com/AllenDang/gform" "github.com/AllenDang/w32" )

  • [Closed] Cannot build with gform

    [Closed] Cannot build with gform

    When I try to build any Go program which contains gform.Init(), it crashes with the following message:

    runtime.callbackasm1: nosplit stack overflow
        120     assumed on entry to runtime.callbackasm1
        104     after runtime.callbackasm1 uses 16
        96      on entry to runtime.cgocallback_gofunc
        88      after runtime.cgocallback_gofunc uses 8
        80      on entry to runtime.cgocallbackg
        48      after runtime.cgocallbackg uses 32
        40      on entry to runtime.exitsyscall
        32      after runtime.exitsyscall uses 8
        24      on entry to exitsyscallfast
        0       after exitsyscallfast uses 24
        -8      on entry to runtime.lock
    runtime.callbackasm: nosplit stack overflow
        120     assumed on entry to runtime.callbackasm
        112     on entry to runtime.callbackasm1
        96      after runtime.callbackasm1 uses 16
        88      on entry to runtime.cgocallback_gofunc
        80      after runtime.cgocallback_gofunc uses 8
        72      on entry to runtime.cgocallbackg
        40      after runtime.cgocallbackg uses 32
        32      on entry to runtime.exitsyscall
        24      after runtime.exitsyscall uses 8
        16      on entry to exitsyscallfast
        -8      after exitsyscallfast uses 24
    

    Go version: go1.3.2 windows/amd64 Windows version: Windows 8.1 (64 bit)

  • go build dialog.go bug line 32

    go build dialog.go bug line 32

    go build dialog.go

    command-line-arguments

    .\dialog.go:32: lv.InsertItem undefined (type *gform.ListView has no field or method InsertItem)

    Windows 7 SP1 amd64

    commit 1abee3a69849ea573d871da734b04a21e372d236

  • In during install appear error

    In during install appear error

    $ cd gform/src && gomake make -C pkg/gform clean make[1]: Entering directory /d/projects/GO/src/gform/src/pkg/gform' rm -rf *.o *.a *.[568vq] [568vq].out *.so _obj _test _testmain.go *.exe _cgo* te st.out build.out make[1]: Leaving directory/d/projects/GO/src/gform/src/pkg/gform' make -C pkg/gform install make[1]: Entering directory /d/projects/GO/src/gform/src/pkg/gform' 8g -p gform -o _go_.8 init.go rect.go color.go font.go imagelist.go globalvars .go util.go pen.go brush.go canvas.go icon.go msghandlerregistry.go controller.g o eventhandler.go eventarg.go eventmanager.go controlbase.go wndproc.go w32contr ol.go dialog.go form.go customcontrol.go buttons.go statics.go edit.go progressb ar.go commondlgs.go listview.go tooltip.go app.go brush.go:14: undefined: w32.BS_SOLID canvas.go:61: undefined: user32.FillRect make[1]: *** [_go_.8] Error 1 make[1]: Leaving directory/d/projects/GO/src/gform/src/pkg/gform' make: *** [all] Error 2

    w32 installed good

  • Failed to find SetWindowLongPtrW procedure in user32.dll on Windows XP

    Failed to find SetWindowLongPtrW procedure in user32.dll on Windows XP

    Windows XP go version go1.1.2 windows/386

    D:\gform>go run test-gform.go
    panic: Failed to find SetWindowLongPtrW procedure in user32.dll: The specified procedure could not be found.
    
    goroutine 1 [running]:
    syscall.(*LazyProc).mustFind(0x10e41e80)
            C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist465310315/go/src/pkg/syscall/dll_windows.go:258 +0x52
    syscall.(*LazyProc).Call(0x10e41e80, 0x30e51748, 0x3, 0x3, 0x10e41d80, ...)
            C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist465310315/go/src/pkg/syscall/dll_windows.go:277 +0x38
    github.com/AllenDang/w32.SetWindowLongPtr(0x1603de, 0xfffffffc, 0x10e42728, 0x10e43060)
            C:/Go/src/pkg/github.com/AllenDang/w32/user32.go:353 +0x81
    github.com/AllenDang/gform.(*W32Control).init(0x10e430c0, 0x4a3558, 0x6, 0x10e44000, 0x10e43060, ...)
            d:/gform/GOPATH/src/github.com/AllenDang/gform/w32control.go:20 +0xda
    github.com/AllenDang/gform.(*PushButton).init(0x10e430c0, 0x10e44000, 0x10e43060)
            d:/gform/GOPATH/src/github.com/AllenDang/gform/buttons.go:48 +0x55
    github.com/AllenDang/gform.NewPushButton(0x10e44000, 0x10e43060, 0xd)
            d:/gform/GOPATH/src/github.com/AllenDang/gform/buttons.go:30 +0x48
    main.main()
            D:/gform/test-gform.go:15 +0x9b
    exit status 2
    

    test-gform.go

    package main
    
    import (
        "github.com/AllenDang/gform"
    )
    
    func main() {
        gform.Init()
    
        mainWindow := gform.NewForm(nil)
        mainWindow.SetPos(300, 100)
        mainWindow.SetSize(500, 300)
        mainWindow.SetCaption("Controls Demo")
    
        btn := gform.NewPushButton(mainWindow)
        btn.SetPos(10, 10)
    
        mainWindow.Show()
    
        gform.RunMainLoop()
    }
    
  • Can't install : Error msg says cannot use flag (type uint32).

    Can't install : Error msg says cannot use flag (type uint32).

    Hi, I tried to install this as you stated in this page.But i got this error message. " C:\Users\UserName>go get github.com/AllenDang/gform

    github.com/AllenDang/w32

    go\src\github.com\AllenDang\w32\user32.go:1039:10: cannot use flag (type uint32) as type uintptr in argument to procRedrawWindow.Call " What to do ?

  • Recommand Tools an Virus Alert: Trotux.

    Recommand Tools an Virus Alert: Trotux.

    Hello Allen,

    I tried play with your repository but when i install resedi tools that you higly recommend it. My system infected by Trotux virus.

    I think you could suggest a clean link for your repo.

    With my best

    Ugur

  • Error on installation C:\\MinGW\mingw-get.exe: unrecognised option `-E`

    Error on installation C:\\MinGW\mingw-get.exe: unrecognised option `-E`

    windows 8 I'am install mingw and mingw-w64-install.exe If i run "go get github.com/AllenDang/gform" display error "cc1.exe: sorry, unimplemented: 64-bit mode not compiled in", then i run mingw-w64.bat and run "go get github.com/AllenDang/gform" - display error "C:\MinGW\mingw-get.exe: unrecognised option -E" Whats wrong?

  • to many func not found when i run the demo

    to many func not found when i run the demo

    my code like this:

    package main

    import ( "github.com/AllenDang/gform" )

    func main() { gform.Init()

    mainWindow := gform.NewForm(nil)
    mainWindow.SetPos(300, 100)
    mainWindow.SetSize(500, 300)
    mainWindow.SetCaption("Controls Demo")
    
    btn := gform.NewPushButton(mainWindow)
    btn.SetPos(10, 10)
    btn.OnLBUp().Bind(btn_onclick)
    
    mainWindow.Show()
    
    gform.RunMainLoop()
    }
    

    when i run it ,it print

    error

    but when i check the program,it has that functions.

  • Button

    Button "Close window" doesn't work. Is it bug or feature?

    When I click on button "Close window" or press <Alt+F4>, window doesn't close. Must I write my own onClose-handler?

    func formOnClose(arg *gform.EventArg) {
            var sender = arg.Sender()
            w32.DestroyWindow(sender.Handler())
    }
    
    func main() {
            ... 
            mainWindow.Bind(w32.WM_CLOSE, formOnClose)
            ...
    }
    

    Or is there default handler?

Common library for Go GUI apps on Windows
Common library for Go GUI apps on Windows

winc Common library for Go GUI apps on Windows. It is for Windows OS only. This makes library smaller than some other UI libraries for Go.

Dec 12, 2022
Windows GUI library for Go (Golang). Comes with a graphical UI designer.

Version 2 Please go to Version 2 of this library for the latest version. Windows GUI Library This is a pure Go library to create native Windows GUIs.

Jan 1, 2023
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.

XCGUI 项目文档 帮助文档 程序示例 介绍 English | 简体中文 DirectUI设计思想: 在窗口内没有子窗口,界面元素都是逻辑上的区域(无HWND句柄,安全,灵活), 所有UI元素都是自主开发(不受系统限制), 更加灵活的实现各种程序界面,满足不同用户的需求.

Dec 22, 2022
Windows API and GUI in idiomatic Go.
Windows API and GUI in idiomatic Go.

Windigo Win32 API and GUI in idiomatic Go. Overview The UI library is divided in the following packages: Package Description ui High-level UI wrappers

Dec 27, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functional build process. This repository is intended as a quick reference to help others start similar projects using the referenced libraries and will not be actively maintained.

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
W32find - Find parent windows and their children windows using win32api.

w32find Package w32find provides a set of interface to win32 APIs that can be used to find windows and their controls. Install go get -v github.com/mo

Jan 5, 2022
Cross platform rapid GUI framework for golang based on Dear ImGui.
Cross platform rapid GUI framework for golang based on Dear ImGui.

giu Cross platform rapid GUI framework for golang based on Dear ImGui and the great golang binding imgui-go. Any contribution (features, widgets, tuto

Dec 28, 2022
Cross-Platform GUI Framework for Go

⚠️ I'm currently working on this project as part of my master's thesis at the Berlin University of Applied Sciences and Technology. It is under active

Oct 31, 2022
Cross platform GUI in Go based on Material Design
Cross platform GUI in Go based on Material Design

About Fyne is an easy to use UI toolkit and app API written in Go. It is designed to build applications that run on desktop and mobile devices with a

Jan 3, 2023
Go wrapper around the Iup GUI toolset

Iup Go Wrapper iup is a Go wrapper around the Iup GUI toolkit. The project was started on April 27, 2011. Fork https://github.com/grd/iup is a fork of

Nov 28, 2020
Platform-native GUI library for Go.

ui: platform-native GUI library for Go This is a library that aims to provide simple GUI software development in Go. It is based on my libui, a simple

Jan 9, 2023
Go Wrapper for the wxWidgets GUI

This is the source code for wxGo a Go wrapper of the wxWidgets library. The actuall wxWidgets source code is not included and will need to be downloa

Nov 30, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electr

Jan 9, 2023
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)

gowd Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) How to use this library: Download and install nwjs Install this library g

Dec 11, 2022
RobotGo, Go Native cross-platform GUI automation @vcaesar

Robotgo Golang Desktop Automation. Control the mouse, keyboard, bitmap, read the screen, Window Handle and global event listener. RobotGo supports Mac

Jan 7, 2023
Cross-platform GUI for go is never this easy and clean.
Cross-platform GUI for go is never this easy and clean.

gimu Strongly suggest NOT to use this project anymore, the auto-generated cgo wrapper of Nuklear has a random crash issue which is hard to fix (becaus

Jul 12, 2022