Skip to content

Enable creating GraphicsCaptureItem from HWND by resolving the WindowId namespace mismatch #6275

@radian-jp

Description

@radian-jp

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions