3

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?

Nick
  • 10,309
  • 21
  • 97
  • 201
  • Note also, http://www.codeproject.com/Questions/115460/Direct-D-Capturing-a-dialog-background-in-a-bitmap – 9dan Mar 03 '15 at 02:11

1 Answers1

5

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).

  1. 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.

  2. 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);

Community
  • 1
  • 1
Peter Kostov
  • 941
  • 1
  • 6
  • 15