func (cw *CustomWidget) bufferedPaint(canvas *Canvas, updateBounds Rectangle) error { hdc := win.CreateCompatibleDC(canvas.hdc) if hdc == 0 { return newError("CreateCompatibleDC failed") } defer win.DeleteDC(hdc) buffered := Canvas{hdc: hdc, doNotDispose: true} if _, err := buffered.init(); err != nil { return err } w, h := int32(updateBounds.Width), int32(updateBounds.Height) if w < 1 { w = 1 } if h < 1 { h = 1 } hbmp := win.CreateCompatibleBitmap(canvas.hdc, w, h) if hbmp == 0 { return lastError("CreateCompatibleBitmap failed") } defer win.DeleteObject(win.HGDIOBJ(hbmp)) oldbmp := win.SelectObject(buffered.hdc, win.HGDIOBJ(hbmp)) if oldbmp == 0 { return newError("SelectObject failed") } defer win.SelectObject(buffered.hdc, oldbmp) win.SetViewportOrgEx(buffered.hdc, -int32(updateBounds.X), -int32(updateBounds.Y), nil) win.SetBrushOrgEx(buffered.hdc, -int32(updateBounds.X), -int32(updateBounds.Y), nil) err := cw.paint(&buffered, updateBounds) if !win.BitBlt(canvas.hdc, int32(updateBounds.X), int32(updateBounds.Y), w, h, buffered.hdc, int32(updateBounds.X), int32(updateBounds.Y), win.SRCCOPY) { return lastError("buffered BitBlt failed") } return err }
func hBitmapFromWindow(window Window) (win.HBITMAP, error) { hdcMem := win.CreateCompatibleDC(0) if hdcMem == 0 { return 0, newError("CreateCompatibleDC failed") } defer win.DeleteDC(hdcMem) var r win.RECT if !win.GetWindowRect(window.Handle(), &r) { return 0, newError("GetWindowRect failed") } hdc := win.GetDC(window.Handle()) width, height := r.Right-r.Left, r.Bottom-r.Top hBmp := win.CreateCompatibleBitmap(hdc, width, height) win.ReleaseDC(window.Handle(), hdc) hOld := win.SelectObject(hdcMem, win.HGDIOBJ(hBmp)) flags := win.PRF_CHILDREN | win.PRF_CLIENT | win.PRF_ERASEBKGND | win.PRF_NONCLIENT | win.PRF_OWNED window.SendMessage(win.WM_PRINT, uintptr(hdcMem), uintptr(flags)) win.SelectObject(hdcMem, hOld) return hBmp, nil }