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.

And for the COM bindings:

Package Description
win/com/autom Native Win32 Automation COM interfaces.
win/com/autom/automco Automation constants, all typed.
win/com/autom/automvt Automation virtual tables.
win/com/dshow Native Win32 DirectShow COM interfaces.
win/com/dshow/dshowco DirectShow constants, all typed.
win/com/dshow/dshowvt DirectShow virtual tables.
win/com/idl Native Win32 Object IDL COM interfaces.
win/com/idl/idlco IDL constants, all typed.
win/com/idl/idlvt IDL virtual tables.
win/com/shell Native Win32 Shell COM interfaces.
win/com/shell/shellco Shell constants, all typed.
win/com/shell/shellvt Shell virtual tables.

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.

Comments
  • [Feature] DDE support/bindings

    [Feature] DDE support/bindings

    DDE (dynamic data exchange, DDE docs) is used widely in Windows and it'd be great if there were a way to create (at least) DDE clients and (possibly) DDE servers in Go using windigo.

  • GetTextExtentPoint32 len(lpString) is not calculated correctly

    GetTextExtentPoint32 len(lpString) is not calculated correctly

    https://github.com/rodrigocfd/windigo/blob/0151ff04f45224c76e327b24cb15cc7484514fb7/ui/any_globals.go#L111

    https://github.com/rodrigocfd/windigo/blob/0151ff04f45224c76e327b24cb15cc7484514fb7/win/hdc.go#L250-L259

    https://github.com/rodrigocfd/windigo/blob/0151ff04f45224c76e327b24cb15cc7484514fb7/internal/proc/gdi32.go#L39

    https://docs.microsoft.com/en-us/windows/win32/gdi/specifying-length-of-text-output-string

    Each of these functions has both an "ANSI" version and a Unicode version (for example, DrawTextExA and DrawTextExW, respectively). For the "ANSI" version of each function, the length is specified as a BYTE count and for the Unicode function it is specified as a WORD count.

    It is traditional to think of this as a "character count". That is generally accurate for many languages, including English, but it is not accurate in general. In "ANSI" strings, characters in SBCS code pages take one byte each, but most characters in DBCS code pages take two bytes. Similarly, most currently defined Unicode characters reside in the Basic Multilingual Plane (BMP) and their UTF-16 representations fit in one WORD, but supplementary characters are represented in Unicode by ''surrogates'', which require two WORDs.

  • GetWindowLongPtrW&SetWindowLongPtrW Not found.

    GetWindowLongPtrW&SetWindowLongPtrW Not found.

    Failed to find GetWindowLongPtrW procedure in user32.dll: The specified procedure could not be found. Failed to find SetWindowLongPtrW procedure in user32.dll: The specified procedure could not be found.

  •  VerSetConditionMask 32-bit system parameter error

    VerSetConditionMask 32-bit system parameter error

    Running in 32 programs will crash. Because in 32 programs 'ULONGLONG' is passed with two parameters.

    https://github.com/vito/houdini/blob/d5a6d80a3b87f479919ab5c6bc4badd4de80f57e/win32/win32_windows_amd64.go#L15 https://github.com/vito/houdini/blob/d5a6d80a3b87f479919ab5c6bc4badd4de80f57e/win32/win32_windows_386.go#L24

  • GetWindowThreadProcessId() Can't get process id due to remove second param

    GetWindowThreadProcessId() Can't get process id due to remove second param

    in this function

    func (hWnd HWND) GetWindowThreadProcessId() uint32 {
    	ret, _, _ := syscall.Syscall(proc.GetWindowThreadProcessId.Addr(), 2,
    		uintptr(hWnd), 0, 0)
    	return uint32(ret)
    }
    

    after changed to

    func (hWnd HWND) GetWindowThreadProcessId() (uint32,uint32) {
    	var processId uint32
    	ret, _, _ := syscall.Syscall(proc.GetWindowThreadProcessId.Addr(), 2,
    		uintptr(hWnd), uintptr(unsafe.Pointer(&processId)), 0)
    	return uint32(ret), processId
    }
    

    i got the right processID

A Windows GUI toolkit for the Go Programming Language
A Windows GUI toolkit for the Go Programming Language

About Walk Walk is a "Windows Application Library Kit" for the Go Programming Language. Its primarily useful for Desktop GUI development, but there is

Dec 30, 2022
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 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(ni

Jan 1, 2023
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
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
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
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
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
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
Easy Go GUI wrapper for interactive manipulation of visual algorithms/backend code.
Easy Go GUI wrapper for interactive manipulation of visual algorithms/backend code.

RenderView ================ Install: go get github.com/TheGrum/renderview Needs either Shiny (limited functionality), Gio, go-gtk, or gotk3. The latt

Aug 4, 2022