• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Windows API and GUI in idiomatic Go.

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:

Package Description
ui High-level UI wrappers for windows and controls.
ui/wm High-level event parameters (Windows message callbacks).

For the Win32 API bindings:

Package Description
win Native Win32 structs, handles and functions.
win/co Native Win32 constants, all typed.
win/errco Native 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:

Packages Description
win/com/autom
win/com/autom/automco
win/com/autom/automvt
Native Win32 Automation COM interfaces.
win/com/com
win/com/com/comco
win/com/com/comvt
Native Win32 COM API base.
win/com/d2d1
win/com/d2d1/d2d1co
win/com/d2d1/d2d1vt
Native Win32 Direct2D COM interfaces.
win/com/dshow
win/com/dshow/dshowco
win/com/dshow/dshowvt
Native Win32 DirectShow COM interfaces.
win/com/shell
win/com/shell/shellco
win/com/shell/shellvt
Native 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:

  • programmatically, by specifying the options used in the underlying CreateWindowEx;
  • by loading resources from a .rc or a .res file.

CGo is not used, just syscalls.

Error treatment

The native Win32 functions deal with errors in two ways:

  • Recoverable errors will return an errco.ERROR value, which implements the error interface;

  • Unrecoverable errors will simply panic. This avoids the excess of if err != nil with errors that cannot be recovered anyway, like internal Windows errors.

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.

More Repositories

1

winsafe

Windows API and GUI in safe, idiomatic Rust.
Rust
442
star
2

winlamb

A lightweight modern C++11 library for Win32 API, using lambdas to handle Windows messages.
C++
320
star
3

winsafe-examples

Examples of native Windows applications written in Rust with WinSafe.
Rust
57
star
4

string-tension-calc

Guitar string tension calculator with graphical plotting.
TypeScript
22
star
5

defer-lite

A lightweight high-performance implementation of Go's defer statement.
Rust
20
star
6

react-require

React with RequireJS: no build step, no Webpack, not even Node.js.
JavaScript
14
star
7

flac-lame-frontend

A native Win32 GUI to work with FLAC and LAME command line tools.
Rust
11
star
8

html5-tree-graph

Pure HTML5 and JavaScript tree graph.
JavaScript
10
star
9

chromium-peeker

A native C++11 Win32 utility to download a list of Chromium builds for Windows.
C++
9
star
10

binary-file-diff

Drag two binary files into the page, and compare them side by side.
JavaScript
8
star
11

click-lines

Simple C++11, Win32, WinLamb example using raw windows and custom controls.
C++
7
star
12

ordenador-cespe

Um script para ordenação dos resultados divulgados pelo Cespe.
5
star
13

format-comment

VSCode extension to format comments to fit a maximum number of chars on each line.
TypeScript
5
star
14

id3-padding-remover

C and Win32 program to remove padding from ID3v2 tags in MP3 files.
C
4
star
15

vscode-font-patch

An utility to patch a Visual Studio Code installation on Windows, slightly enhancing the font rendering, and fixing the autocomplete icon color.
Rust
3
star
16

react-mpa

PoC with React and Webpack for a multi-page application, JavaScript and TypeScript.
JavaScript
1
star