1

I am working on a C++ WinUI3 project and got this problem. How do I obtain the handle of a XAML grid?

Something like this in QT can achieve it:

HWND m_hWnd;

m_hWnd = (HWND)(ui.label->winId());

But I couldn't find the similar thing in WinUI3. I look up on the Internet, but only find this solution which is in C#:

Get-a-controls-handle-in-XAML

And the Microsoft provide this, but it is only working for window handle, not XAML controls.

Retrieve a window handle (HWND)

Could anyone help me with it? Any suggestions will be great!

Clara2022
  • 27
  • 4

1 Answers1

4

How do I obtain the handle of a XAML grid?

You can't because there is none.

All XAML controls on the screen are ultimately backed by a single HWND that belongs to the parent window, i.e. an individual control doesn't have its own handle in Win UI.

There is only a single top-level handle and the controls are rendered as content inside this HWND.

mm8
  • 163,881
  • 10
  • 57
  • 88