Enable GraphicsCaptureItem creation from Microsoft.UI.WindowId/DisplayId#6280
Draft
Enable GraphicsCaptureItem creation from Microsoft.UI.WindowId/DisplayId#6280
Conversation
Adds a new static runtimeclass GraphicsCaptureItem in the Microsoft.Windows.Graphics.Capture namespace with: - TryCreateFromWindowId(Microsoft.UI.WindowId) - creates a GraphicsCaptureItem from a WinAppSDK WindowId - TryCreateFromDisplayId(Microsoft.UI.DisplayId) - creates a GraphicsCaptureItem from a WinAppSDK DisplayId This resolves the namespace mismatch between Microsoft.UI.WindowId (returned by Win32Interop.GetWindowIdFromWindow) and Windows.UI.WindowId (expected by GraphicsCaptureItem.TryCreateFromWindowId) by using IGraphicsCaptureItemInterop COM interface directly. Co-authored-by: lauren-ciha <64796985+lauren-ciha@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Enable creating GraphicsCaptureItem from HWND by resolving WindowId mismatch
Enable GraphicsCaptureItem creation from Microsoft.UI.WindowId/DisplayId
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd)returnsMicrosoft.UI.WindowId, butWindows.Graphics.Capture.GraphicsCaptureItem.TryCreateFromWindowIdexpectsWindows.UI.WindowId. Despite identical memory layout, the namespace gap forces developers into unsafe manual reinterpret hacks.Changes
New API:
Microsoft.Windows.Graphics.Capture.GraphicsCaptureItemStatic runtimeclass with two factory methods that use
IGraphicsCaptureItemInteropCOM interface directly, bypassing theWindows.UI.WindowIdrequirement entirely:TryCreateFromWindowId(Microsoft.UI.WindowId)— extracts HWND fromWindowId.Value, callsIGraphicsCaptureItemInterop::CreateForWindowTryCreateFromDisplayId(Microsoft.UI.DisplayId)— callsIGraphicsCaptureItemInterop::CreateForMonitor; covers the display capture interop gap symmetricallyTryCreate*convention: returnnullon invalid handle or non-capturable target; propagate unexpected COM activation failures as exceptions per WinRT boundary policyNew files
dev/Interop/GraphicsCapture/Microsoft.Windows.Graphics.Capture.idldev/Interop/GraphicsCapture/GraphicsCaptureItem.{h,cpp}dev/Interop/GraphicsCapture/GraphicsCapture.vcxitemsdev/Projections/CS/Microsoft.Windows.Graphics.Capture.Projection/test/GraphicsCaptureTests/— API tests for null-WindowId and null-DisplayId guard conditionsModified files
dev/WindowsAppRuntime_DLL/WindowsAppRuntime_DLL.vcxproj— import new vcxitemsdev/WindowsAppRuntime_DLL/pch.h— addwinrt/Windows.Graphics.Capture.hbuild/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props— registerMicrosoft.Windows.Graphics.Capture.winmdWindowsAppRuntime.sln— wire up all new projectsA microsoft employee must use /azp run to validate using the pipelines below.
WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.
For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.