Beispiel #1
0
// MustRegisterWindowClass registers the specified window class.
//
// MustRegisterWindowClass must be called once for every window type that is not
// based on any system provided control, before calling InitChildWidget or
// InitWidget. Calling MustRegisterWindowClass twice with the same className
// results in a panic.
func MustRegisterWindowClass(className string) {
	if registeredWindowClasses[className] {
		panic("window class already registered")
	}

	hInst := win.GetModuleHandle(nil)
	if hInst == 0 {
		panic("GetModuleHandle")
	}

	hIcon := win.LoadIcon(0, (*uint16)(unsafe.Pointer(uintptr(win.IDI_APPLICATION))))
	if hIcon == 0 {
		panic("LoadIcon")
	}

	hCursor := win.LoadCursor(0, (*uint16)(unsafe.Pointer(uintptr(win.IDC_ARROW))))
	if hCursor == 0 {
		panic("LoadCursor")
	}

	var wc win.WNDCLASSEX
	wc.CbSize = uint32(unsafe.Sizeof(wc))
	wc.LpfnWndProc = defaultWndProcPtr
	wc.HInstance = hInst
	wc.HIcon = hIcon
	wc.HCursor = hCursor
	wc.HbrBackground = win.COLOR_BTNFACE + 1
	wc.LpszClassName = syscall.StringToUTF16Ptr(className)

	if atom := win.RegisterClassEx(&wc); atom == 0 {
		panic("RegisterClassEx")
	}

	registeredWindowClasses[className] = true
}
Beispiel #2
0
// NewIconFromResource returns a new Icon, using the specified icon resource.
func NewIconFromResource(resName string) (ic *Icon, err error) {
	var lpIconName *uint16
	hInst := win.GetModuleHandle(nil)
	if hInst == 0 {
		err = lastError("GetModuleHandle")
		return
	}
	if id, atoierr := strconv.Atoi(resName); atoierr == nil {
		lpIconName = (*uint16)(unsafe.Pointer(uintptr(id)))
	} else {
		lpIconName = syscall.StringToUTF16Ptr(resName)
	}
	if hIcon := win.LoadIcon(hInst, lpIconName); hIcon == 0 {
		err = lastError("LoadIcon")
	} else {
		ic = &Icon{hIcon: hIcon}
	}
	return
}
Beispiel #3
0
func NewBitmapFromResource(resName string) (b *Bitmap, err error) {
	var lpBitMapName *uint16
	hInst := win.GetModuleHandle(nil)
	if hInst == 0 {
		err = lastError("GetModuleHandle")
		return
	}
	if id, atoierr := strconv.Atoi(resName); atoierr == nil {
		lpBitMapName = (*uint16)(unsafe.Pointer(uintptr(id)))
	} else {
		lpBitMapName = syscall.StringToUTF16Ptr(resName)
	}
	if hBitMap := win.LoadBitmap(hInst, lpBitMapName); hBitMap == 0 {
		err = lastError("LoadBitmap")
	} else {
		b = &Bitmap{hBmp: hBitMap}
	}
	return
}