简体   繁体   English

C++中如何获取WinUI3中控件的句柄?

[英]How to get a control's handle in WinUI3 in C++?

I am working on a C++ WinUI3 project and got this problem.我正在处理 C++ WinUI3 项目并遇到了这个问题。 How do I obtain the handle of a XAML grid?如何获取 XAML 网格的句柄?

Something like this in QT can achieve it: QT 中这样的东西可以实现它:

HWND m_hWnd; HWND m_hWnd;

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

But I couldn't find the similar thing in WinUI3.但是我在WinUI3中找不到类似的东西。 I look up on the Inte.net, but only find this solution which is in C#:我在 Inte.net 上查找,但只找到 C# 中的解决方案:

Get-a-controls-handle-in-XAML 在 XAML 中获取控件句柄

And the Microsoft provide this, but it is only working for window handle, not XAML controls.微软提供了这个,但它只适用于 window 句柄,而不适用于 XAML 控件。

Retrieve a window handle (HWND) 检索 window 句柄 (HWND)

Could anyone help me with it?有人可以帮我吗? Any suggestions will be great!任何建议都会很棒!

How do I obtain the handle of a XAML grid?如何获取 XAML 网格的句柄?

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, ie an individual control doesn't have its own handle in Win UI.屏幕上的所有 XAML 控件最终都由属于父 window 的单个 HWND 支持,即单个控件在 Win UI 中没有自己的句柄。

There is only a single top-level handle and the controls are rendered as content inside this HWND.只有一个顶级句柄,控件呈现为此 HWND 中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM