Harshith
Harshith

Reputation: 321

WinUI3 : How to get the WinUI3 window back from its respective HWND

I'm working on the WinUI3 desktop application. I'm trying to set an ID to the winui3 window and get the WinUI3 window back with only the ID. I could not find any direct way to do this.

I tried to extract HWND from the WinUI3 window and set the ID using SetProp.

uWindow.try_as<::IWindowNative>()->get_WindowHandle(&hWnd);

SetProp(hWnd,"ID","WindowID")

But it doesn't fit well as per my requirements. I want to get the WinUI3 Window back when I have only the ID, I was able to get the HWND of the window back from the ID which I set as the property for HWND, but I was not able to get back the WinUI3 Window from that HWND.

It would be of great help if you could help me get the WinUI3 window back from HWND of its native window.

Thank you

Upvotes: 0

Views: 1148

Answers (1)

Jeaninez - MSFT
Jeaninez - MSFT

Reputation: 4040

You could try to follow the following steps:

1, Retrieve the HWND for your existing window object via Retrieve a window handle

2, Pass that HWND to the GetWindowIdFromWindow interop function to retrieve a WindowId.

3, Pass that WindowId to the static AppWindow.GetFromWindowId method to retrieve the AppWindow.

For more details I suggest you could refer to the Doc: Manage app windows (Windows App SDK)

Upvotes: 0

Related Questions