Windows GUI framework for Go.
Go Other
Latest commit 6bb9f0d Aug 30, 2013 @AllenDang Merge pull request #10 from frank418/master
go最新版本错误修正及一些小改动
Permalink
Failed to load latest commit information.
demo Merge branch 'master' of https://github.com/AllenDang/gform Jul 29, 2012
startkit Remove startkit.exe. Apr 8, 2012
AUTHORS Initial commit. Sep 22, 2011
LICENSE Initial commit. Sep 22, 2011
README.md Update demo code for raw message bind. Apr 8, 2012
app.go 修正 Aug 29, 2013
bitmap.go 修正 Aug 29, 2013
brush.go Update "w32" package usage. Apr 16, 2012
buttons.go Update "w32" package usage. Apr 16, 2012
canvas.go 修正 Aug 29, 2013
color.go Refine package structure to be ready to use "go" command to build and… Feb 2, 2012
commondlgs.go 修正 Aug 29, 2013
controlbase.go 修正 Aug 29, 2013
controller.go Add OnSize support Jun 24, 2012
customcontrol.go 修正 Aug 29, 2013
dialog.go 修正 Aug 29, 2013
edit.go 修正 Aug 29, 2013
eventarg.go Refine package structure to be ready to use "go" command to build and… Feb 2, 2012
eventdata.go Add OnSize support Jun 24, 2012
eventmanager.go 1. Event handler is a function pointer now (originally it's a functio… Apr 8, 2012
font.go 修正 Aug 29, 2013
form.go WM_CLOSE 消息处理调整 Aug 30, 2013
globalvars.go Refine package structure to be ready to use "go" command to build and… Feb 2, 2012
icon.go Update "w32" package usage. Apr 16, 2012
imagelist.go Update "w32" package usage. Apr 16, 2012
init.go Update "w32" package usage. Apr 16, 2012
listview.go 修正 Aug 29, 2013
msghandlerregistry.go Refine package structure to be ready to use "go" command to build and… Feb 2, 2012
pen.go Update "w32" package usage. Apr 16, 2012
progressbar.go Update "w32" package usage. Apr 16, 2012
rect.go 修正 Aug 29, 2013
statics.go Refine package structure to be ready to use "go" command to build and… Feb 2, 2012
tooltip.go 修正 Aug 29, 2013
utils.go 修正 Aug 29, 2013
w32control.go 修正 Aug 29, 2013
wndproc.go 修正 Aug 29, 2013

README.md

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!