Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can only capture the desktop by the function GetFrontBufferData()
Is there any way to capture a window?
Posted

1 solution

No, there is no general solution to this via DirectX.

The reason for this is that the Window you're trying to capture may have no existance in DirectX at all. If it belongs to an application that doesn't use DirectX then from the DirectX point of view there is nothing special about that area of the screen you see as a window you want to capture, from the point of view of DirectX it's just some pixels in a larger area of pixels without any boundary or associated object.

Here are some ideas for potential work arounds:

You're better off going via the OS window manager at least to work out initially which pixels are part of the capture area and which aren't. Unfortunately there's no one simple general solution to this either. On WinXP you can use Win32 API, on Vista it's likely broken/missing but should be avalable through Desktop Window Manager as it is on Windows7. On Windows 8 apparently DWM is gone but I can't confirm.

An approach that might use DirectX or OpenCV is to get the area of the screen buffer you're interested in from the Graphics hardware. However you're still going to need probably Win32 APIs like GetWindowPos to work out what to capture.

It might in the end be easier to capture the whole screen and then duplicate only the part you're interested in and throw the original capture away. Inefficient but possibly easier than trying to get the system to do it for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900