2

I have a windows form Window that is being painted on top of by another process. If I try to copy the window image using PrintWindow or device context copy, only my window below shows up:

Window before it's painted on by another process:

enter image description here

Window after it's painted:

enter code here

Window I get when I do PrintWindow or BitBlt:

enter image description here

Is it possible to read the window draw from the window directly without sending it the paint argument? Can I read it from the graphics card directly?

Jason
  • 13,563
  • 15
  • 74
  • 125

3 Answers3

4

DirectX breaks the rules, you cannot make PrintWindow() work. Using Graphics.CopyFromScreen() doesn't work either, it has a critical bug that prevents you from passing the correct CopyPixelOperation value. One that was addressed in Windows 8 by Windows itself, you can't rely on it yet.

You'll need to fallback to BitBlt(). The critical option is CopyPixelOperation.CaptureBlt so that video overlays are included in the copy. You'll find the required code in this answer.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

If I am correct you want to copy window that is rendered by some DirectX proccess?

You can do that but you need to understand that you can't copy memory from window directly because winows form doesn't have your image, it only have a placeholder for rendered image. It is only a ilusion that image is rendered inside form. What you need to do is to copy memory from graphic card but unfortunately I don't know how to do that.

Most simple idea is to get window screenshot like alt+print screen, remove the border and copy that image to your window.

Maybe it will help http://www.codeproject.com/Articles/274461/Very-fast-screen-capture-using-DirectX-in-Csharp

Logman
  • 4,031
  • 1
  • 23
  • 35
0

Dmitry is right.
You can only make a CopyFromScreen as he suggested:
Capture the Screen into a Bitmap
You can modify the source code to create a bitmap large as your window and copy only that part of screen

Community
  • 1
  • 1