microsoft / Windows.UI.Composition-Win32-Samples

Windows.UI.Composition Win32 Samples
MIT License
459 stars 186 forks source link

WPF is ok, but UWP has this error #101

Closed lizongying closed 2 years ago

lizongying commented 2 years ago
0
robmikh commented 2 years ago

The most common error from CreateFromWindow is because the window provided is not available to capture. Does this happen with all windows or just some windows? Is there an application that can reliably reproduce this error when captured?

lizongying commented 2 years ago

The most common error from is because the window provided is not available to capture. Does this happen with all windows or just some windows? Is there an application that can reliably reproduce this error when captured?CreateFromWindow

same window

lizongying commented 2 years ago

The most common error from CreateFromWindow is because the window provided is not available to capture. Does this happen with all windows or just some windows? Is there an application that can reliably reproduce this error when captured?

This error is raised for all windows

lizongying commented 2 years ago

GraphicsCapturePicker is no problem

robmikh commented 2 years ago

Ah sorry, I missed an important piece of information from your title. UWP and LowIL callers are blocked from calling CreateFromWindow and CreateFromMonitor, it's a Win32 only API.

To programmatically capture the screen from a UWP app, you'll need to use a different API:

  1. Define the graphicsCaptureProgrammatic capability in your manifest.
  2. Call GraphicsCaptureAccess.RequestAsync with GraphicsCaptureAccessKind.Programmatic.
  3. Call GraphicsCaptureItem.TryCreateFromWindowId.

You can obtain WindowIds from WindowServies.FindAllTopLevelWindowIds. Keep in mind that these APIs were introduced in Windows 11, and will not work on previous versions of Windows.

lizongying commented 2 years ago

GraphicsCapturePicker doesn't seem to support XboxGameBarWidget, and can't find any GraphicsCaptureItem, which can be found on other pages. So I tried to use CreateFromWindow, and if it can be solved, thank you very much!

robmikh commented 2 years ago

Your best bet is using the new API on Windows 11.