コード例 #1
0
// Change the window's icon
func (wi *windowInternal) setIcon(icon image.Image) error {
	// First destroy the previous one
	if wi.icon != nil {
		C.DestroyIcon(wi.icon)
	}

	type BGRA [4]uint8

	// Windows wants BGRA pixels: swap red and blue channels
	Rect := icon.Bounds()
	iconPixels := make([]BGRA, Rect.Dy()*Rect.Dx())
	for i, y := 0, 0; y < Rect.Dy(); y++ {
		for x := 0; x < Rect.Dx(); x++ {
			r, g, b, a := icon.At(x, y).RGBA()
			iconPixels[i][0] = uint8(b)
			iconPixels[i][1] = uint8(g)
			iconPixels[i][2] = uint8(r)
			iconPixels[i][3] = uint8(a)
		}
	}

	// Create the icon from the pixel array
	width, height := C.int(Rect.Dx()), C.int(Rect.Dy())
	wi.icon = C.CreateIcon(C.GetModuleHandle(nil), width, height, 1, 32, nil, (*C.BYTE)(&iconPixels[0][0]))

	if wi.icon == nil {
		return fmt.Errorf("could not create icon (%d)", C.GetLastError())
	}

	C.SendMessage(wi.window.Handle, C.WM_SETICON, C.ICON_BIG, C.LPARAM(uintptr(unsafe.Pointer(wi.icon))))
	C.SendMessage(wi.window.Handle, C.WM_SETICON, C.ICON_SMALL, C.LPARAM(uintptr(unsafe.Pointer(wi.icon))))

	return nil
}
コード例 #2
0
ファイル: win32.go プロジェクト: sixteng/goGLPro
func (window *Win32Window) Create(width uint, height uint, title string) bool {

	hInstance := C.GetModuleHandle(nil)

	if hInstance == nil {
		fmt.Println("Error")
		return false
	}

	res := C.RegisterWindow(C.CString("WindowClass"), hInstance, (C.WNDPROC)(unsafe.Pointer(syscall.NewCallback(func(hwnd C.HWND, message C.UINT, wParam C.WPARAM, lparam C.LPARAM) C.LRESULT {
		return window.WndProc(hwnd, message, wParam, lparam)
	}))))

	if res == 0 {
		fmt.Println("ERRRROR")
	}

	hwnd := C.CreateWindowTest(C.CString("WindowClass"), C.CString(title), (C.UINT)(width), (C.UINT)(height), hInstance)

	window.width = width
	window.height = height
	window.hInstance = hInstance
	window.hwnd = hwnd

	C.ShowWindow(hwnd, C.SW_SHOW)

	return true
}
コード例 #3
0
func createHiddenWindow(width, height int) C.HWND {
	window := C.CreateWindowExW(0, contextInternal_className, contextInternal_wTitle, C.WS_POPUP|C.WS_DISABLED, 0, 0, C.int(width), C.int(height), nil, nil, C.GetModuleHandle(nil), nil)
	if window == nil {
		return nil
	}

	C.ShowWindow(window, C.SW_HIDE)
	return window
}
コード例 #4
0
// #include "helper_windows.h"
//
// extern LRESULT CALLBACK (*pGlobalOnEvent)(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
import "C"
import (
	"fmt"
	"image"
	"unsafe"
)

var className, classNameLength = utf16Convert("go-glml/window.Window")
var windowClass = C.WNDCLASSW{
	lpfnWndProc:   C.pGlobalOnEvent,
	style:         C.CS_OWNDC | C.CS_HREDRAW | C.CS_VREDRAW,
	hInstance:     C.HINSTANCE(C.GetModuleHandle(nil)),
	lpszClassName: className,
}

func init() {
	C.RegisterClassW(&windowClass)
}

type WindowHandle struct {
	Handle C.HWND
}

func (wh WindowHandle) IsValid() bool {
	return wh.Handle != nil
}