MCPcopy Index your code
hub / github.com/lxn/walk / hBitmapFromWindow

Function hBitmapFromWindow

bitmap.go:570–594  ·  view source on GitHub ↗
(window Window)

Source from the content-addressed store, hash-verified

568}
569
570func hBitmapFromWindow(window Window) (win.HBITMAP, error) {
571 hdcMem := win.CreateCompatibleDC(0)
572 if hdcMem == 0 {
573 return 0, newError("CreateCompatibleDC failed")
574 }
575 defer win.DeleteDC(hdcMem)
576
577 var r win.RECT
578 if !win.GetWindowRect(window.Handle(), &r) {
579 return 0, newError("GetWindowRect failed")
580 }
581
582 hdc := win.GetDC(window.Handle())
583 width, height := r.Right-r.Left, r.Bottom-r.Top
584 hBmp := win.CreateCompatibleBitmap(hdc, width, height)
585 win.ReleaseDC(window.Handle(), hdc)
586
587 hOld := win.SelectObject(hdcMem, win.HGDIOBJ(hBmp))
588 flags := win.PRF_CHILDREN | win.PRF_CLIENT | win.PRF_ERASEBKGND | win.PRF_NONCLIENT | win.PRF_OWNED
589 window.SendMessage(win.WM_PRINT, uintptr(hdcMem), uintptr(flags))
590
591 win.SelectObject(hdcMem, hOld)
592
593 return hBmp, nil
594}
595
596// hBitmapFromIcon creates a new win.HBITMAP with given size in native pixels and DPI, and paints
597// the icon on it stretched.

Callers 1

NewBitmapFromWindowFunction · 0.85

Calls 3

newErrorFunction · 0.85
HandleMethod · 0.65
SendMessageMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…