WinUI 3: Any way to retrieve winrt::Microsoft.UI.Xaml::Window from HWND, WindowId or AppWindow?

世杰 倪 40 Reputation points
2023-05-10T07:02:27.7366667+00:00

I created a window through CreateWindowEx in a WinUI 3 application, so I didn't have a Window object at first.

Using the window handle, I'm able to get WindowId and thus AppWindow. However, I couldn't find any document on how to get Window other than declare it directly. https://github.com/ACGNnsj/WinUI3CppWinRTDemo/blob/3477dedd9404e15689278aa9c2eab734fae20316/OCR/MainWindow.xaml.cpp#LL88C3-L88C8

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
727 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,501 Reputation points Microsoft Vendor
    2023-05-10T08:57:20.8966667+00:00

    There is no existed winrt::Microsoft.UI.Xaml::Window which associates with the native window in your sample.

    Also, there is no APIs to get the associated winrt::Microsoft::UI::Xaml::Window from the native window or WindowId as I said in the question.

    I have submitted a feature request about this. You can also submit an issue at WindowsAPPSDK GitHub Issues.

    0 comments No comments

0 additional answers

Sort by: Most helpful