Home

Awesome

Go Reference GitHub go.mod Go version of a Go module Lines of code License: MIT

Windigo

Win32 API and GUI in idiomatic Go.

Overview

The UI library is divided in the following packages:

PackageDescription
uiHigh-level UI wrappers for windows and controls.
ui/wmHigh-level event parameters (Windows message callbacks).

For the Win32 API bindings:

PackageDescription
winNative Win32 structs, handles and functions.
win/coNative Win32 constants, all typed.
win/errcoNative Win32 error codes, with types errco.ERROR and errco.CDERR.

For the COM bindings, there is the main package, and two subpackages – the co suffix contains the constants, and the vt contains the virtual tables:

PackagesDescription
win/com/autom<br>win/com/autom/automco<br>win/com/autom/automvtNative Win32 Automation COM interfaces.
win/com/com<br>win/com/com/comco<br>win/com/com/comvtNative Win32 COM API base.
win/com/d2d1<br>win/com/d2d1/d2d1co<br>win/com/d2d1/d2d1vtNative Win32 Direct2D COM interfaces.
win/com/dshow<br>win/com/dshow/dshowco<br>win/com/dshow/dshowvtNative Win32 DirectShow COM interfaces.
win/com/shell<br>win/com/shell/shellco<br>win/com/shell/shellvtNative Win32 Shell COM interfaces.

Windigo is designed to be familiar to Win32 programmers, using the same concepts, so most C/C++ Win32 tutorials should be applicable.

Windows and controls can be created in two ways:

CGo is not used, just syscalls.

Error treatment

The native Win32 functions deal with errors in two ways:

Example

The example below creates a window programmatically, and handles the button click. Also, it uses the minimal.syso provided in the resources folder.

Screen capture

package main

import (
    "fmt"
    "runtime"

    "github.com/rodrigocfd/windigo/ui"
    "github.com/rodrigocfd/windigo/win"
    "github.com/rodrigocfd/windigo/win/co"
)

func main() {
    runtime.LockOSThread()

    myWindow := NewMyWindow() // instantiate
    myWindow.wnd.RunAsMain()  // ...and run
}

// This struct represents our main window.
type MyWindow struct {
    wnd     ui.WindowMain
    lblName ui.Static
    txtName ui.Edit
    btnShow ui.Button
}

// Creates a new instance of our main window.
func NewMyWindow() *MyWindow {
    wnd := ui.NewWindowMain(
        ui.WindowMainOpts().
            Title("Hello you").
            ClientArea(win.SIZE{Cx: 340, Cy: 80}).
            IconId(101), // ID of icon resource, see resources folder
    )

    me := &MyWindow{
        wnd: wnd,
        lblName: ui.NewStatic(wnd,
            ui.StaticOpts().
                Text("Your name").
                Position(win.POINT{X: 10, Y: 22}),
        ),
        txtName: ui.NewEdit(wnd,
            ui.EditOpts().
                Position(win.POINT{X: 80, Y: 20}).
                Size(win.SIZE{Cx: 150}),
        ),
        btnShow: ui.NewButton(wnd,
            ui.ButtonOpts().
                Text("&Show").
                Position(win.POINT{X: 240, Y: 19}),
        ),
    }

    me.btnShow.On().BnClicked(func() {
        msg := fmt.Sprintf("Hello, %s!", me.txtName.Text())
        me.wnd.Hwnd().MessageBox(msg, "Saying hello", co.MB_ICONINFORMATION)
    })

    return me
}

License

Licensed under MIT license, see LICENSE.md for details.