Closed mightypanda closed 2 years ago
Assuming you're at least on the very first version of Windows 10, you'll first need to check that the capture API itself is available. You can do that with the ApiInformation.IsTypePresent
function. Next you'll want to make sure that screen capture is supported on the device you're on (e.g. the Xbox does not support screen capture via Windows.Graphics.Capture at this time), which you can do with GraphicsCaptureSession.IsSupported
. That'll look something like this:
auto supported =
winrt::Windows::Foundation::Metadata::ApiInformation::IsTypePresent(
L"Windows.Graphics.Capture.GraphicsCaptureSession")
&&
winrt::Windows::Graphics::Capture::GraphicsCaptureSession::IsSupported();
That's the minimum for using the GraphicsCapturePicker
object to select a GraphicsCaptureItem
to capture. However, if you'd like to use the IGraphicsCaptureItemInterop
interface to capture a window or monitor using a HWND
or HMONITOR
respectively, you'll need to either check for the interface on the GraphicsCaptureItem
factory or check for UniversalApiContract v8:
auto isWin32ProgrammaticPresent =
winrt::ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 8);
See issue #50 for more discussion on this topic, as well as how to check for certain features that were introduced later on (e.g. the IsCursorCaptureEnabled
property).
Closing this for now, but feel free to ask more questions!
Hello, What is the correct way to check for availability of the screen-capture API? A check on windows version or expecting an exception? Thank you!