microsoft / microsoft/WindowsAppSDK

Enable creating GraphicsCaptureItem from HWND by resolving the WindowId namespace mismatch

Open
#6,275 0 comments 2 reactions 2 assignees Claimed by @lauren-ciha View on GitHub
area-AOT feature proposal needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

I am developing a C# application using Windows.Graphics.Capture.
I am facing a friction point when trying to use GraphicsCaptureItem.TryCreateFromWindowId(Windows.UI.WindowId windowId).
While Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd) exists to bridge the Win32 and WinUI worlds,
it returns a Microsoft.UI.WindowId struct. However, the Capture API expects a Windows.UI.WindowId struct.
Although these two structs share the same memory layout (a single ulong Value),
they reside in different namespaces and lack a built-in conversion or shared interface.
This forces developers to perform manual bitwise copying or "fake" casts,
which feels like an unsupported hack rather than a first-class developer experience.

To improve the interoperability between Win32 and Windows.Graphics.Capture,
I request one of the following:

1.Direct HWND Support:
Add GraphicsCaptureItem.TryCreateFromHwnd(IntPtr hwnd) to bypass the WindowId confusion entirely.

2.Official Conversion Utility:
Provide a standard method such as WindowId.FromHwnd(IntPtr hwnd) that returns the correct WindowId type for the target API,
or a bridge between Microsoft.UI.WindowId and Windows.UI.WindowId.

3.Documentation Clarity:
If WindowId.Value is guaranteed to be the same as an HWND handle,
please explicitly state this in the official documentation so developers can perform the cast safely.

The current lack of a clear, unified path for HWND-based capture is a significant hurdle for modernizing Windows apps.
I hope to see a more streamlined Interop experience in future updates.

Thank you for your consideration.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.