Ejemplo n.º 1
0
func NewBitmapFromResource(instance w32.HINSTANCE, resName *uint16, resType *uint16, background Color) (*Bitmap, error) {
	var gpBitmap *uintptr
	var err error
	var hRes w32.HRSRC

	hRes, err = w32.FindResource(w32.HMODULE(instance), resName, resType)
	if err != nil {
		return nil, err
	}
	resSize := w32.SizeofResource(w32.HMODULE(instance), hRes)
	pResData := w32.LockResource(w32.LoadResource(w32.HMODULE(instance), hRes))
	resBuffer := w32.GlobalAlloc(w32.GMEM_MOVEABLE, resSize)
	pResBuffer := w32.GlobalLock(resBuffer)
	w32.MoveMemory(pResBuffer, pResData, resSize)

	stream := w32.CreateStreamOnHGlobal(resBuffer, false)

	gpBitmap, err = w32.GdipCreateBitmapFromStream(stream)
	if err != nil {
		return nil, err
	}
	defer stream.Release()
	defer w32.GlobalUnlock(resBuffer)
	defer w32.GlobalFree(resBuffer)
	defer w32.GdipDisposeImage(gpBitmap)

	var hbitmap w32.HBITMAP
	// Reverse gform.RGB to BGR to satisfy gdiplus color schema.
	hbitmap, err = w32.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R())))
	if err != nil {
		return nil, err
	}

	return assembleBitmapFromHBITMAP(hbitmap)
}
Ejemplo n.º 2
0
func SetClipboardText(text string) {
	if !w32.OpenClipboard(w32.HWND(0)) {
		return
	}
	defer w32.CloseClipboard()

	w32.EmptyClipboard()

	tuftlen := uint32(len(text)*2 + 1)
	cptrglob := w32.GlobalAlloc(w32.GMEM_MOVEABLE, tuftlen)

	cptr := unsafe.Pointer(w32.GlobalLock(cptrglob))
	tptr := unsafe.Pointer(syscall.StringToUTF16Ptr(text))
	w32.MoveMemory(cptr, tptr, tuftlen)
	w32.GlobalUnlock(cptrglob)

	w32.SetClipboardData(w32.CF_UNICODETEXT, w32.HANDLE(cptrglob))
}