I need to capture the screen of a windows given its HWND
handle and store the capture in a ID2D1Bitmap
object in order to draw this bitmap by means of my render target.
How can I achive this result?
I need to capture the screen of a windows given its HWND
handle and store the capture in a ID2D1Bitmap
object in order to draw this bitmap by means of my render target.
How can I achive this result?
Direct2D doesn't provide such functionality.
A possible way to go is if you first capture the screen via GDI
(1) and then create a ID2D1Bitmap
from the returned bitmap handle (2).
Getting a HBITMAP
- Check this answer: https://stackoverflow.com/a/5164267/3962893. You need the part till the HBITMAP hbDesktop = CreateCompatibleBitmap( hdc, width, height);
The hbDesktop
variable will contain a handle to the screen captured bitmap.
Creating an ID2D1Bitmap
from a HBITMAP
- check this answer: https://stackoverflow.com/a/27500938/3962893. It copies an icon to a ID2D1Bitmap
, but the workflow is identical. Except:
hIcon := SendMessage(Handle, WM_GETICON, ICON_BIG, 0);
....
wicFactory.CreateBitmapFromHICON(hIcon, wicBitmap);
that you have to change to:
wicFactory.CreateBitmapFromHBITMAP(hbDesktop, wicBitmap);