Win32控件未出现在Winui3中

发布于 2025-02-02 02:49:26 字数 1060 浏览 2 评论 0 原文

我想要一个winui3窗口,要托管一个Win32控件,我尝试了以下操作:

app.xaml.cs:

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
    m_window = new MainWindow();
    var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(m_window);
    var ctrl = CreateWindow("EDIT", "Edit", WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE, 100, 100, 300, 50, hwnd, (IntPtr)0, (IntPtr)0, (IntPtr)0);
        
    m_window.Activate();
}

不幸的是,该控件没有直接显示,只有在您非常快速调整窗口大小时才可见。 我认为这是因为控制是在XAML后面创建的。我试图通过将窗帘设置为最上方来解决此问题,但它也无法使用。

SetWindowPos(ctrl, (IntPtr)(-1), 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);

有能力解决,还是我忘记了什么?

该文档,访问Win32 API: https:/// Learn.microsoft.com/en-us/windows/apps/winui/winui3/desktop-winui3-app-with-with-with-basic-interop

I want a Winui3 window, to host a Win32 control, I tried the following:

App.xaml.cs:

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
    m_window = new MainWindow();
    var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(m_window);
    var ctrl = CreateWindow("EDIT", "Edit", WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE, 100, 100, 300, 50, hwnd, (IntPtr)0, (IntPtr)0, (IntPtr)0);
        
    m_window.Activate();
}

Unfortunately, the control did not show up directly, It was only visible if you resize the window really fast.
I think that's because the control is created behind the XAML. I tried to fix this, by setting the WindowStyle to TopMost, but it didn't work either.

SetWindowPos(ctrl, (IntPtr)(-1), 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);

Is there a workaround, or did I forget something?

The documentation, to access Win32 apis:
https://learn.microsoft.com/en-us/windows/apps/winui/winui3/desktop-winui3-app-with-basic-interop

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文