Example #1
0
File: icon.go Project: wangch/walk
// create an Alpha Icon or Cursor from an Image
// http://support.microsoft.com/kb/318876
func createAlphaCursorOrIconFromImage(im image.Image, hotspot image.Point, fIcon bool) (win.HICON, error) {
	hBitmap, err := hBitmapFromImage(im)
	if err != nil {
		return 0, err
	}
	defer win.DeleteObject(win.HGDIOBJ(hBitmap))

	// Create an empty mask bitmap.
	hMonoBitmap := win.CreateBitmap(int32(im.Bounds().Dx()), int32(im.Bounds().Dy()), 1, 1, nil)
	if hMonoBitmap == 0 {
		return 0, newError("CreateBitmap failed")
	}
	defer win.DeleteObject(win.HGDIOBJ(hMonoBitmap))

	var ii win.ICONINFO
	if fIcon {
		ii.FIcon = win.TRUE
	}
	ii.XHotspot = uint32(hotspot.X)
	ii.YHotspot = uint32(hotspot.Y)
	ii.HbmMask = hMonoBitmap
	ii.HbmColor = hBitmap

	// Create the alpha cursor with the alpha DIB section.
	hIconOrCursor := win.CreateIconIndirect(&ii)

	return hIconOrCursor, nil
}
Example #2
0
File: pen.go Project: wangch/walk
func (p *nullPen) Dispose() {
	if p.hPen != 0 {
		win.DeleteObject(win.HGDIOBJ(p.hPen))

		p.hPen = 0
	}
}
Example #3
0
File: pen.go Project: wangch/walk
func (p *GeometricPen) Dispose() {
	if p.hPen != 0 {
		win.DeleteObject(win.HGDIOBJ(p.hPen))

		p.hPen = 0
	}
}
Example #4
0
File: brush.go Project: wangch/walk
func (b *nullBrush) Dispose() {
	if b.hBrush != 0 {
		win.DeleteObject(win.HGDIOBJ(b.hBrush))

		b.hBrush = 0
	}
}
Example #5
0
File: brush.go Project: wangch/walk
func (b *SolidColorBrush) Dispose() {
	if b.hBrush != 0 {
		win.DeleteObject(win.HGDIOBJ(b.hBrush))

		b.hBrush = 0
	}
}
Example #6
0
File: font.go Project: wangch/walk
// Dispose releases the os resources that were allocated for the Font.
//
// The Font can no longer be used for drawing operations or with GUI widgets
// after calling this method. It is safe to call Dispose multiple times.
func (f *Font) Dispose() {
	for dpi, hFont := range f.dpi2hFont {
		if dpi != 0 {
			win.DeleteObject(win.HGDIOBJ(hFont))
		}

		delete(f.dpi2hFont, dpi)
	}
}
Example #7
0
func (bmp *Bitmap) Dispose() {
	if bmp.hBmp != 0 {
		win.DeleteObject(win.HGDIOBJ(bmp.hBmp))

		win.GlobalUnlock(bmp.hPackedDIB)
		win.GlobalFree(bmp.hPackedDIB)

		bmp.hPackedDIB = 0
		bmp.hBmp = 0
	}
}