Click here to Skip to main content
13,044,543 members (61,358 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I can only capture the desktop by the function GetFrontBufferData()
Is there any way to capture a window?
Posted 28-Mar-13 22:35pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100